Posts

Showing posts from May, 2011

Buffers and Web Audio API -

i'm working on building ambient sound generator college project , running slight issue. basically have 3 different files user can pause/play in combination, , each pause/play ok. issue if play more 1 sound @ time, 1 of 2 sounds continues play after i've hit stop. maybe can point me in direction of i'm going wrong and/or resources can learn more api. <head> <meta charset="utf-8"> <link rel="stylesheet" href="css/loopy_styles.css" /> <!--<script type="text/javascript" src="js/loop_functions.js"></script>--> <script> context = new (window.audiocontext || window.webkitaudiocontext)(); var soundbuffer1 = null; var soundbuffer2 = null; var soundbuffer3 = null; var soundbuffer4 = null; var soundbuffer5 = null; window.onload = function() { create_buffers(); }; function create_buffe

html - min-width in page body not working -

i have set minimum width of 767px on website avoid shrunk when viewing website on smartphone. issue is doesn't seem taken consideration (see screenshot below) idea why? many thanks css: html, body { height: 100%; min-width: 767px; -webkit-font-smoothing: antialiased; text-shadow: 1px 1px 1px rgba(0, 0, 0, 0.004); background: url('../images/background-produits.jpg')no-repeat center fixed; -webkit-background-size: cover; -moz-background-size: cover; -o-background-size: cover; background-size: cover; font-family: 'open sans'; font-size: 16px; font-weight: 300; line-height: 1.38; color: rgb(71, 64, 50); } you've got lot of things positioned absolutely. work correctly need have them contained in item relative positioning. yep, body tag, apparently. body {position: relative}

ruby on rails - Logout redirect error -

i having trouble logging user out , clearing sessions user. keep getting following error in rails server terminal window: started delete "/logout" ::1 @ 2014-12-01 17:17:47 -0500 actioncontroller::routingerror (uninitialized constant sessoinscontroller): here controller sessions: class sessionscontroller < applicationcontroller # sessions not active record model def new end def create user = user.find_by(email: params[:session][:email].downcase) if user && user.authenticate(params[:session][:password]) log_in user redirect_to user else # flash.now used when going homepage danger # message not there anymore # designed displaying flash on rendered pages flash.now[:danger] = "invalid email/password combination" render 'new' end end # logs out current user, check session_helper details def destroy log_out redirect_to

bash adds escape chars when passing a string with quotes -

i'm trying run msyql command includes quoted string, eg: mysql -h host -u=user -p=pass -e "show tables" database. here i'm having difficulty pass "show tables" quotes fuction executes command. run_cmd() # run command { local output=$1 local timeout=$2 shift 2 ( $* > $output 2>&1 ) & # .... } # query mysql query_mysql(){ local mysql_cmd=( "mysql -h $host --user=$user --password=$pass -e "show tables" $db") run_cmd $output $timeout "${mysql_cmd[@]}" } query_mysql i tried many combinations, command executed either without quotes or multiple single/double/escape chars. in cases final command becomes invalid due missing/additional quotes/chars. few of attempts & final command: "show tables" mysql -h localhost --user=root --password=foo -e show tables db1 'show tables' mysql -h localhost --user=root --password=foo -e ''\''show' 'tables

android - How is it possible to have feeds from different Urls in the same ListView -

