Posts

How do you convert a timestamp into a datetime in python with the correct timezone? -

you naively expect work: import pytz datetime import datetime def tz_datetime_from_timestamp(timestamp): """convert timestamp datetime """ tz = pytz.timezone('australia/perth') server_time = datetime.utcnow() delta = tz.utcoffset(server_time) value = datetime.utcfromtimestamp(timestamp).replace(tzinfo=tz) return value + delta print tz_datetime_from_timestamp(1416387060) and convert timestamp 1416387060 wed nov 19 16:51:00 2014 gmt+8:00. ...but not. prints: 2014-11-19 16:51:00+07:43 the timezone of australia/perth not gmt+7:43. it gmt+8:00. unequivocally stated on australian government website http://www.australia.gov.au/about-australia/our-country/time : awst equal coordinated universal time plus 8 hours (utc +8). so, heck pytz pulling 7.43 from? well, turns out pytz pulls data http://www.iana.org/time-zones time zone database, , database states: # western australia # # rule name type in on @...

d - Is there I can get GDC to give me source code with all templates expanded, but no other work done? -

suppose have file foo.d instantiates bunch of templates. there way can ask gdc (specifically) give me foo.d templates instantiated, nothing else done? gcc -e option doesn't work, d templates not expanded c preprocessor, i'm not sure option should try (or if 1 exists).

css - How to add a transition to a absolute positioned box on hover -

hi have created boxes overflow: hidden , on hover box drop down showing inner box. i have created , works fine use transition on effect smoothen drop down. have added transition , not working. any advice great on thank you. <html> <head> <title></title> <style type="text/css"> #items {width:300px;} .item {width:100px;border:solid 1px #ccc;float:left;height:20px; z-index:0;overflow:hidden;position:relative;} .item:hover{overflow:visible;z-index:100;} .item:hover .inner{z-index: 100;} .inner{position: absolute; background: white; width: 100%; } </style> </head> <body> <div id="items"> <div class="item"><div class="inner">text 1<br>text 1<br>text 1</div></div> <div class="item"><div class="inner">text 2<br>text 2<br>text 2</div></div> <div class="item"><div class="in...

.net - Preventing XSS attacks across site -

i need review quite large .net 4.0 project , re-factor prevent xss attacks. first thing did turn on requestvalidation site, there else can @ global level or going case of trawling through every page, validating input , html encoding output. there lots of pages, , 300 classic asp pages still in use. is htmlencode() safe use or need install microsofts antixss package. requestvalidation approach. at global level 1 more thing can think of enabling x-xss-protection header @ http responses. easy implement , gives native defences browser (ie 8+, chrome) has offer based on xss patterns. x-xss-protection: 1; mode=block you may @ content-security-policy, think in scenario may big roll out entire site. those think of http header based xss mitigations. generic , not apply asp.net. answering other question is htmlencode() safe use or need install microsofts antixss package what benefit make encodertype antixssencoder in mvc application? antixssencoder uses whitel...

HTML pattern attribute for email validation -

i need email address of user match format while registering. name.name@gmail.com he should not able enter @yahoo.com or @hotmail.com or else other @gmail.com. also, allowed enter lower case letters , period [.] if wants. may please know how achieve this? have got far. pattern ="[a-z.]+@gmail.com" try /^([a-z0-9.])+\@gmail.com+$/

sql server - Generate Invoice Number for Multi user environment in C# -

i generating invoice numbers using max function , adding 1 last invoice number. straightforward. applied multi user environment getting problem. because 2 users open invoice window @ same time both same id, invoice number should first thing appear , not last cannot use identity (auto generate id) invoice number. want generate invoice number multi user environment windows form application in c#... the other problem happen 2 users accessing , updating same record same time. i hope understand problem. read optimistic vs. pessimistic locking need solution. can please reply me have different database table store max invoice number. when user opens invoice window, run stored procedure to: lock table get current number store current+1 number unlock table return current+1 number this ensure though there simultaneous requests unique invoice number. the flip side: 1. stored procedure cannot run simultaneously multiple users bottleneck in case of high traffic. 2. th...

