Posts

python - Diffing two files while ignoring any missed lines -

i diffing 2 unsorted files , problem moment 1 of files gets line not present in other file, diff goes off. want write/print line not present , continue on. import re f1=open("file1","r") f2=open("file2","r") f=open("output","w") test_lines=f1.readlines() correct_lines=f2.readlines() test, correct in zip(sorted(test_lines), sorted(correct_lines)): if test.strip().split("(")[0].replace(" ","").strip() != correct.strip().split("(")[0].replace(" ","").strip() , test!="\n": print "oh no! expected %r; got %r." % (correct, test) else: towrite=correct + test f.write(towrite) else: len_diff = len(test_lines) - len(correct_lines) if len_diff > 0: print "test file had data." elif len_diff < 0: print "test file had little data." else: print "everythin...

Python How to get Scrapy Xpath data from Basic Table? -

<table> <br> <tr> <td width = 270><p align="left" style="margin-left: 0;"><b>info</b></p></td> <td><p> </p></td> </tr> <tr> <td width = 270><p align="left" style="margin-left: 10;">page&nbsp;count</p></td> <td><p> = 4 </p></td> </tr> ... trying response.xpath = 4 value table above. when inspecting element in chrome , pulling xpath way sill end [] value. tried: /html/body/table[1]/tr[2]/td[2] //table[2]/tr[2]/td[2] both fails. i'd td count text instead , following-sibling : //td[contains(p, "count")]/following-sibling::td/p/text() demo: $ scrapy shell index.html in [1]: response.xpath('//td[contains(p, "count")]/following-sibling::td/p/text()').extract() out[1]: [u' = 4 '] and if want extract ...

shader - How to create a texture alpha, with white and black colors only, in GLSL? -

Image
i looking reproduce glow effect tutorial , if understand well, convert first image "alpha texture" (black , white), , blur (rgb * a) texture. how possible create alpha texture, colors go white, , other go black? found : how render texture alpha? don't know how use these answers. thanks it appears misunderstanding diagram showing you. 1 texture, (a) shows rgb color , (b) shows alpha channel. (c) shows happens when multiply rgb a. alpha not "black , white", abstract concept , amounts range of values between 0.0 , 1.0 . human brain make sense out of it, interprets black ( 0.0 ) , white ( 1.0 ). in reality, alpha whatever want , unrelated color (though can used color). typically alpha channel generated post-process image filter, looks areas of texture above average luminance. in modern graphics engines hdr used , part of scene color bright displayed on monitor candidate glowing. intensity of glow derived how brighter lighting @ point mo...

sql server - best way to get iso into usa format -

trying convert date string usa format '20150316 16:28' '3/16/2015 4:28 pm' (note: 24hr format fine too) http://sqlfiddle.com/#!6/9eecb/862 the predefined format "g" give date time in format: select format(cast('20150316 16:20' datetime), 'g') update: select format( cast('20150316 16:20' datetime), 'd') + ' ' + format( cast('20150316 16:20' datetime), 'hh:mm') produces 3/16/2015 16:20 see these articles predefined , custom date time formats: https://msdn.microsoft.com/en-us/library/8kb3ddd4(v=vs.110).aspx https://msdn.microsoft.com/en-us/library/az4se3k1(v=vs.110).aspx note these vary culture.

c++ - Hook function call linux mint -

some days ago wrote simple hook/detour patching single call instruction. worked on ubuntu 12.xyz (32bit), updated linux mint 17.1(32bit) , segmentation fault. i have 2 projects target project calls function named goodguy library project loaded dlopen() overwrites offset call instruction in target application before overwriting call instruction offset, modify protection of page by: mprotect(pageof(address),pagesize,prot_write|prot_exec|prot_read) this works fine (returns 0). when debug programm, crashs while trying write address of call: memcpy((void*)(address + 1),(void*)&calloffset,4); looks not allowed overwrite instructions, why ? i diabled alsr , used -z execstack -fno-stack-protector flags g++. do know how allow application write instructions ? thank you, alex edit sorry guys, here code: target application: #include <dlfcn.h> #include <stdio.h> #include <stdio.h> #include <iostream> void goodguy(); //full lib path ...

javascript - <button> JQuery onclick works only once -

i have button onclick event works fine here: // create function remove "popup-open" classes // function used in onclick attribute (function( $ ){ $.fn.popupclose = function() { $( "body" ).removeclass( "popup-open" ) $( ".overlay_btn" ).removeclass("popup-open"); return this; }; })( jquery ); // if <button> exists // onclick read button id value // add "popup-open" class span idvalue class, fadein effect if ( $( "button.popup" ).length ) { $("button.popup").click( function() { var btnid = $(this).attr('id'); $( "body" ).hide().addclass( "popup-open" ).fadein(100); $( "."+ btnid ).hide().addclass( "popup-open" ).fadein(200); } ); } if ( $( "button.link" ).length ) { $("button.link").click( function() { var btnformaction = $(this).attr(...

