Posts

Showing posts from May, 2012

regex - How do I retrieve an integer's ordinal suffix in Perl (like st, nd, rd, th) -

i have number , need add suffix: 'st', 'nd', 'rd', 'th'. example: if number 42 suffix 'nd' , 521 'st' , 113 'th' , on. need in perl. pointers. try this: my $ordinal; if ($foo =~ /(?<!1)1$/) { $ordinal = 'st'; } elsif ($foo =~ /(?<!1)2$/) { $ordinal = 'nd'; } elsif ($foo =~ /(?<!1)3$/) { $ordinal = 'rd'; } else { $ordinal = 'th'; }

c# - How to calculate checksum for 3 GB file but first remove the last 28 bytes -

environment: 3 gb data file 28 byte sha-1 checksum appended end. is possible use filestream or other type of stream calculate sha-1 checksum hash reading stream position 0 position [x - 28(the length of appended checksum)] without physically removing appended checksum end of file first? currently opening file using filestream , reading using binaryreader seek , read last 28 bytes of file. then opening file again filestream , setting length of stream length - 28 bytes , removing checksum file. finally calculating checksum of data file last 28 bytes removed , comparing checksum removed end of file ensure checksums match. basically want know if it's possible calculate checksum of data part of file without having remove appended checksum first. if know how data want read (i.e. length - 28 bytes) when compute hash, put in data. haven't said how you're computing hash, can repeatedly "write" more data hash computation - long need, until last 28 bytes. sample:...

git - Removing patch from Gerrit -

i submitted patch review gerrit, created review page. wanted update patch modifications, unfortunately ended submitting new patch, depended on old one, along new corresponding review page. happened because did not amend previous commit, rather made new commit , pushed review. what i'm wondering if there way revert recent commit, amend changes older commit , have reflected on gerrit, removing recent review page , update old one. feel free edit question, or ask me if i'm not being clear. sure possible. there 2 tasks - clean git repository , update gerrit. to clean git, there couple approaches. automatic method squash 2 current commits using git rebase -i . option git checkout head^ && <make edits> && git commit --amend . once happy git tree, push gerrit creating new patch set original change. use 'abandon' button on change made accidentally , should go.

Django 1.4 Deployment and and os.environ.setdefault -

in new django 1.4 project layout, have declaration of os.environ.setdefault on manage.py , wsgi.py inside project folder. difference between two? also, if have settings structure: mysite |-- mysite | |-- settings | |-- base.py | |-- dev.py | |-- production.py | wsgi.py |-- myapp |-- manage.py which os.environ.setdefault should edit? 1 in manage.py or 1 in wsgi.py? os.environ.setdefault("django_settings_module", "mysite.settings") also, in file should detect current env? , how do so? so manage.py never executed once deployed, development and/or executing commands against project wsgi.py you're interested in. you can check looking @ file has: if __name__ == "__main__": should tell file meant executed directly command line.

asp.net mvc 3 - $.ajaxSetup for Ajax.BeginForm -

$.ajaxsetup used ajax call in jquery. works fine if use jquery ajax. but in mvc use ajax.beginform() .the callback handlers onfailure,onsuccess,onbegin. is there way can use $.ajaxsetup ajax.beginform(). update eg have used ajax.beginform() in 10 places instead of writing onfailure handler want write single common onfailure in common place jquery $.ajaxsetup. there way of doing it? quote documentation of $.ajaxsetup : note: global callback functions should set respective global ajax event handler methods - .ajaxstart(), .ajaxstop(), .ajaxcomplete(), .ajaxerror(), .ajaxsuccess(), .ajaxsend() - rather within options object $.ajaxsetup(). so suggested, use corresponding global ajax event handlers such .ajaxerror() example if want handle ajax errors globally: $(document).ajaxerror(function () { console.log('oopsy'); });

How to implement PropertyDefiner for logback to access multiple properties -

