Posts

Showing posts from May, 2014

c - Producer/Consumer using TCP client/server -

the server intended multithreaded server spawns new threads upon either producer or consumer connection via tcp. problem i'm getting stuck in wait state once producer client fills queue. snippet shows server's handling of producer connection. format of request producer sends put (item) reqline[0] = strtok (mesg, " \t\n"); if ( strncmp(reqline[0], "put\0", 4)==0 ) { item[0]=strtok(null," \t\n"); pthread_create (&pro, null, producer, fifo); pthread_join (pro, null); } so can see i'm creating new thread handles job of filling queue/detecting when empty. code within producer: queue *fifo; int i=atoi(item[0]); char*fullmsg="full\n"; fifo = (queue *)q; pthread_mutex_lock (fifo->mut); while (fifo->full) { //the problem block printf ("producer: queue full.\n"); send(conn_s, fullmsg,st

c++ - using gprof and boost -

while profiling bit of code use's many boost functions gprof, there nasty , hard follow output see sample below , there way clean gprof use boost or more boost friendly alternatives? looks of there repition of boost::math::policy cluttering profiling output making difficult see or understand call graph btw heres snippet of example boost::math::policies::policy<boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy> >(long double, long double, long double*, long double*, int, boost::math::policies::policy<boost::math::po

objective c - Mocking KVO with OCMock -

i test key-value-observation working class of mine. has 1 property, depends on another. set so: + (nsset *)keypathsforvaluesaffectingsecondproperty { return [nsset setwithobjects: @"firstproperty", nil]; } - (nsarray *)secondproperty { return [self.firstproperty array]; } i want run unit test verify when firstproperty changes, object bound secondproperty gets notification. @ first thought able use +[ocmockobject observermock] , looks can used nsnotificationcenter . best way test this? i worked on while after @chrispix's answer inspired me work in different direction. started this: id objecttoobserve = [[theclassbeingtested alloc] init]; id secondpropertyobserver = [ocmockobject mockforclass:[nsobject class]]; [[secondpropertyobserver expect] observevalueforkeypath:@"secondproperty" ofobject:objecttoobserve change:

git - How do you see which commit deleted a file from the repo? -

this question has answer here: find when file deleted in git 4 answers since no longer in repository, can't do git log <filename> i can run git log --diff-filter='d|r' <directory_that_contained_it> but information , grepping not seem list file i'm looking for. git log -1 --stat -- <path/to/file> i put --stat in there can verify file deleted.

Call intent to make a call with put extra to select a phone number in Android? -