PHP - What Host name should we provide in websocket server file -

hello trying implemented chat application website. have uploaded files online server check chatting.the code works fine in localhost problem server.php don't run. running file through ssh terminal. think might have problem here $server = new phpwebsocket(); $server->bind('message', 'wsonmessage'); $server->bind('open', 'wsonopen'); $server->bind('close', 'wsonclose'); // other computers connect, need change lan ip or external ip, // alternatively use: gethostbyaddr(gethostbyname($_server['server_name'])) $server->wsstartserver('127.0.0.1', 9300); my server.php file residing in directory public_html/domain.com/websocket/server.php

converter - Converting .3DC + .DDS files into .OBJ + .MTL + .TGA -

how go @ converting .3dc + .dds files .obj + .mtl + .tga? this simple do, goes file format i'll using .3dc file. download 3d object converter, you'll have pay fee if want program convert object without removing every 5th quad or triangle. after you've done open , go menu , click batch convert. add file want convert change options suit , choose export .obj wavefront don't take other type of .obj file format. can find near end of list. convert file. , voila! if texture in dds format or whatever , want change tga, use online picture converter. after amend file.mtl , change correct texture should call to. and there go!

python - serialized json size is much more than pickled or original dictionary -

i want send python dictionary through network sockets. used ujson , json dumping dictionary result size original dictionary. original dictionary size around 1mb json size around 6mb , pickled result around 1mb i used asizeof pympler , builtin len function getting size of results. note dictionary contains binary data encoded base64 converting text data.

CSS text button won't position in the center no matter what -