i define properties in logback.xml config file , saw implementing propertydefiner great way set properties in customizable way. after starting implement began wonder how access value of name attribute of element within tag. i'm not seeing anyway , i'm scratching head. propertydefiner make create new implementation every single property? why not hard code it? didn't see discussion out on web. i hope i'm not seeing , brains of stackoverflow can me out. know how this? thanks! i found discussion : same question asked, no answer returned. fyi: want customize how properties because pulling database. have helper class pulls properties in on server startup. these properties vary based on environment (dev, test, prod, etc.) as of logback version 1.0.6, value of name attribute cannot accessed directly. however, nothing prevents passing value of name attribute in property of choice. example: <define name="rootlevel" class="your.propertydefiner"...

git - What is libintl.h and where can I get it? -

trying make install of git source, , keep kicking error: make install * new build flags or prefix cc credential-store.o in file included credential-store.c:1: in file included ./cache.h:8: ./gettext.h:17:11: fatal error: 'libintl.h' file not found # include <libintl.h> ^ 1 error generated. make: *** [credential-store.o] error 1 no amount of googling has turned on lib.intl.h. elusive library, , how can can install git? depending on system, it's part of gnu c library (glibc). note installing file libintl.h isn't good. on debian-based systems (including debian, ubuntu, , linux mint), it's part of libc6-dev package, installed with: sudo apt-get install libc6-dev since you're using mac os x, google search "libintl.h osx" shows lot of people having similar problems. according install file in git sources: set no_gettext disable localization support , make git use english. under autoconf configure script automatically if can't fin...

Confusing Behaviour of regex in Python -

i'm trying match specific pattern using re module in python. wish match full sentence (more correctly alphanumeric string sequences separated spaces and/or punctuation) eg. "this regular sentence." "this valid" "so one" i'm tried out of various combinations of regular expressions unable grasp working of patterns properly, each expression giving me different yet inexplicable result (i admit beginner, still). i'm tried: "((\w+)(\s?))*" to best of knowledge should match 1 or more alpha alphanumerics greedily followed either 1 or no white-space character , should match entire pattern greedily. not seems do, wrong know why. (i expected return entire sentence result) result first sample string mentioned above [('sentence', 'sentence', ''), ('', '', ''), ('', '', ''), ('', '', '')]. "(\w+ ?)*" i'm not sure how 1 sho...

Wysihat without Rake, just Javascript? -

is there way install , use wysihat without running rake? naively tried copying source javascript-files online examples of wysihat, warning should "run rake in project root". second, tried rake (whatever may be). found decent article on how , running, let alone how use it. see words 'git', 'gem' , 'command line' (at least know is) on place, don't know start. taken in account problems above, have asked question instead: how install , use rake? main problem is: want wysihat work, or without rake. in advance reply! yes, understand miss understanding rake (or other build-stuff). there reason, probably. i'm php-developer , never needed use rake. i facing same problem. until find how run rake file, can wysihat.js here .

python - Parallel mapping functions in IPython w/ multiple parameters -

i'm trying use ipython's parallel environment , far, it's looking great i'm running problem. lets have function, defined in library def func(a,b): ... that use when want evaluate on 1 value of , bunch of values of b. [func(mya, b) b in mylonglist] obviously, real function more complicated essence of matter takes multiple parameters , i'd map on 1 of them. problem map, @dview.parallel, etc. map on arguments. so lets want answer func(mya, mylonglist). obvious way curry, either w/ functools.partial or dview.map_sync(lambda b: func(mya, b), mylonglist) however, not work correctly on remote machines. reason when lambda expression pickled, value of mya not included , instead, value of mya local scope on remote machine used. when closures pickled, variables close on don't. two ways can think of doing work manually construct lists every argument , have map work on of arguments, dview.map_sync(func, [mya]*len(mylonglist), mylonglist) or horrifically use data d...

java - Transparent JPanel in JLayeredPane -

