Posts

php - Faster way for this mysql_query -

$handle = fopen("stock.csv", "r"); while (($data = fgetcsv($handle, 1000, ";")) !== false) { $model = mysql_real_escape_string ($data[0]); $quantity = mysql_real_escape_string ($data[7]); mysql_select_db("verradt33_xoho", $link); $quantity = str_replace("ja", "10", $quantity); $quantity = str_replace("nee", "0", $quantity); $result = mysql_query("update dev_product set quantity = $quantity model = '$model'") or die(mysql_error()); even tho code works, takes long time process 7000+ lines in csv. due having replace ja or nee 10 or 0 every single line. is there way make faster? can't touch csv file, that's hard part of course. current load time 40 minutes. your first question should be: is column model indexed? secondly, try commenting out database access's , see how long takes .csv processing! mysql_select_db("verradt33_xoho",...

Write data to one csv row Python -

in py script, need write data csv file result of 5 columns per row. title:info title title title title 1 2 3 4 5 1 2 3 4 5 title:info title title title title 1 2 3 4 5 i want use file.write() method, not csv module if @ possible. for ip in open("list.txt"): open("data.txt", "a") csv_file: csv_file.write("\r title:" + ip + ", title, title, title, title \r") line in open("0820-org-apflog.txt"): new_line = line.split() #search apflog correct lines if "blocked" in new_line: if "src="+ip.strip() in new_line: #write columns new text file & remove headers lines in files , add commas csv_file.write(ip + ", " + new_line[11].replace("dst=", ", ") + new_line[12].replace("proto=", ", ")) try...

unit testing - SystemVerilog program block vs. traditional testbench -

are there features of sv program block offers can't duplicated other methods? the less concrete version of question is: should bother program blocks verification? i'm moving environment constrained verilog-95 environment sv supported, , i'm wondering if i'm creating work myself not using program blocks. check out ieee std 1800-2012 § 3.4 & § 24. full description program blocks. in short, incomplete summary, program block: cannot cannot contain always procedures, primitive instances, module instances, interface instances ( virtual interface , port interface allowed), or other program instances. specifies scheduling in reactive region. prevents race conditions. has system task $exit , terminates program instances calls it. the simulation terminate when program instances have exited. is module block except stated above. the idea of program block create clear separation between test , design. in earlier versions of systemverilo...

haskell - How to get a SHA-1 digest of a X509 certificate with HsOpenSSL? -

i'm writing web server accepts ssl connections , calculate sha-1 hash of client certificates: import openssl (withopenssl) import openssl.session ssl import openssl.x509 x509 import openssl.evp.digest evp sslstuff :: ssl.ssl -> io string sslstuff ssl = withopenssl $ x509 <- liftm fromjust $ ssl.getpeercertificate ssl issuer <- x509.getissuername x509 false subj <- x509.getsubjectname x509 false putstrln $ "\tsubject: " ++show subj putstrln $ "\tissuer: " ++show issuer dg <- liftm fromjust $ evp.getdigestbyname "sha1" cert <- x509.printx509 x509 putstrln cert let s = evp.digest dg cert putstrln $ "after digest: "++s return s i certificate, digest 15 bytes long instead of 20. i'm not sure correctly convert cert string before passing evp.digest. please give me example of how right way? i not know haskell. following code might you. x509 * x509; char sha1dig[sha1_digest_length]; /...

sql - Date Aging Report + Cummulative -

i working on aging report based on last action date stored in table, given table below: requestno usercode lastactiondate actiontype req1 407 12/14/2012 9:47 saved req1 407 12/14/2012 9:48 submitted req1 407 12/14/2012 9:48 approved req1 203 12/17/2012 9:54 reviewed req1 242 12/18/2012 10:29 wf setup in dev. req1 203 12/18/2012 15:14 transport prod. req1 242 12/18/2012 15:16 completed req2 407 12/27/2012 10:36 submitted req2 456 12/27/2012 11:18 approved req2 407 12/27/2012 11:27 approved req2 203 12/27/2012 17:34 reviewed req2 242 12/28/2012 14:07 wf setup in dev. req2 203 12/28/2012 14:11 transport prod. req2 242 12/28/2012 21:27 completed req3 407 12/27/2012 11:32 submitted req3 456 12/27/2012 11:33 approved req3 407 12/27/2012 11:3...

ios - Update NSError UserInfo -

i'm trying update nserror object more information. example, api call may fail , want update error object returned api class view controller information (method name caused error, client message, additional info). there isn't setter method userinfo dictionary , trying set value dictionary raises exception (not key value code compliant believe). thought creating new nserror object updated user info, wasn't sure if might lose information. question what's best way update user info dictionary of nserror object? easiest way mutable copy of userinfo dictionary , add whatever that. have create new nserror (since there not setuserinfo: method) same domain , code original one.

python - Cleaner / reusable way to emit specific JSON for django models -

i'm rewriting end of app use django, , i'd keep front end untouched possible. need consistent json sent between projects. in models.py have: class resource(models.model): # name chosen consistency old app _id = models.autofield(primary_key=true) name = models.charfield(max_length=255) @property def bookingpercentage(self): bookings.models import booking return booking.objects.filter(resource=self) .aggregate(models.sum("percent"))["percent__sum"] and in views.py gets resource data json: def get_resources(request): resources = [] resource in resource.objects.all(): resources.append({ "_id": resource._id, "name": resource.first, "bookingpercentage": resource.bookingpercentage }) return httpresponse(json.dumps(resources)) this works need to, seems antithetical django and/or python. ...