Posts

c# - Comma escape in stringbuilder -

here's simple issue i'm running into, knowledge limited. have program turns existing database csv; however, many of fields contain commas , need them escape. i've tried couple of things no avail (under objecttocsvdata), included snippet appreciated. using system; using system.collections.generic; using system.linq; using system.text; using system.collections; using system.reflection; namespace ofasort { public static class utility { public static string collectiontocsv(ilist collection) { stringbuilder sb = new stringbuilder(); (int index = 0; index < collection.count; index++) { object item = collection[index]; if (index == 0) { sb.append(objecttocsvheader(item)); } sb.append(objecttocsvdata(item)); sb.append(environment.newline); } return sb.tostring(); } public static string objecttocsvdata(object obj) {...

dax - Count Unique Occurrences PowerPivot -

i new powerpivot , dax formulas. assume trying basic , has been answered somewhere, don't know search on find it. i trying determine percent of sales people had sale in given quarters. have 2 tables, 1 lists sales people , 1 list sales quarter. example employee id 123 456 789 sales id - emp id - amount 135645 ---- 123 ----- $50 876531 ---- 123 ----- $127 258546 ---- 123 ----- $37 516589 ---- 789 ----- $128 998513 ---- 789 ----- $79 as result, pivot table this: emp id - % w/ sales 123 -------- 100% 456 -------- 0% 789 -------- 100% total ------- 66% if can point me post has been addressed or let me know best way address appreciate it. thank you. here's simple way of doing (assuming table names emps , sales ): =if (distinctcount ( sales[emp id] ) = blank (), 0, distinctcount ( sales[emp id] ) ) / countrows ( emps ) the if() required ensure people haven't made sale appear in pivot. actual formula doing dividing number of s...

python - Dynamic nested dictionaries -

just begin know there couple similarly-titled questions on here, none explained quite way nor problem scope same. i want add nested dictionary entries dynamically. the use case thus: have python script monitoring network. dictionary created each observed ip protocol (tcp, udp, icmp) observed. sub-dictionary created key destination port (if 1 exists) each of these ip protocols (80, 443, etc.) (note doesn't matter whether sees server port source or destination, servers destination picked http , https examples). each of these destination ports key created corresponding server ip (e.g., ip www.google.com). , dictionary timestamp session first observed key , data/value key being client's ip. however, want need populated time goes on since won't have data before execution nor @ initialization. the output akin to: { 'icmp' : { 'echo-request' : { '<ip_of_www.google.com>' : { '<timestamp>' : <some...

linux - IPv6 vs IPv4 connectivity load -

one of our applications uses cross-platform tcp connectivity layer. layer has connectivity stress-test. test launches 20 client threads , 20 server threads; each client connect/small-data-exchange/close several randomly chosen server threads. the test done 4 connectivity variants (ipv4 ipv4, ipv6 ipv6, ipv4 dual-mode, , ipv6 dual-mode). passes on everywhere except on one particular 64-bit linux machine 4 machines of running redhat 2.6.18-8.el5. ipv4 connectivity (both ipv4 , dual-mode) passes on this machine these machines, ipv6 can handle tenth of should able to. gets timeout errors, few connection-reset errors. cpu, memory, descriptors, etc. not issue. i've reviewed network settings on machine, nothing seems have been messed with. using localhost vs host name changes nothing. (in particular, i'm ruling out faulty network card, fails on loop-back.) netstat shows nothing unusual. (a lot of sockets in time_wait, that's expected given nature of test.) i'd ...

How can I access a character in the middle of a line in c++? -

i working on project consists of reading input file called input.txt has infinite number of lines. each line has roman numeral, space, plus or minus, space, , roman numeral. supposed add 2 numbers , write answer file called output.txt. however, can't think of way access operator. here sample input file: xv + vii xii + viii can give me idea of how can access plus sign each line of code? if you're reading file standard input, can whitespace delimited tokens using extraction operator. #include <string> #include <iostream> int main(int argc, char *argv[]) { std::string token; while (std::cin >> token) { // parse tokens here ... // example, i'll print out stream of tokens. std::cout << token << std::endl; } } if you'd assume have 3 tokens per line, can this: #include <string> #include <iostream> int main(int argc, char *argv[]) { std::string first, middle, last; while ...

replace - Trying to remove all spaces, tabs, carriage returns using VBScript -

i trying assign results of command below variable. goal obtain pid number. service_name: msftpsvc type : 10 win32_own_process state : 3 stop_pending (stoppable, not_pausable, accepts_shutdown) win32_exit_code : 0 (0x0) service_exit_code : 0 (0x0) checkpoint : 0x0 wait_hint : 0x0 pid : 7888 flags : if have better idea let me know. trying remove spaces, tabs, carriage returns, etc... search "pid:" string , "flags" , copy pid number. i haven't been able remove spaces , have in 1 single string. here code: dim wshshell set wshshell = wscript.createobject("wscript.shell") dim commandtorun, scriptstdout, scriptstderr, exitcode dim results commandtorun = "sc.exe queryex msftpsvc" exitcode = execscript(commandtorun) results = replace(scriptstdout, vbcrlf, ...

sql - MySQL proportionate subset of returned rows -

i have query so select t.trial, count(*), max(d.value) data d inner join trial_info t on d.instance_timestamp between t.trial_start_timestamp , t.trial_end_timestamp group t.trial; which returns t.trial | count(*) | max(d.value) --------------------------------- 1 | 80 | 176 2 | 63 | 219 3 | 49 | 109 4 | 67 | 155 one row of d represents 1 second, condensing on t.trial means count(*) return number of seconds in each trial, , max(d.value) largest value observed in seconds. question : how can whittle results return middle 50% of each trial and max value in time ? want throw out first 25% of trial time last 25%. subquery skills aren't hot... here idea far. substituting join works when computedvalue set static number. want computedvalue percentage of rows returned (displayed in count(*) result column above). inner join trial_info t on d.instance_timestamp between date_add(t.trial_start_timestam...