i trying create way user can contact friend via sms, email , phone call. have completed email , sms part. have figured out how use createchooser select how message sent using either email or text message, achieved clicking on button, following code how this: intent = new intent(intent.action_send); i.settype("text/plain"); i.putextra(intent.extra_email , new string[]{""}); i.putextra(intent.extra_subject, "check out awesome score!"); i.putextra(intent.extra_text , "i playing awesome game called tap button, , scored incredible highscore of " +s+ " taps!!\n\ncan beat it!?"); try { startactivity(intent.createchooser(i, "send mail...")); } catch (android.content.activitynotfoundexception ex) { toast.maketext(fail.this, "there no email clients installed.", toast.length_short).

In VB6, is it possible to call a function with an operator in the parameter? -

i'm having hard time finding answer this, such generic terminology, , it's possible question still difficult parse. have code variable representing amount of free disk space remaining percentage. want call function, use reverse amount in message user, i.e. amount of used space. can little math in function call? public sub myapp() dim nfreespace integer nfreespace = getfreespace displayusedspace 100 - nfreespace 'is valid? end sub private function displayusedspace(byval nusedspace integer) boolean msgbox("you have used " & nusedspace & "% of disk drive space.") end function yes, valid. although, write this call displayusedspace(100 - nfreespace) but, code work fine too.

c++ - How to compile Boost.Log standalone -

after doing research, partially on stack overflow, decided try boost.log library andrey semashev. unfortunately, build boost.log library i have place in boost source tree , compile part of boost. blocker me, because have complicated building configuration. i want build boost.log standalone. i've found interesting thread on boost.log forum , method doesn't work me. instead of using boost.log, might suggest consider cpplog: https://github.com/andrew-d/cpplog it's header library based on google's logging library.

java - @Inject is injecting a new instance every time i use it -

i have following issue. (jboss 7.1 as, jsf 2 , myfaces extension filter) two managed beans. (i have cleaned code). want retrieve loginbean nextbean. problem every time inject bean new instance of loginbean , not current one. have tried things @named("name"). bean (both) invoked jsf pages , data set, new instance injected every time , cant figure out i'm doing wrong!!! @named @sessionscoped public class loginbean implements serializable { private static final long serialversionuid = -8825740128333470396l; @ejb private userdetaildao userdetaildao; private string description; public string getdscription() { return description; } public string submit() { userdetaildao.dosomething("test"); description = "testing"; return "next.xhtml"; } } and second bean @named @sessionscoped public class nextbean extends somebean implements serializable { private static final long serialversi

jdbc - Error with connection: java.sql.SQLException: ORA-00917: missing comma -

i'm working on web application using java servlets. trying implement login, logout, , registration functionality i'm little confused on how working. here code login page: to change template, choose tools | templates * , open template in editor. */ package hw5package; import java.io.ioexception; import java.io.printwriter; import java.sql.*; import java.util.uuid; import javax.servlet.servletexception; import javax.servlet.http.httpservlet; import javax.servlet.http.httpservletrequest; import javax.servlet.http.httpservletresponse; import javax.servlet.http.httpsession; /** * * @author tyler */ public class login extends httpservlet { /** * processes requests both http * <code>get</code> , * <code>post</code> methods. * * @param request servlet request * @param response servlet response * @throws servletexception if servlet-specific error occurs * @throws ioexception if i/o error occurs */ protected void processrequest(httpservletre

asp.net - How to redirect all .aspx URLs to their NEW location on a subdomain -

i completed transfer of large aspdotnetstorefront site (many pages/urls) domain's wwwroot subdomain. for seo reasons want auto 301 redirect & old urls end in ".aspx" new location on subdomain. (all paths being same except being in subdomain instead of wwwroot) example: old url= "http://www.mysite.com/c-2-some-product-page.aspx" desired new url = "http://store.mysite.com/c-2-some-product-page.aspx" i need check if requested page ends in .aspx, redirects "store" subdomain. should make sure requested old page url doesn't exist this site running on windows host, appliedi.net thanks much i think want try in global.asax file // untested, concept there. private void application_beginrequest(object source, eventargs e) { if (httpcontext.current.request.url.tostring().tolower().startswith( "http://www.mysite.com/")) { httpcontext.current.response.status = "301 moved

POST data from PHP and GET data in java servlet -

is there method can retrieve data (eg, username , password) php java servlet? thanks create post request in php: use curl: $ch = curl_init('http://www.example.com:8080/my-servlet/'); $data = '...' # data want send curl_setopt($ch, curlopt_post, 1); curl_setopt($ch, curlopt_postfields, $data); curl_setopt($curl, curlopt_returntransfer, true); $response = curl_exec($ch); curl_close($ch); a better, more concise approach, using pecl_http : $response = http_post_data('http://www.example.com:8080/my-servlet/', $data);

visual studio - Is there a simple way to create a custom VS action for personalised comments? -

feel free massively re-word question. basically, i'm stripping out huge portion of large framework - involves lot of commenting. can find of later batch commenting , copy-pasting marker before each block this: //myinitials_remove /*if (this code rubbish) { comment out; }*/ i'd create function 1 button press or key combination batch comment out selected code , automatically place tag @ beginning. instead of opening comment being '//' or '/*' 'myinitials_remove//' or 'myinitials_remove/*' is possible? edit thinking it, wouldn't mind if every single line began 'myinitials_remove//'. i think looking this: public sub cstylecomment() dim selection textselection = dte.activedocument.selection selection.toppoint.createeditpoint.insert("//myinitials_remov" & vbcrlf & "/*") selection.bottompoint.createeditpoint.insert("*/") end sub maybe version more suitable (aut

How to tell Mercurial to automatically accept "their" version during a merge conflict of any files in a particular directory? -

Image
first off, prefer not check in generated files @ manager insists. so, given constraints create mercurial "merge-patterns" take "their files" in directories named "generated" in working repo. have read hgrc documentation , related post , here think should like: [merge-patterns] generated/** = internal:other #keep files and placed in root .hg/hgrc file. when run hg update merge conflicts get: > hg update couldn't find merge tool internal:other #keep files specified generated/** merging generated/file.sv so modified "merge-patterns" this: [merge-patterns] **/generated/** = internal:other #keep files and here get: > hg update merging generated/file.sv so, no longer "couldn't find merge tool internal:other" warning still trying merge generated files. any ideas on how work? additional notes: we using mercurial version 1.7.5 having problems newer versions , subrepos. i working subrepos here structure

I'm using Notepad++ with JSON viewer and it won't recognize my JSON string -

do have problem json string or not using viewer? here string: (project related info removed) { "var": [{ "q": "aaaaaa", "a1": "bbb!", "a2": "ccc!", "a3": "ddd!" }] } maybe can try jsminnpp plugin in notepad++. parser better

listview - android how to save give file names to saved files by coding -

i have code saves json files internal or external memory, problem have how give them file names coding when users clicks on listview item assigns file name @ runtime, have no idea of start, have code saves file eg string filename = "storyone.json" i need code automaticly give file name .json extenton can me of start??? the other problem have listview of files updates stories avalible download listview dont know how make when list gets bigger onitemclick matches how many stories there here listview code @override public void onitemclick(adapterview<?> parent, view view, int position, long id) { if (position == 0) { showdialog(0); } if (position == 1) { showdialog(0); } if (position == 2) { showdialog(0); } if (position == 3) { showdialog(0); } so code can save 4 files, h

How do you install (build) Ruby 1.9.3 on OSX Lion? -

i've been working on installing ruby on mac, osx lion. i've installed xcode, gcc, readline, homebrew, , jewlerybox, have no idea what's going on. pointers? here's terminal says? hugo-pc:ruby-1.9.3-p125 squantowalks$ rvm install 1.9.3 fetching yaml-0.1.4.tar.gz /users/squantowalks/.rvm/archives extracting yaml-0.1.4.tar.gz /users/squantowalks/.rvm/src error running 'tar xmzf /users/squantowalks/.rvm/archives/yaml-0.1.4.tar.gz -c /users/squantowalks/.rvm/src ', please read /users/squantowalks/.rvm/log/ruby-1.9.3-p125/yaml/extract.log configuring yaml in /users/squantowalks/.rvm/src/yaml-0.1.4. error running ' ./configure --prefix="/users/squantowalks/.rvm/usr" ', please read /users/squantowalks/.rvm/log/ruby-1.9.3-p125/yaml/configure.log compiling yaml in /users/squantowalks/.rvm/src/yaml-0.1.4. error running 'make ', please read /users/squantowalks/.rvm/log/ruby-1.9.3-p125/yaml/make.log installing ruby source to: /users/squant

httpwebrequest - ETag not being returned by WebResponse Header in c# -

i trying extract etag response header. exist in response. can see using firebug , can see in response object using inspector: status: 200 ok x-api-version: 1.3.2 access-control-allow-origin: * x-runtime: 0.151298 connection: keep-alive content-length: 8185 cache-control: public, max-age=11216 content-type: application/json; charset=utf-8 date: fri, 09 mar 2012 01:40:05 gmt expires: fri, 09 mar 2012 04:47:01 gmt etag: "bd3fe1123a8f55e01ca859f4804e8fbe" last-modified: fri, 09 mar 2012 00:47:01 gmt server: nginx/1.0.11 all other code working fine, making httpwebrequest, getting respose etc. problem null when trying etag (which existing in response header). here simplified code: var request = (httpwebrequest)webrequest.create(validuri); setheaders(); // helper function set basic headers. var response = request.getresponse(); var stream = response.getresponsestream(); var reader = new streamreader(stream); var result

wxPython and ARCGIS -

i working on desktop application built wx python. application visualize maps(shapefiles) gis software , provide interactions map. looking through arcpy , arcgisscripting not sure if me render shapefile on panel. please let me know if possible? there application created wxpython gis here: http://thuban.intevation.org/ there's 1 grass: http://grass.osgeo.org/wiki/wxpython-based_gui_for_grass you can use starting places @ least.

android - How do I display admob ads across activities -

i able ad ads apps main activity. can not figure out how make display across 3 activities have in app. import com.google.ads.*; public class testactivity extends activity { private static final string my_ad_unit_id = "yourid"; private adview adview; @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); super.loadurl("file:///android_asset/www/index.html"); // create adview adview = new adview(this, adsize.banner, my_ad_unit_id); linearlayout layout = super.root; // change layout.addview(adview); adview.loadad(new adrequest()); xml file: <com.admob.android.ads.adview android:id="@+id/ad" android:layout_width="fill_parent" android:layout_height="wrap

php - Language Country Code Conversion -

does know how convert language country codes ones below name of actual language? en_us de_de en_gb it_it fr_fr i have dynamic input , need convert language country code corresponding name of language (i.e en_us = english, fr_fr = french). check code , works fine have used codes http://msdn.microsoft.com/en-us/library/ms533052%28v=vs.85%29.aspx <?php $strlcodes = '<tr><td>af</td><td>afrikaans </td><td>sq</td><td>albanian </td></tr> <tr><td>ar-sa</td><td>arabic (saudi arabia) </td><td>ar-iq</td><td>arabic (iraq) </td></tr> <tr><td>ar-eg</td><td>arabic (egypt) </td><td>ar-ly</td><td>arabic (libya) </td></tr> <tr><td>ar-dz</td><td>arabic (algeria) </td><td>ar-ma</td><td>arabic (morocco) </td></tr> <tr>

Using .gif file in android live wallpaper -

my question regarding post is possible set animated gif file live wallpaper in android? the method given in post not seem work. when put animated .gif file in /res/raw folder, there error says file cannot resolved or not field. there should know resources in raw folder or there other problem. following code. belleengine() throws ioexception { inputstream = getresources().openrawresource(r.raw.ballerina); if (is != null) { try { mbelle = movie.decodestream(is); mbelleduration = mbelle.duration(); } { is.close(); } } else { throw new ioexception("unable open r.raw.belle"); } thanks in advance! i have tried example works me. have tried different .gif images , doesn't seems problem. code . { /** * method init suitable wallpaper according time. */ private void initwallpaperaccordingtotime(inputstream inputstream

ios - Using Testflight, trying to generate Archive but error on chown for Entitlement.plist -

Image
i've done requisite search on google error haven't found useful i'm posting here leads. i'm using testflight. have followed the directions here xcode 4. when product -> build -> archiving...it compiles , signs using key when product -> archive...it fails message {some stuff before...but think culprit } /usr/sbin/chown -rh "entitlements.plist:staff" "/users/jtu/library/developer/xcode/deriveddata/myproject-agrwkgvjqjnrrvglrgpdcmvlquzy/build/intermediates/archiveintermediates/myprojectlite/installationbuildproductslocation/applications/playing cards lite.app" chown: entitlements.plist: invalid argument command /usr/sbin/chown failed exit code 1 i tried change permissions entitlements.plist file 777...no luck. i'm not stuck , can't create ipa archive testflight. any ideas on should try? i found culprit. i'm not sure how came "entitlements.plist" entered in install owner , alternate install owner.

split - Loading Big files into Hashes in Perl (BLAST tables) -

i'm perl beginner, please me out query... i'm trying extract information blast table (a snippet of looks below): it's standard blast table input... want extract information on list of reads (look @ second script below , idea of want do).... anyhow precisely i've done in second script: inputs: 1) blast table: 38.1 0.53 59544 gh8nflv01a02ed gh8nflv01a02ed rank=0113471 x=305.0 y=211.5 length=345 1 yp_003242370 dynamin family protein [paenibacillus sp. y412mc10] -1 0 48.936170212766 40.4255319148936 47 345 1213 13.6231884057971 3.87469084913438 31 171 544 590 34.3 7.5 123828 gh8nflv01a03qj gh8nflv01a03qj rank=0239249 x=305.0 y=1945.5 length=452 1 xp_002639994 hypothetical protein cbg10824 [caenorhabditis briggsae] 3 0 52.1739130434783 32.6086956521739 46 452 367 10.1769911504425 12.5340599455041 111 248 79 124 37.7 0.70 62716 gh8nflv01a09b8 gh8nflv01a09b8 rank=0119267 x=307.0 y=1014.0 length=512

image - Saving Surface to Bitmap and optimizing DirectX screen capture in C# -

after whole day of testing came code, captures current screen using directx (slimdx) , saves file: device d; public dxscreencapture() { presentparameters present_params = new presentparameters(); present_params.windowed = true; present_params.swapeffect = swapeffect.discard; d = new device(new direct3d(), 0, devicetype.hardware, intptr.zero, createflags.softwarevertexprocessing, present_params); } public surface capturescreen() { surface s = surface.createoffscreenplain(d, screen.primaryscreen.bounds.width, screen.primaryscreen.bounds.height, format.a8r8g8b8, pool.scratch); d.getfrontbufferdata(0, s); return s; } then following: dxscreencapture sc = new dxscreencapture(); ..code here private void button1_click(object sender, eventargs e) { stopwatch stopwatch = new stopwatch(); // begin timing stopwatch.start(); surface s = sc.capturescreen(); surface.tofile(s, @"c:\temp\test.png"

arrays - What is the most idiomatic style to force a computation using Sequences in f#? -

i have side-effective operation securities |> seq.map (fun x -> request.append("securities",x)) what idiomatic way have code perform ? i wrote seq.doit, itches module seq = let doit sa = sa |> seq.toarray |> ignore deferred sequences used when create sequences using seq.delay or sequence expression seq{}. function on sequence returning datatype other seq can force computation. alternatively, can use for loop instead of seq.iter : for s in securities request.append("securities", s) if want hide side effects , return request later use, seq.fold choice: securities |> seq.fold (fun acc x -> acc.append("securities", x); acc) request

objective c - Make Safari Browser appear in iPad/iPhone App -

i have app in process of writing , want have button on screen user can press go web page in safari. not want use uiwebview control , make own browser, want screen switch safari. can give me tips how this? you should able this: [[uiapplication sharedapplication] openurl:[nsurl urlwithstring: @"http://www.google.com"]];

Timing analysis of Clojure code -

hello clojure experts, i trying timing tests in clojure 1.3 , thought i'd ask question based on existing piece of code solves differential equation adapted blog post . code follows: ;; differential equation ;; dy/dt = f(y,t) = t - y (defn f [t y] (- t y)) ;; solve using euler's method (defn solveeuler [t0 y0 h iter] (if (> iter 0) (let [t1 (+ t0 h) y1 (+ y0 (* h (f t0 y0)))] (recur t1 y1 h (dec iter))) [t0 y0 h iter])) (defn multiplesolveeuler [] (let [steps '(1 10 100 1000 10000 100000) results (map #(second (solveeuler 0.0 0.0 (/ 1.0 %) %)) steps) errors (map #(- (math/exp -1) %) results)] (partition 3 (interleave steps results

java - Overlapping Wizard pattern in Android (sharing Activities) -

i'm considering following design app activity flow: wizard 1: mainmenuactivity-> activity1 -> activity 2 -> activity 3 -> activity final wizard 2: otheractivity -> activity1 -> activity 2 -> activity 3 -> activity final b so depeding wizard started need end different activity. whats best way of detecting way? passing along activities in order know "launcher activity" @ activity 3 nice method or have kind of issue? thanks

PHP, How to put an error in a specific spot -

you know how php errors show @ top of page. there way suppress , turn in $var? place somewhere in page. yes, set own error handler intercept , error besides outputting them wherever occur. don't think it's useful display php errors elegantly on page. php errors not meant pretty, they're not meant occur @ all. if see one, should jarring possible , should fix possible. they're meant during development. trying pretty them spending time on wrong part of code. in production, errors should logged log file , not visibly output on page @ all.

php - Getting jQuery's .post to work with Zend, error code 500 -

okay, trying make site using zend framework on php , jquery. make ajax call page 1 of controllers , controller echos code, jquery never "succeeds". got: jquery ajax call: $('.homelink').click(function() { $.ajax({ url: '/index/ajax/page/index', type: 'post', success: function(result){ alert(result); } }); }); the controller echo's following string: <p>home page content here</p> the problem function never called upon success send alert. any help? thanks. update: i discovered ajaxcontext switch. jquery call bit different. using url '/index/index/format/html'. the zend controller being call correctly however, nothing being returned still. console replies internal server error (code 500).

php - 2-phase commit - looking for an implementation -

i looking implementation of 2-phase commit protocol , yes new distributed transactions :) 2-phase commit have implemented between php application , remote 'application' (system). will have implement 2-phase commit scratch ? aware of modules implemented in language give me head start? -- not find on until :) appreciate help. take lixa transaction manager ( http://lixa.sourceforge.net/ ) integrates php , mysql starting release 0.9.0 it provides distributed transaction processing , 2 phase commit feature well. regards ch. f.

screen scraping - Is there a way to identify bolded (<b></b>) with Celerity -

i'm using celerity screen scraping , have come across need identify text elements in bold. celerity offers strong method not offer bold method. has figured out clever way around celerity or other tool. tried using: browser.html.gsub!(<b>,<strong>) browser.html.gsub!(</b>,</strong>) i though replace bold elements strong elements , use celerity's strong method, didn't seem work. thanks in advance help. it seems strange b missing can try: browser.elements_by_xpath('//b').each |b| puts "#{b} bold tag" end