i trying style css navigation bar. did before table, works fine, trying un-ordered list , styling whatever do, text not go middle of button. may see buttons in code below: jsfiddle.net/anidimitrovaaanidimitrova/tbh62k9q/ i tried with: - text-align: center; - vertical-align: middle; - position: absolute - float:center; thanks lot in advance ideas might have. .mainheader nav a:link, .mainheader nav a:visited{ color:#ab6f80; display: block; padding: 7px 20px; /* come here assign height */ height:71px; line-height:71px; } line-height added - work fine 1 line of text in link... http://jsfiddle.net/tbh62k9q/2/

javascript - Google Materials Charts (Scatter) not showing trendlines or tooltips -

i'm using google charts, materials charts running in ie v11, , when things trendlines , tooltips no longer work. same happens if add column {type: 'string', role: 'tooltip'}, nothing appears. if change 'packages':['scatter'] to 'packages':['corechart'] and google.charts.scatter(...); to google.visualization.scatterchart(...); then works listed in documentation. don't know missing here. below example of trendlines not working. i've searched other questions can't find answer. <script type="text/javascript" src="https://www.google.com/jsapi"></script> <script type="text/javascript"> google.load('visualization', '1.1', {'packages':['scatter']}); google.setonloadcallback(drawchart); function drawchart() { var data = new google.visualization.datatable(); data.addcolumn('date', 'date...

java - Customize the output of a monitor -

i creating program using java. within program have ability create output on predefined monitor. ubuntu 14.10 test system has 2 monitors connected through dvi. unity grabs both monitors desktop. how access these monitors? there way create connection through /dev/*? or have in java program? you can use graphicsenvironment list of graphicsdevices attached system. if want to, can generate "virtual" desktop, combining devices areas together, for example

javascript - "TypeError: undefined is not a function" -

i'm learning js on codecademy , i'm stuck in "switch" element part. the instructions are: "create own switch statement in editor. can like! make sure include @ least 3 cases , default." i "typeerror: undefined not function" i'm sure it's dumb can't figure out , tried searching no luck either. and here's code: // write code below! var console = prompt("what's favorite console?"); switch(console) { case "ps4": console.log("it's favorite too!"); break; case 'xone': console.log("good choice!"); break; case 'wii': console.log("i don't it."); break; default: console.log("that's not current gen console!"); }; you're redefining console in first line. console used to, example, print messages. solution problem rename: var console...

PHP Array - Return specific elements of array and display them on one line -

i'm ready go crazy one. can't seem figure out how print out elements of array , put results on 1 line (with specific output). here's array data (after running through foreach statement: array ( [hostname] => server01 [server_id] => 4 [disk_mountpoint] => / [disk_datetime] => 1426395600 [disk_device] => /dev/mapper/volgroup00-logvol00 [disk_capacity] => 15g [disk_used] => 5.3g ) array ( [hostname] => server01 [server_id] => 4 [disk_mountpoint] => /var [disk_datetime] => 1426395600 [disk_device] => /dev/mapper/volgroup01-logvol00 [disk_capacity] => 107g [disk_used] => 52g ) array ( [hostname] => server01 [server_id] => 4 [disk_mountpoint] => /opt [disk_datetime] => 1426395600 [disk_device] => /dev/mapper/volgroup02-logvol00 [disk_capacity] => 156g [disk_used] => 127g ) here's foreach statement: foreach ($storage_...

mysql - Why does SQL NOT EXISTS return 1 record of all NULL values -

sql fiddle on following: create table tbl( col1 int, col2 int, col3 int); insert tbl values(1,1,1); insert tbl values(1,1,1); select sum(col1) c1, sum(col2) c2, sum(col3)c3 tbl not exists ( select 2 c1, 2 c2, 2 c3 ) i expecting return 0 records. instead returns 1 record of null values. can tell me why? p.s. trying understand not exists behavior. it's not exists . not exists evaluates false , since select 2 c1, 2 c2, 2 c3 returns row. means query equivalent to: select sum(col1) c1, sum(col2) c2, sum(col3) c3 tbl 0 saying that, sum semantics. sum in empty set should return value, , value in case null . from mysql documentation : sum(expr) returns sum of expr. if return set has no rows, sum() returns null. sum() returns null if there no matching rows.

c - protect sem_wait() from signals using pthread_sigmask() -

i have library accesses hardware resource (spi) via 3rd party library. library, , in turn spi resource, accessed multiple processes need lock resource semaphores, lock functions below: static int spi_lock(void) { struct timespec ts; if (clock_gettime(clock_realtime, &ts) == -1) { syslog(log_err,"failed read clock: %s\n", spisem, strerror(errno)); return 3; } ts.tv_sec += 5; if (sem_timedwait(bcoms->spisem, &ts) == -1) { syslog(log_err,"timed out trying acquire %s: %s\n", spisem, strerror(errno)); return 1; } return 0; } static int spi_unlock(void) { int ret = 1; if (sem_post(bcoms->spisem)) { syslog(log_err,"failed release %s: %s\n", spisem, strerror(errno)); goto done; } ret = 0; done: return ret; } now problem library used in daemon , daemon stopped via kill signal. kill signal while holding semaphore lock , hence servers c...

When does Powershell honour default values when using $null splat parameters? -

consider following function: function f1{ param( $sb = {}, $s = '' ) if ($sb -isnot [scriptblock]) { 'scriptblock' } if ($s -isnot [string] ) { 'string' } } now invoke splat parameter: ps c:\> $splat = @{foo='bar'} ps c:\> f1 @splat as expected, nothing returned. try again $null splat parameter: ps c:\> $splat = $null ps c:\> f1 @splat scriptblock oddly, scriptblock returned. clearly, @ least [scriptblock] parameter, powershell not honoring default value when $null splat parameter used. powershell honor default value [string] . going on here? for types powershell honour default values when using $null splat parameters? here's demonstration understand what's happening $splat = @{foo='bar'} "$(&{$args}@splat)" -foo: bar when splat hash table, gets converted -key: value string pairs become parameters function. now try: $splat = $null ...

python - Vagrant, Flask — App not running on 10.10.10.10, 127.0.0.1 -

i'm running app on local box via vagrant. python/flask app launches , prints: * running on http://127.0.0.1:5000/ * restarting reloader i found https://github.com/makersquare/student-dev-box/wiki/using-vagrant-for-development#testing-web-based-applications-in-vagrant suggests vagrant apps run on 10.10.10.10 (not 127.0.0.1 ), when navigate ip address (port 5000), same result: "this webpage not available". question: app running, on ip address? can't seem find it. need modify configuration files? thanks in advance. there many ways how run flask web app on virtual machine (managed vagrant). think following approach quite flexible, because don't have deal different ip address. looks developing on host machine. there 2 things need configure. in vagranfile , need configure port forwarding. vagrant.configure(2) |config| # use default box config.vm.box = "ubuntu/trusty64" # forward port guest machine:5000 -> host machine:5000...

Ionic - routing issue/button link -

i'm writing first ionic app , hit little problem. i have tab interface has login screen, once login can select tabs, on 1 tab screen have list of items need click show further options, can't quite these links work, think ui-sref bit wrong... looking second pair of eyes! linking profile view i'm struggling with, below app.js routing , page links on below. app.js .state('login', { url: '/login', templateurl: 'templates/login.html', controller:'loginctrl' }) // setup abstract state tabs directive .state('tab', { url: "/tab", abstract: true, templateurl: "templates/tabs.html" }) .state('tab.profile', { url: '/profile', views: { 'profile': { templateurl: 'templates.tab.profile.html', controller: 'profilectrl' } } }) then list page: <ion-content has-header="true" padding="true" class="viewer-panel"> ...

node.js - How can I search a MongoDB of regexes for matches against a given string? -

i have mongo database accessing via mongoose , node.js. database contains series of items called machine . each machine has field stored string , represents regular expression. want take given string (provided user) , check against regular expressions in database find potential matches. know can search database via regex this: machines.find({subject: {$regex: hi}}).exec(function(err, results) { // stuff results }); but how can reverse of this? you can using $where : machines.find({ $where: 'new regexp(this.subject).test(' + '"' + string + '") === true' }) also hi greg