Image
i've seen several similar questions, unfortunately suggestions contained therein haven't quite done me. the overall goal: have slider want display in upper left of window displays visualization (here "display"). slider should overlay on top of visualization without background. so far, have jpanel containing slider on layer above visualization in jlayeredpane. problem that, despite calls setopaque and/or setbackground(new color(0,0,0,0)), background jpanel including slider appears grey. using nimbus laf. originally, used absolute layout, accomplished quite elegantly , minimal code. issue there visualization didn't resize window automatically (but i'm open approach if there's clean way make visualization resize window). jpanel sliderpane = new jpanel(); sliderpane.setlayout(new boxlayout(sliderpane, boxlayout.x_axis)); sliderpane.add(zoomslider); zoomslider.setmaximumsize(new dimension (60, 150)); sliderpane.add(box.createhorizontalglue()); sliderpane.s...

bytearray - byte array to string in java -

securerandom random = securerandom.getinstance("sha1prng"); byte[] salt = new byte[16]; random.nextbytes(salt); i convert salt string store/read. don't seem able work. have read need use right encoding i'm not sure encoding use. have tried following junk: string s = new string(salt, "utf-8"); string s = new string(salt, "utf-16"); string s = new string(salt); edit: context, i'm trying work through , understand this code. i'm trying view salt , password can monkey code. you need use base64 (apache commons) class or sun.misc.base64encoder/base64decode encode byte array.

Sorting any kind of element using void pointers in C -

hello writing program sorting general element in c. can sort type of object(int,float,complex number, objects) what have thought of using void pointers, void qsort(void *ptr,int sz,int i,int j,int (*fptr) (const void *,const void *) ) { if(i<j) { int p=(i+j)/2; p=partition(ptr,sz,i,j,p,fptr); qsort(ptr,size,i,p-1,fptr); qsort(ptr,size,p+1,j,fptr); } } for comparison by value of sz know whether pointer string,int,char,float,etc int compare(const void* a,const void* b,int sz) { if(sz==0) //means pointer string return strcmp( (char*)a, (char*)b ); else if(sz==1) //means int return *(int*)a - *(int*)b; else if(sz==2) //means float return *(float*)a- *(float*)b; else if(sz==3) return *(char*)a- *(char*)b; } for swapping 2 elements void swap(void *a,void *b,int sz)//for swapping { if(sz==0) { void *c; c=a; a=b; b=c; } else if(sz==1) { a=(int*)a; b=(int*)b; int c; c= *a; *a=*b; *b=c; } else if(sz==2) { a=(float*)a; b=(float*)b; float c; c= *a; *a=*b; *b=c; } edited qsort(arr,4,0...

mysql - sql distinct function trouble -

i have query select m1.mid mid, m1.uid uid, m1.date, m1.body body messages m1 m1.chat_id null , deleted = 0 , m1.date in ( select max(m2.date) messages m2 m2.uid = m1.uid , m2.chat_id null , m2.deleted = 0 ) this query not written me, got here - hanks them lot. but have problem. when there more 1 message same date , uid(from same user) values, 2 or more records same date , uid, i'd have one( no matter which, or message greatest mid f.e.) i've tried use distinct(uid) no success result. there other way achive result want? you can use solution find recent message per uid : select b.* ( select max(mid) maxmid messages chat_id null group uid ) inner join messages b on a.maxmid = b.mid

In which XML file should I use depends element (Magento)? -

we know there 2 necessary xml files module development in magento. package_module.xml etc/config.xml some people use <depends> (if depends on existing module) tag inside first xml file & in second file 2.) <modules> <company> <newproduct> <version>0.7.32</version> <depends> <!-- no dependencies --> </depends> <newproduct> </company> <modules> 1.) <modules> <(namespace_modulename)> <active>[true|false]</active> <codepool>[core|community|local]</codepool> <depends> <(anothernamespace_modulename) /> </depends> <version>(version_number)</version> </(namespace_modulename)> </modules> configuration compiled in multiple steps. because of this, <depends> node should defined in module declaration file in app/etc/modules/ . note <depends> directives establish load order (or error) module config.xml files , nothing...

How to hide the keyboard that pops up in RubyMotion? -