how to display 2 form fields on same line with bootstrap -

i creating form in bootstrap should responsive. see below code. <form novalidate="novalidate" class="form-inline"> <div class="form-group"> <label class="col-sm-4 control-label" for="inputfirstname">first name:</label> <div class="col-sm-4"> <input class="form-control" type="text" id="inputfirstname" ng-model="patient.firstname"/> </div> </div> <div class="form-group"> <label class="col-sm-4 control-label" for="inputlastname">last name:</label> <div class="col-sm-4"> <input class="form-control" type="text" id="inputlastname" ng-model="patient.lastname"/> </div> </div> ...

for loop - Special for syntax for looping over all objects of a certain class? -

can compress combined for -plus- if single for , i.e. can combine first 2 lines single instruction loop? it should visit objects in childnodes instances of mynode . for childnode in childnodes { if let mynode = childnode as? mynode { // mynode } } i presume childnodes array. if yes, can filter it: for childnode in (childnodes.filter { $0 mynode }) { println ("it's node") } or if prefer more explicit code: let nodes = childnodes.filter { $0 mynode } childnode in nodes { println ("it's node") } as far know, in swift there's no clean way combine for loop optional binding skip iterations. something might possible using standard for loop, combined closure which, given index, returns next index containing mynode instance... wouldn't call simplification in terms of code , readability: let findnext = { (var index: int) -> (node: mynode?, next: int) in while index < childnodes.count { ...

php - Add Number for duplicate entry in sql -

i have table :- id name email username 1 johen mak jojo@yahoo.com johen_mak 2 johen mak jojo@gmail.com jojo 3 gawil gorgy jojo@homail.com gawil_gorgy 4 johen mak jojo@yamail.com jojo 5 johen mikik jojo@yamail.com jojo in table in database entry in same username , need add _1 .... end username i need update above table this:- id name email username 1 johen mak jojo@yahoo.com johen_mak 2 johen mak jojo@gmail.com jojo 3 gawil gorgy jojo@homail.com gawil_gorgy 4 johen mak jojo@yamail.com jojo_1 5 johen mikik jojo@yamail.com jojo_2 how can that ...

Import SQLite database using Qt/QSqlDatabase -

i have 2 separate applications, 1 placed @ production @ office, , need copy of sqlite database generated , updated @ production side. until i've tried 2 approches: copy entire sqlite file production-application , "redirect" qsqldatabase-handles file (was not able work, many connections opened , not closable) access sqlite-db on network, query data , insert missing data using sql (works, since there lot of data takes time) are there possibilities import or maybe override existing database (or single tables, placed in different files), there still open connections? using: qt 4.8, sqlite, windows 7, vs2010 so able reach goal using sqlite backup api (which distributed .h , .c qt versions). on documentation page sqlite backup there few examples, database copied either file in-memory db, or in-memory file. in case used following function (1:1 doc page, several comments removed): int loadorsavedb(sqlite3 *pinmemory, const char *zfilename, int issav...

php - Restructure array to be in descending date order -

i have multi-dimensional array, has index ['dates'] . inside ['dates'] there index, , inside there ['date_time'] index data. presently ordering of part of array oldest newest date/time. wish reverse first element most recent data. here subset of data: array(4) { [0]=>array(3) { ["id"]=>string(4) "1279" ["name"]=>string(13) "account_name" ["dates"]=>array(7) { [0]=>array(3) { ["date_time"]=>string(19) "2014-11-14 09:30:03" ["follower_count"]=>string(4) "1567" ["gains_losses"]=>string(4) "1567" } [1]=>array(3) { ["date_time"]=>string(19) "2014-11-14 16:30:35" ["follower_count"]=>string(4) "1566" ["gains_losses"]=>string(2) "-1" }... here full array you m...

xcopy - how to copy and paste file into folder using batch -

i want create batch file copy content of folder , paste folder. say source: d:\backup\test destination: d:\backup1 but here want create subfolder destination can paste file. @echo off :: variables echo backing file set /p source=enter source folder: set /p destination=enter destination folder: set listfile=xcopy /l set xcopy=xcopy /s/e/v/q/f/h %listfile% %source% %destination% echo files copy press enter proceed pause %xcopy% %source% %destination% pause the if not exist checks see if directory exists. if not, mkdir creates it. @echo off echo backing file set /p source=enter source folder: set /p destination=enter destination folder: if not exist %destination% mkdir %destination% set listfile=xcopy /l set xcopy=xcopy /s/e/v/q/f/h %listfile% %source% %target% echo files listed copied. pause %xcopy% %source% %destination%

mysql select condition with 3 conditions -

Image
i have table have field called cheque_type , filed comes 3 variables such life,nonmotor,motor and table has time stamp. need result how many life, nonmotor , motors checks printed what need add 3 columns sql query , number of results according category select date(`timestamp`) ___date___, count(`id`) total, sum(print_status) printed, (count(`id`) - sum(print_status)) to_be_print cheque.vouchers date( `timestamp`) >='2014-11-15' , date( `timestamp`) <='2014-11-31' group date(`timestamp`) ; select date(`timestamp`) ___date___, count(`id`) total, sum(print_status) printed, (count(`id`) - sum(print_status)) to_be_print, sum(cheque_type = 'life') life_check, sum(cheque_type = 'nonmotor') non_check, sum(cheque_type = 'motor') motor_check cheque.vouchers date( `timestamp`) >='2014-11-15' , date( `timestamp`) <='2014-11-31' group date(`timestamp`) ;

xmlhttprequest - What is the suggested way to build and send a http request in Python -

i wrote small module 1 year age. when tried add feature these days, found there big change in python's urllib , confused how build request. in old module fancyurlopener used base class, yet found deprecated since version 3.3. so read document again, , try build request instead of opener. however, when tried add headers, 1 function request.add_header(key, val) provided. have headers copied fiddler this: get some_url http/1.1 host: sosu.qidian.com user-agent: mozilla/5.0 (windows nt 6.1; wow64; rv:33.0) gecko/20100101 firefox/33.0 accept: application/json, text/javascript, */*; q=0.01 accept-language: zh-cn,en-us;q=0.7,en;q=0.3 accept-encoding: gzip, deflate x-requested-with: xmlhttprequest referer: anothe_url cookie: lot of data connection: keep-alive so have add them request 1 one? also found openner urllib.request.build_opener() can add lot of headers in 1 time. not set method 'get' or 'post'. i newbie on python, suggestions ? by far...

lua - How to get past 1gb memory limit of 64 bit LuaJIT on Linux? -

the overview prototyping code understand problem space, , running 'panic: unprotected error in call lua api (not enough memory)' errors. looking ways around limit. the environment bottom line torch, scientific computing framework runs on luajit, , luajit runs on lua. need torch because want hammer on problem neural nets on gpu, there need representation of problem feed nets. (stuck) on centos linux, , suspect trying rebuild pieces source in 32bit mode (this reported extend luajit memory limit 4gb) nightmare if works @ all of libraries. the problem space not particularly relevant, in overview have datafiles of points calculate distances between , bin (i.e. make histograms of) these distances try , work out useful ranges. conveniently can create complicated lua tables various sets of bins , torch.save() mess of counts out, pick later , inspect different normalisations etc. -- after 1 month of playing finding easy , powerful. i can make work looking @ 3 distances 15...

c# - NotSupportedException when doing a Bing image search programatically -

i using following code more 50 results bing image search using bing search container bing api. problem when try , execute query ( query.excecute() ) after changing off-set next 50 results ("$skip", 50) following error: a first chance exception of type 'system.notsupportedexception' occurred in microsoft.data.services.client.dll i can't figure out how query. re-iterate occurs when when loop executes second time. happens on line var results = query.execute(); , when tries query. void bingsearch(string searchterm) { try { imageset = new list<bing.imageresult>(); const string bingkey = "[key]"; var bing = new bingsearchcontainer( new uri("https://api.datamarket.azure.com/bing/search/")) { credentials = new networkcredential(bingkey, bingkey) }; var query = bing.image("\"" + sear...

vbscript - Use string as Object method -

basically, i'm creating small script update ad attributes (for super user, not admin). i've got number of attributes, need custom field user can type in ad attribute , searched ldap query , displayed using objuser. here code: do while z = true attrchoice = inputbox("please enter custom attribute wish edit", "custom attribute") msgbox "you have selected " & objuser.+attrchoice, vbokonly+vbinformation, objuser.displayname on error resume next if err.number <> 0 msgbox "error!" & vbcrlf & "attribute cannot found, please try again", vbokonly+vbexclamation, "error" else z = false end if on error goto 0 loop as can see, i've tried doing objuser. attribute part few different ways - i'm not sure how use string that's input user. in custom field, user put "mail" , code run objuser.mail - make sense? if need more information, ple...

box api - Way to create file with the box api -

i there way create doc, .boxnote third app box api ? seems edit, delete update functionalities avaible. i not possible. box notes created using specific web application box. box's api have two modules : box content : managing upload/download of data box view : converting docs html

Assigning values of an object to a column in Loop through R -

this snippet of r code. trying assign value of resultsdata[i] column error values not assigning. results coming in console somehow not able assign required column resultsdata=foreach(i=1:length(xyzarr)) %dopar% { xyzred[xyzsred$loopn==xyzarr[i],]$setpoint-xyzred[xyzred$loopn==xyzarr[i],]$temp } foreach(i=1:length(xyzarr)) %dopar%{ xyzred[xyzred$loopn==datapointsarr[i],]$error=resultsdata[[i]] } results in console: [[1]] [1] 1.186 1.186 1.186 1.186 1.186 1.186 1.186 1.186 1.186 1.186 1.186 1.186 1.186 2.266 2.266 2.266 2.266 2.266 [19] 2.266 2.266 2.266 2.266 1.384 2.392 2.392 i typically use combine feature. general approach calculate column, output entire row. lastly, row binding logic puts together. xyzarr$var_name_here <- numeric(nrow(xyzarr)) resultsdata <- foreach(i=1:length(xyzarr), .combine=rbind) %dopar% { xyzarr[i,]$var_name_here <- xyzred[xyzsred$loopn==xyzarr[i],]$setpoint-xyzred[xyzred$loopn==xyzarr[i],]$temp xyzarr[i,] }

node.js - Node js Error: Most middleware (like session) is no longer bundled with Express and must be installed separately -

i have upgraded express version 3 , seeing error in middleware. specifically: error: middleware (like session) no longer bundled express , must installed separately. please see https://github.com/senchalabs/connect#middleware. the stack trace is: at function.object.defineproperty.get (/home/phpsaravana/nodeshop/node_modules/express/lib/express.js:89:13) @ module.exports (/home/phpsaravana/nodeshop/node_modules/connect-mongo/lib/connect-mongo.js:30:39) @ object.<anonymous> (/home/phpsaravana/nodeshop/admin.js:6:42) @ module._compile (module.js:456:26) @ object.module._extensions..js (module.js:474:10) @ module.load (module.js:356:32) @ function.module._load (module.js:312:12) @ function.module.runmain (module.js:497:10) @ startup (node.js:119:16) @ node.js:906:3 how fix this? in newer versions of express, middle-wares session not bundled express , if want use them, have install them separately. : npm install express-session and require : var session = r...