with current project can take datas single url , display them in custom listview. there way can datas more 1 url , put in same listview if datas each url called differently? code allows me have items url: public class class1 extends fragment { private rssfeed myrssfeed = null; public class1() { } @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { view view = inflater.inflate(r.layout.tab1, null); if (android.os.build.version.sdk_int > 9) { strictmode.threadpolicy policy = new strictmode.threadpolicy.builder().permitall().build(); strictmode.setthreadpolicy(policy); } try { url rssurl = new url("url"); saxparserfactory mysaxparserfactory = saxparserfactory.newinstance(); saxparser mysaxparser = mysaxparserfactory.newsaxparser(); xmlreader myxmlre

ftp - Wait until zip fully written then continue, Bash Script -

i've been trying zip file , upload ftp using bash script, it's uploading corrupt zip file. i've had around , i'm trying use lsof | grep confirm file complete i'm not sure i'm doing. so i've got cd /var/test/tobezipped zip -r test.zip * folder="/var/test/tobezipped" zips=$(ls $folder) f in $zips ; while [ -n "$(lsof | grep $f" ] ; sleep 1 done ftp -n <<eof open myserver user user pass put test.zip eof done and test.zip corrupt @ time it's being uploaded, on other server it's not readable on server it's zipped on it's time check it. any kind of advice appreciated, i'm pretty new sort of thing , tried search around heaps find solution, not sure i'm going in right direction. in advance. from man page: put local-file [remote-file] store local file on remote machine. if remote-file left unspecified, local file name used after processing according

Android - Reload a Fragment that is Part of ViewPager -

i need reloading fragment part of viewpager. here current setup: reportactivity extends fragmentactivity , uses viewpager host 4 tabs tab 1 4. each tab fragment seperate layout. viewpager uses tabspageradapter switch between tabs , works expected. tab1fragment displays graph using static dataset. have added spinner dynamically change dataset , looking ways reload fragment can re-display graph correct dataset. following ints correspond values of spinner. static final int report_period_day = 0; static final int report_period_week = 1; static final int report_period_month = 2; static final int report_period_year = 3; i have method correctly calculates correct data based on the int passed in, struggling how create intent or other method recreate tab1fragment , passes int parameter. here want re-create fragment mreportperiodspinner.setonitemselectedlistener(new adapterview.onitemselectedlistener() { @override public void onitemselected

winforms - C# TcpClient updating (for an IRC client) -

i bascially trying make barebones irc client c#, winforms, , tcpclient display raw data irc server onto the text area (textbox1). struggling on updating code (reading stream server). right have timer runs function ( listener ) reads tcp stream every 100ms. application freezes , cursor disapeears, , application hangs trying grab more data. better updating function? using system; using system.collections.generic; using system.componentmodel; using system.data; using system.drawing; using system.linq; using system.text; using system.threading.tasks; using system.windows.forms; using system.io; using system.net.sockets; namespace logernirc { public partial class form1 : form { public form1() { initializecomponent(); } //variables tcpclient client; streamreader sr; streamwriter sw; //functions public void connect(string host) { client = new tcpclient(host, 6667);

How to read trc files from different directory in matlab -

i have program reads data .trc files. of now, can read .trc files in current directory i.e matlab folder. if want read file, have copy file in matlab folder. there way can move different directories , choose .trc file? have tried using dir , uigetdir etc. nothing seems work! it's pretty straightforward filter results dir command file extension if specify folder search wildcard character in place of file name. can loop on generated list of file names in output structure (as shown) or whatever need files. foldername = 'c:\path\to\target\folder\'; filelist = dir(strcat(foldername, '*.trc')); k = 1:length(filelist) filehere = fullfile(foldername, filelist(k).name); % need files in here end

c - Parallelizing a for loop (1D Naive Convolution) in CUDA -

can please me convert nested loop cuda kernel? here function trying convert cuda kernel: // convolution on host void conv(int* a, int* b, int* out) { (int = 0; < n; ++i) (int j = 0; j < n; ++j) out[i + j] += a[i] * b[j]; } i have tried hard parallelize code. here attempt: __global__ void conv_kernel(int* a, int* b, int* out) { int = blockidx.x; int j = threadidx.x; __shared__ int temp[n]; __syncthreads(); temp[i + j] = a[i] * b[j]; __syncthreads(); int sum = 0; (int k = 0; k < n; k++) sum += temp[k]; out[i + j] = sum; } your cpu conv function appears doing (for n = 4, example): a0b0 a0b1 a0b2 a0b3 + ^ a1b0 a1b1 a1b2 a1b3 + n a2b0 a2b1 a2b2 a2b3 + rows a3b0 a3b1 a3b2 a3b3 = v ------------------------------------------ out0 out1 out2 out3 out4 out5 out6 <- (2*n)-1 columns

if statement - Hangman Python Repeats Fucntions -

when try run code keeps repeating,"so far have guessed" when want repeat once. output name when guess made should : secret_word = hello , after every word should h???o or h?ll? def get_secret_word(): while true: secret_word = input('please enter word guessed\nthat not contain ? or whitespace:') if not ('?' in secret_word or ' ' in secret_word or secret_word == ''): return secret_word def is_game_over(wrong_guess, secret_word, output, chars_guessed): if wrong_guess == 7: print('you failed guess secret word:', secret_word) return true guess in secret_word: if guess in chars_guessed: output += guess else: output += '?' if not ('?' in output): print('you correctly guessed secret word:', secret_word) return true else: return false def display_hangman(wrong_guess): if wrong_guess == 1:

In C#, what's the safe way to do generically convert a primitive to a string for serialization? -

i'd generically serialize class/struct in c#. sake of simplicity, let's assume class/struct can 1 level deep (no structs of structs). here's i'd write system.text.stringbuilder builder = new system.text.stringbuilder(); system.reflection.fieldinfo[] fields = obj.gettype().getfields(); foreach (system.reflection.fieldinfo info in fields) { object fieldvalue = info.getvalue(obj); if (fieldvalue != null) { builder.append(fieldvalue.tostring()); } ... } unfortunately far can tell won't work because tostring() culture sensitive. in other words single might output 12.345 or 12,345 depending on culture settings. is there other non-culture sensitive tostring can call primitive types? also, there non-culture sensitive generic string object function. i'm using object value = system.convert.changetype(string, sometype); but that's apparently culture sensitive. :( for changetype, there's overload accepts iform

Oracle Substr SQL -

i got list of database. **name** oee_line_abc oee_line_abcd oee_line_qwertyuiop oee_line_zxcvbd i need grab name after oee_line_ . not standardize how many characters. google fix how many characters. example : substr(name,10,3) result: 'abc' if use above substr, able grab 1st value ( oee_line_abc ) without problem, when comes 2nd value, there's problem because above substr can retrieve 3 characters. expected result: the sql statement able grab values after oee_line_ result(return name without oee_line_ ): name = abc name = abcd name = qwertyuiop name = zxcvbd any related post share , answer? i suggest looking last '_ ' , taking string there: select substr(name, length(name) - instr(reverse(name), '_') + 2)

haskell - Missing dependencies for chart-cairo on linux mint 17 -

i'm struggling install gtk / gtk2hs binding on linux mint 17. the first time encountered problem when tried glade support in haskell. there same problems purely fun let be. this time trying visualize graph haskell chart . the problem occured in forth step cabal install chart-cairo i'm using ghc version 7.6.3, cabal version 1.16.0.2, gtk2hs-buildtools version 0.12.4-2ubuntu1 (from package manager), gtk2hsc2hs version 0.13.6 (this glade needs have >=0.13.8, can't find newer version) things i've tried far: after downloading gtk2hs-buildtools package manager updated cabal , installed tools command line added "$home/.cabal/bin" front of $path (after gtk installed correctly) cabal install chart-cairo gets me error message resolving dependencies... [1 of 2] compiling setupwrapper ( /tmp/cairo-0.13.0.2-19862/cairo-0.13.0.2/setupwrapper.hs, /tmp/cairo-0.13.0.2-19862/cairo-0.13.0.2/dist/setup/setupwrapper.o ) [2 of 2] compiling main

mysql - Segregating sandbox environment -

for site using sandbox mode, such payment site, separate database used, or same one? i examining 2 schemas production , sandbox environment. here 2 options. option 1: clone database, route requests correct database based upon sandbox mode. option 2 single database, 'main tables' have is_sandbox boolean. what pros , cons of each method? in situations, you'd want keep 2 separate databases. there's no reason have 2 intermingled in same database, , lot of reasons keep them separated: keeping track of entities in "realm" (production vs. sandbox) work code, , you'll have include in lot of places. you'll need logic in database schema well. unique indexes have include realm, instance. if forget of code, you've got potential security vulnerability. malicious user cause data 1 realm influence other. depending on application is, range anywhere annoying terrifying. (if it's payment application, instance, potential conse

R: How to compute mean of every 10 lines of a variable -

i have datasets collected every 1 min, have replace data mean of 10 mins data. have r code. for(k in 1:(length(temp[,1])/10)){ temp2[k,1]<-temp[1,1] temp2[k,2]<-temp[k*10,2] temp2[k,3]<-mean(na.omit(as.numeric(temp[((k-1)*10+1):k*10,3]))) } however, efficiency of code tooooo low. , 1 more question. because of missing data, time variable not continuous. , have compute data of every true 10 mins (that 2014-01-01 00:00 2014-01-01 00:10, example), no matter how many obs in 10 mins. loop goes to tmp<-na.omit(temp[temp[,2]>(st+600*(k-1)) & temp[,2]<=(st+600*k),]) temp2[k,1]<-tmp[1,1] temp2[k,2]<-st+600*k temp2[k,3]<-mean(na.omit(as.numeric(tmp[,3]))) which cannot bearable. , cannot handle case "some months missing". so, how can solve in r, while efficiency not low. original data: time var1 2014-01-01 00:01 10 2014-01-01 00:02 12 2014-01-01 00:03 43 ... 2014-01-01 00:10 52 desired output: time var1 2014-01-01 00

javascript - Connect two socket.io clients together (Establish a socket to socket, cross browser connection) -

i'd know if there's way establish p2p connection between 2 browsers using socket.io-client (but i'm willing use else may trick). both browsers connected node.js app serving http requests express, stores both clients's ip addresses (and ports when running locally). i'd add third connection links both clients (let's call them , b) directly, messages/data go straight 1 client another, without transiting through node.js server. is feasible? if so, how? so far, i've tried connecting 2 clients (let's call them , b) following code: client a: a_to_server_socket = io(); a_to_server_socket.on('p2p', function(address_b){ a_to_b_socket = io(address_b); // instantiates new socket a_to_b_socket.on('connect', function() { console.log('connected!'); }); }); i'm not sure code client b. i've tried: repeat above code b, using b's own address (to override default of connecting server) repea

javascript - jquery drag n drop, not allow drop on clone drop container -

try drag item , drop clone div, it's not working. it's seem jquery drag n drop not allow drop on clone item. drag n drop working on first one, after click add more dropzone, , try drop item new dropzone. it's not allow to. here jsfiddle $(document).on("click", ".add_dropzone", function(e){ $('<div class=\"dropzone\"></div>').insertafter($('.dropzone').last());}); $( "ul li" ).each(function(){ $(this).draggable({ helper: "clone" }); }); $( ".dropzone" ).droppable({ activeclass: "active", hoverclass: "ui-state-active", tolerance: "touch", accept: ":not(.ui-sortable-helper)", drop: function( event, ui ) { var targetelem = $(this).attr("id"); $( ).addclass( "ui-state-highlight" ); if($(ui.draggable).hasclass('draggable-source')) $

AngularJS - Why watcher is removed? -

i new angularjs , follow long tutorial started. in 1 tutorial shows how remove watcher example below: $scope.breakit = $scope.$watch('mydata.val',function(newval){ $scope.mydata.toolong = newval.length >3; }) <button ng-click="breakit()">break it</button> it works, don't understand why calling breakit function remove watcher? $scope.$watch returns function deregisters watcher when called.

Change Background Image in Itext to watermark or alter opacity c# ASP.net -

i want make background image in itext transparent here code image: string root = server.mappath("~"); string parent = path.getdirectoryname(root); string grandparent = path.getdirectoryname(parent); string imagefilepath = parent + "/images/logo.png"; itextsharp.text.image jpg = itextsharp.text.image.getinstance(imagefilepath); jpg.scaletofit(1700, 800); jpg.alignment = itextsharp.text.image.underlying; jpg.setabsoluteposition(100, 250); jpg.scaleabsoluteheight(500); jpg.scaleabsolutewidth(500); any idea? please take @ backgroundtransparant example. variation on backgroundimage example. in code, you're adding image document instance. that's ok, if want make such image transparent, need introduce soft mask. that's not difficult, there's easier way make background transparent: add image direct content, , introduce pdfgstate defining opacity: pdfcontentbyte canvas = writer.getdirectconte

noclassdeffound error in java, linux -

running java class shell script: java -cp $classpath cg_gpsrequest "dbname","oracle.jdbc.driver.oracledriver","abc","abc" while running script in unix, getting error, exception in thread "main" java.lang.noclassdeffounderror: cg_gpsrequest caused by: java.lang.classnotfoundexception: cg_gpsrequest class file name. okay.. if understand correctly.. i think problem package name specification.. your calss cg_gpsrequest must have specified in packaging way example com.xxx.yyy.cg_gpsrequest so think jvm searching class com.xxx.yyy.cg_gpsrequest in patter please run script following modifications. java -cp $classpath com.xxx.yyy.cg_gpsrequest "dbname","oracle.jdbc.driver.oracledriver","abc","abc" this assumption have created class in pacakgin hirarechy since havent specified more information.

Parsing regex in javascript -

this question has answer here: javascript regex, use escape characters? 3 answers i'm unable parse regex. i've tested regexpal.com , regex101.com (by setting expression "(?:^csrf-token|;\s*csrf-token)=(.*?)(?:;|$)" , test string "__ngdebug=false; csrf-token=b2ssoj4jnolpdmxahn4corpvfoo4ngsupej25tdj") works. the example jsfiddle . function getcookie(name) { var s = "__ngdebug=false; csrf-token=b2ssoj4jnolpdmxahn4corpvfoo4ngsupej25tdj"; var regexp = new regexp("(?:^" + name + "|;\s*"+ name + ")=(.*?)(?:;|$)", "g"); var result = regexp.exec(s); return (result === null) ? null : result[1]; } alert(getcookie("csrf-token")); if s "csrf-token=b2ssoj4jnolpdmxahn4corpvfoo4ngsupej25tdj" , works fine. please tell me what's wrong

javascript - math.pow results not displaying -

trying math.pow function display not. labels should answer 77^39 mod 517, etc. <body> <p><input type="button" value="encrypt message" id="encbutton" onclick="encrypt()" name="encbutton" /></p> <p id="encryptresultlabel1"></p> <p id="encryptresultlabel2"></p> <p id="encryptresultlabel3"></p> <p id="encryptresultlabel4">&nbsp</p> </body> <script> function encrypt(){ var g = ((math.pow(77, 39)) % 517); var h = ((math.pow(65, 39)) % 517); var j = ((math.pow(84, 39)) % 517); var k = ((math.pow(73, 39)) % 517); displayresult(g, "encryptresultlabel1"); displayresult(h, "encryptresultlabel2"); displayresult(j, "encryptresultlabel3"); displayresult(k, "encryptresultlabel4"); } </script> use math instead of math . refer link more detail. var g = ((math.p

arrays - How do I fix the error: java.lang.ArrayIndexOutOfBoundsException: 1? -

this question has answer here: how avoid arrayindexoutofboundsexception or indexoutofboundsexception? [duplicate] 2 answers all want return two-dimensional point array reason keep receiving error message. can me fix please? error message directed toward line of code @ end of first 'if' statement. btw - method takes board , finds matches of length 3 or greater , returns points in single array. both horizontally , vertically. supposed iterate through each point on board, check this. public static point[][] findmatches(board b) { int counter = 0; int prev = 2; int x = 0; int y = 0; point n = new point(x,y); point[][] foundmatches = new point[1][0]; //instead of 1? for(y=0; y<b.getsize(); y++) { for(x=0; x<=b.getsize(); x++) { if (buildpossiblematchrow(n,b).length >=3 ) //switch x , y

sql - Mysql wrong syntax -

an example: select avg(cost) items seller_id=6 lets want find average cost of items seller 6 , average cost of items seller 10. need in 1 sql. when seller_id = 6 , 7. gives me average cost of 6 , 7. want average of 6 , average of 7. this actual question: our orders have 5 priorities: "1-urgent", "2-high", "3-medium", "4-not spec", "5-low". type of orders has highest sum of ‘total price’? my sql: select sum(o_totalprice) orders `o_order-priority`='1-urgent' , '2-high' , "3-medium" , "4-not spec" , "5-low" select seller_id,avg(cost) items seller_id in (6,10) group seller_id and if want sellers remove seller_id in (6,10) clause sql fiddle 2 sellers sql fiddle sellers edit based on question's edit select o_order-priority, sum(o_totalprice) total orders group o_order-priority order total desc limit 1 that gives o_order-priority has maximum sum. , if remov

java - Facebook Fetching friends in custom layout -

i trying fetch facebook friends in custom layout. have updates libraries , jar files new fb sdk version.. still facing error.. can please on this.. kind of you.. here placing module of fetching friends private void showfriendlist() { if (session.getactivesession() != null) { session.openactivesession(invitefriendsactivity.this, true, new statuscallback() { @override public void call(session session, sessionstate state, exception exception) { // todo auto-generated // method stub list<string> permissions = session.getpermissions(); permissions.add("user_friends"); session.newpermissionsrequest request = new session.newpermissionsrequest( getparent(), arrays.aslist("user_friends"));

maven - When we get "Can't process temp ncss xml file" error? -

when type of error in javancss an error has occurred in javancss report report generation. can't process temp ncss xml file. changed goals , options findbugs:findbugs javancss:report test findbugs:findbugs test javancss:report in jenkins.

java - Wicket info, warn, error messages -

i need implement kind of component trigger functions depending on message type (warning, error, info), feedback panel not suitable purpose. don't know how fetch these messages on every request, can me? you can take @ source code feedbackpanel , see component does. there apis available @ messages. browsing can see feedbackpanel uses feedbackcollector collect available messages. either can use feedbackcollector directly, or use example own code.

sql - How can I get the maximum date of both passed and failed results using MySQL? -

i new mysql. need sql query below expected results. please check following, table: user_results id cid uid tid pass date 1 23 34 2 y 7/8/2013 10:24:47 2 23 34 2 n 11/27/2014 10:36:32 3 23 34 3 y 12/9/2013 10:24:47 4 23 34 3 n 11/27/2014 10:39:10 5 23 34 4 y 10/26/2013 10:24:47 6 23 34 4 n 11/27/2014 10:38:08 7 59 93 2 y 11/24/2013 9:34:23 8 69 82 2 y 11/28/2014 9:04:22 9 69 82 2 y 11/28/2014 8:59:52 10 69 82 4 y 11/28/2014 8:59:52 11 69 82 4 y 11/28/2014 9:10:40 12 69 82 4 n 11/28/2014 9:12:01 13 72 72 2 n 12/1/2014 6:46:02 14 73 69 2 n 12/1/2014 6:49:29 15 73 69 3 n 12/1/2014 6:51:31 16 73 69 3 n 12/1/2014 7:11:25 below 1 expected results, id cid uid tid pass date 1 23 34 2 y 7/8/2013 10:24:47 3 23 34 3 y 12/9/2013 10:24:47 5 23 34 4 y 10/26/2013 10:24:47 7 59 93 2 y 11/24/2013 9:34:23 9 69 82 2 y 11/28/20

java - how to handle this InputMismatchException? -

in code below i'm getting inputmismatchexception @ line 80 before i'm giving input. why this? try { loop:while(true) { choice=sc.nextint(); switch (choice) { case 1: term=3; break loop; case 2: term=6; break loop; default: system.out.println("invalid input.. enter again"); choice=sc.nextint(); } } } catch (inputmismatchexception e2) { system.out.println("wrong format!! enter number"); choice=sc.nextint(); //line 80 } consume end of line: catch (inputmismatchexception e2) { system.out.println("wrong format!! enter number"); sc.nextline(); // add choice=sc.nextint(); //line 80 } in addition, shouldn't have 2 choice=sc.nextint(); in loop. and want put try-catch inside loop, in order stay in loop after exception caught.

c++ - How can I deal with undesired template instantiation for a function that isn't called? -

i'm trying implementing code want call templated methods based on type traits. unfortunately, methods instantiated types (that never called said types) incompatible function, causes compilation errors. ideally use traits prevent said uncalled methods being instantiated that's not case, i'm looking workaround or design pattern can use. i have few simple pod structs. each type has different members (their existence indicated corresponding traits) struct thinga { int a; }; struct thingab { int a; int b; }; struct thingabc { int a; int b; int c; }; template <typename thing> struct thingtraits { static const bool has_a=false; static const bool has_b=false; static const bool has_c=false; }; here's template function; thinga, thingab , thingabc can passed either src or dst type template<typename src, typename dst> void assign(src const &src, dst &dst) { constexpr bool c_a = thingtraits<src>::has_a

android - How to get media file from which they already have downloaded via Google Play Music -

i'm working on music application android.i download songs google play music , enable option in google play music "keep on device" . using contentresolver query "managedquery(mediastore.audio.media.external_content_uri, null, null,null, null)" in music application shown songs files (note:songs saved on phone memory , sdcard) except downloaded files purchased "google play music" , saved on device. is there solution show album name or track purchased "google play music? lot in advance!