how 1 hide virtual keyboard pops in text field? the button hides not seem appear , in case, next screen loads (which not have text field) still have keyboard in loaded position. thanks! update: using following allows keyboard return: def textfieldshouldreturn textfield textfield.resignfirstresponder 'yes' end however, still remains open upon next screen. it should true instead of 'yes' , don't forget set textfield delegate def textfieldshouldreturn textfield textfield.resignfirstresponder true end

c++ - malloc for string pointers: how it can be disastrous? -

in this informit c++ guide , read this: using malloc() create non–pod object causes undefined behavior: //disastrous! std::string *pstr =(std::string*)malloc(sizeof(std::string)); i didn't understand 2 points here : pointers pods. why called non-pod here? (maybe have understand pod better.) how can disastrous? (i guess have understand string internals this.) please explain! pointers pods why here called non-pod it's not talking pointer, std::string . it's disastruous because malloc doesn't call constructor, you'll have pstr std::string pointer points std::string wasn't constructed. memory allocated wasn't initialized properly, because of missing constructor call. the correct way is std::string *pstr = new std::string; the clean way have variable in automatic storage: std::string str;

chrome browser issue with asp.net 3.5 website -

i have developed 1 website in asp.net 3.5. running in browsers flickering in chrome. not able find reason. doing is, have 5 type of banners(header,footer,silver,gold , diamond) , each 1 refreshing on different time. using update panels. url of website http://www.allindiaeducationalhub.com . i thankfull if me it happening because of css property used there. need concern browser version , css support that. please go through link below, think solution. http://www.thewebseye.com/css-browser-compatibility.htm thanks & regards, subhankar

Drawing cubic lattice in Python -

Image
so want draw simple cubic lattice in python using visual package. i have simple way of making lattice small spheres have same color, want colors alternate: make nacl lattice need have sphere of 1 color surrounded 6 spheres of other color. so did this: from __future__ import division visual import sphere,color l = 5 r = 0.3 = [] odd = [] in range(-l,l+1): if i%2==0: even.append(i) else: odd.append(i) in even: j in even: k in even: sphere(pos=[i,j+1,k+1],radius=r,color=color.green) in odd: j in odd: k in odd: sphere(pos=[i,j,k],radius=r,color=color.yellow) and spheres of 1 color next speres of different color, in rows: but need them alternate :\ correct placement in direction. how correct others make simple cubic lattice? tried fiddling positions of spheres (i,j,k+-number), way got bcc lattice (one green sphere in middle, others around it). i'm stuck... what need this: from visual import sphere,color count = 3 r=0.3 x in range(-count,count+1): y in range(-count,count+1):...

javascript - Switch places on div with CSS? -

i'm buildinga site css media queries mobile , need switch places on 3 divs. this how looks : http://jsfiddle.net/snowman/3kzw2/ and need : http://jsfiddle.net/snowman/7s7e9/ is possible changing css of version 1? one way achieve setting widths on divs , using float right: http://jsfiddle.net/wabjn/

coding style - zen of Python vs with statement - philosophical pondering -

i don't intend waste time, but: has occurred too, while using python's with statement contrary 5th line of "the zen of python" goes "flat better nested"? can enlightened python guru share me of insights on this? (i find 1 more level of indentation pops in code every time use with instead of f.close() ... , it's not i'm not gonna use try: ... finally: ... anyways , benefits of with still elude me, grow , understand python more , more...) @glglgl (sorry, can't find way write code in comments): yes, if go with way, code becomes: try: file(...) f: ... except ioerror: ... ...and using without try people end doing in type of hacky "one use" code use f.close() instead of anyways (which bad because file may not closed if exception thrown before f.close() ), "hacky" code people don't use with because, don't know, guess find "fancy" , structured code doesn't bring benefits anyways, seems me there'...

osx - Java System Tray Icon on MacOS 10.7.4 not showing animated gif -

i'm trying animated gif appear in macos system tray using java. have png icons showing corretly, try , set icon animated gif (so can show spinning timer) goes blank , shows nothing in system menu tray. according javadocs system tray class, setimage should automatically support animated images if given doesn't specify image format or else required animated icons in system tray. does know how working? chances problem cannot resolved java.awt.systemtray class. option have try jdic uses native code. frankly i'm not sure whether jdic project maintained anymore, quite hard find information on web... in project of mine used jdic integrate system tray. can use starting point , libraries there, if can't find other resources.

Enable a javascript plugin on button press -

i have webpage on there button. on button press, intent embed script in head section of page enable plugin. can manually insert snippet , plugin want able on button click keep optional element users. way go this? as per @padde 's query, script looks following way include in header: <script type="text/javascript" src="http://code.abc.com/farfalla.js"></script> <script type="text/javascript" src="http://code.abc.com/postmessage.js"></script> use createelement() of javascript , add dom check below link more information : http://www.hunlock.com/blogs/howto_dynamically_insert_javascript_and_css if using jquery can use $.getscript load external js file. $.getscript('filename.js',function(){ //your code ... });

silverlight - How to create a picture? -

hi have question windows phone 7 app i want create picture or area in app can e.g. add font or other elements circle. who can show me example or code? ir not possible? waht silverlight app, not xna you can advanced image creation/manipulation using .net image tools silverlight .

Android: new information replace old information in notification -

from documenation of notificationmanager in android: public void notify (int id, notification notification) post notification shown in status bar. if notification same id has been posted application , has not yet been canceled, replaced updated information. it replaced updated information. i don't want old information replaced, want both notifications. nb: each notification has own id: notificationmanager.notify(0, notification); notificationmanager.notify(1, notification); how this? stack notifications if app creates notification while of same type still pending, avoid creating altogether new notification object. instead, stack notification. a stacked notification builds summary description , allows user understand how many notifications of particular kind pending. http://developer.android.com/design/patterns/notifications.html

ruby on rails - Routing specs fails because hashes are stored differently -

my test example is: it "routes #add_role" post("/users/1/add_role").should route_to("users#add_role",id: 1) end here failure message: userscontroller routing routes #add_role failure/error: post("/users/1/add_role").should route_to("users#add_role",id: 1) recognized options <{"controller"=>"users", "action"=>"add_role", "id"=>"1"}> did not match <{"id"=>1, "controller"=>"users", "action"=>"add_role"}>, difference: <{"id"=>1}>. <{"id"=>1, "controller"=>"users", "action"=>"add_role"}> expected <{"controller"=>"users", "action"=>"add_role", "id"=>"1"}>. my environment: ruby-1.9.3-p194 rails 3.2.6 rspec (2.10.0) you need id in route_...

One Click install for Safari Extensions -

when user downloads plugin firefox (for example) plugin installation begins download has completed. is possible achieve same thing in safari? i.e. user clicks link download plugin, once has downloaded automatically begins installation. i don't think possible on other domain except extensions.apple.com . i've done extensive testing on , safari.installextension() method present if domain matches extensions.apple.com (probably controlled browser, similar how chrome apis shows inside of extensions themselves). i tested theory going js file , opening js console: https://extensions.apple.com/home/scripts/extensioninstall.js after js file has loaded, type typeof(safari.installextension) in js console , should return "function" . notice exists on non-html page, meaning it's being provided browser (since script doesn't execute, nor has code in provide method). i tried doing on other sites , doesn't exist: "undefined" . i had crazy thought need...

back folded corner using css or javascript or jquery -

Image
how create folded corner menu below using css, jquery or javascript. or there kind of library allow this. thank much back folded corner using css or javascript or jquery - stack overflow stack overflow questions developer jobs documentation beta tags users current community help chat stack overflow meta stack overflow communities sign up or log in customize list. more stack exchange communities company blog tour start here quick overview of site center detailed answers questions might have meta discuss workings , policies of site learn more stack overflow company business learn more hiring developers or posting ads log in sign up learn, share, build each month, on 50 million developers come stack overflow learn, share knowledge, , build careers. join world̢۪s largest developer community. sign up back folded corner using css or ja...