Posts

Showing posts from June, 2013

recursion - Recursing Binary Decision Diagrams in SML -

Image
in 1 of classes @ university, learning functional programming through sml/nj. i have been given assignment requires perform number of operations on binary decision diagrams. (conjunction, disjunction, not, etc.) based on truth table i have following function defined fun ifthenelse(p,q,r) = if p q else r; then, have bdd (robdd) datatype declared such datatype robdd = true | false | ifthenelse of string * robdd * robdd; so far straightforward. i'm getting lost on operating on bdd's, instance, creating robdd represents conjunction of 2 robdd's. my function declaration far looks this infix bddand; fun op bddand(first:robdd,second:robdd) = ... it called 2 robdd's, this val conjunction = ifthenelse("p", true, false) bddand ifthenelse("q", true, false); from here, i'm not sure start. professor has given hint: of course, true bddand anyrobdd anyrobdd . ordering: if you’re asked comp

android - Why getView not getting called? -

i have adapter extends simplecursoradapter. reason can't seem see, getview not being called. have breakpoint inside getview , never gets there , list shows empty. can take thru , see i've done wrong? package com.example.ok1; import java.text.simpledateformat; import java.util.date; import android.app.activity; import android.content.contentvalues; import android.content.intent; import android.content.sharedpreferences; import android.content.sharedpreferences.editor; import android.database.cursor; import android.database.sqlexception; import android.database.sqlite.sqlitedatabase; import android.os.bundle; import android.util.log; import android.util.sparsebooleanarray; import android.view.menu; import android.view.menuitem; import android.view.view; import android.widget.adapterview; import android.widget.adapterview.onitemclicklistener; import android.widget.listview; import android.widget.textview; import android.app.listactivity; public class mainactivity extends a

string - reading unicode input from user in java -

i have simple console program in java, try input user input in hebrew "שלום" when tried read ???? , wish "שלום" , how best way? my code: public static void main(string[] args) { string s; scanner in = new scanner(system.in); system.out.println("enter string"); s = in.nextline(); system.out.println(s); } } output: run: enter string שלום ???? build successful (total time: 5 seconds) i know should use utf-8 dont know how... help?

Videos converted using FFMPEG do not have video duration information -

i using ffmpeg convert uploaded videos .flv, after conversion flv video doesn't have information it's duration. user cannot rewind/forward, replay or see specific part of it. code follows: "ffmpeg -i $srcfile_path -s 320x240 -ar 44100 -b 2048k -r 12 $desfilepath"; please help. in advance. i ran following command , worked. "ffmpeg -i $srcfile_path -f flv - | flvtool2 -u stdin $desfilepath" this requires flvtool installed on system. using ffmpeg , flvtool2 enabled server, worked.

Extjs Store DataModel Subfield Null Error -

when try load remotely data grid error subfields: cannot read property 'id' of null my datamodel: ext.define('ruledatamodel', { extend: 'ext.data.model', fields: [ { name: 'id'}, { name: 'createtime', type:'date', dateformat: 'timestamp', convert:function(v,j){ return (v != null?new date(v):null);}}, { name: 'discountpercent'}, { name: 'discountamount'}, { name: 'discountoversalepriceflag', type: 'boolean'}, { name: 'minsalepricetotal'}, { name: 'maxcount'}, { name: 'execorder'}, { name: 'clearanceincludedflag', type: 'boolean'}, { name: 'relatedproductmincount'}, { name: 'promocoderuletypename', mapping: 'promocoderuletype.friendlytype'}, { name: 'groupname'},

if statement - Multiple nested if blocks in google spreadsheets formulas -

im trying write nested if statement pseudo code : =if(h4=1, "correct", if(h4=2, "correct"), if(h4=3, "correct"), if(h4=4, "correct")) but im getting following error, if write out code , add if statement each time. ie. start first if block , add more testing each time, breaks when add third statement. wrong number of arguments if. expected between 2 , 3 arguments, received 4 arguments. is there better way nest if blocks in google spreadsheets ? ive made google spreadsheet of issue here : https://docs.google.com/spreadsheets/d/1mbomatni5c_spsvudcqpeanhtofr36kglg9bxueazxu/edit#gid=0 (the above code example of nesting if blocks, not actual issue im trying solve) the error simple syntax issue - placement of parentheses - here correct: =if(h4=1, "correct", if(h4=2, "correct", if(h4=3, "correct"))) i fixed on spreadsheet. every if statement must have 3 parts essentially, if(this, this,

java - How to ensure a class can only be instantiated by Spring? -

i re-factoring legacy java application use spring. this involves declaring application classes spring beans , replacing occurrences of new context.getbean or di . i'm re-writing application logic in way classes become singletons. since being instantiated using new in other locations, multiple copies exist mess business logic. i'd ensure application explicitly fails whenever tries instantiate object itself, instead of running , misbehaving in unpredictable ways. (i'm not sure re-factoring has covered 100% of application there still might new lurked in corner) what best way of ensuring class can instantiated spring container? (i'm hoping avoid writing factory each class) as question in particular scenario 1 copy of object should exist fetched context, multiple copies mess business logic. you can create classic singleton , use getinstance() method factory method in bean definition in spring's xml file: <bean id="mybean" clas

python - Summing over ellipsis broadcast dimension in numpy.einsum -

in numpy, have array can either 2-d or 3-d, , reduce 2-d while squaring each element. tried , doesn't work: a = np.random.rand(5, 3, 3) np.einsum('...ij,...ij->ij', a, a) it returns error: valueerror: output has more dimensions subscripts given in einstein sum, no '...' ellipsis provided broadcast dimensions. i suppose einsum doesn't assume when ellipsis goes away in right hand side, want sum on ellipsis dimension(s), if exist. there "elegant" way (i.e. without checking number of dimensions , using if statement) tell want 3-d: a = np.random.rand(5, 3, 3) np.einsum('aij,aij->ij', a, a) and 2-d? a = np.random.rand(3, 3) np.einsum('ij,ij->ij', a, a) sometimes 'elegant' way handle variable dimensions use set of if tests, , hide them in function call. example @ np.atleast_3d ; has 4way if/else clause. i'd recommend here, except adds dimension @ end, not start. if clauses using reshape not

verilog - Is this code structure going in the right direction? -

i trying utilize 7 segment display. have written module want take 4 inputs , change hex output. there seems issue unpacked/packed arrays , don't know on earth i'm doing. appreciated. module hexdisplay(hex, c0, c1, c2, c3); input c0; input c1; input c2; input c3; output hex[6:0]; reg out[6:0]; always@(*) begin case({c3, c2, c1, c0}) 4'b0000:out [5:0] = 1; // 0001-1111 go here //... default:out [6:0] = 0; endcase assign hex = out; end endmodule errors: error (10773): verilog hdl error @ lab2pre.v(55): declaring module ports or function arguments unpacked array types requires systemverilog extensions error (10133): verilog hdl expression error @ lab2pre.v(61): illegal part select of unpacked array "out" error (10133): verilog hdl expression error @ lab2pre.v(62): illegal part select of unpacked array "out" err

database - mysql search LIKE not working for long phrase -

i have mysql table, type 'myisam', collation: 'latin1_swedish_ci'. inside it, have column named 'content'. inside there, have row following content: <p>the state have different advantage on other states, 1 of largest populations in nation blablablabla. </p> my query in phpmyadmin , in php file: select * `pages` `content` '%with 1 of largest populations%' order `pages`.`title` asc limit 0 , 30 0 rows returned. the weird thing if edit query this: select * `pages` `content` '%with 1 of largest%' order `pages`.`title` asc limit 0 , 30 then , 1 rows returned, , works. is there setting might limit search query few words or few characters? most there other whitespace character(s), otherwise, query seems fine. try largest populations should return 0 recs. so replace, characters column before, searching. you can find here

java - Can't open file even though it exists at the given directory -

import java.io.*; file thisun = new file("c:\\users\\ch\\documents\\dictionary.txt"); system.out.println(thisun.canread()); for reason can't read file though exist @ given directory : / i'm sure it's simple, won't see it. i've tried doing different directories. also, if want open file in same folder .java file. know in c++ defaults wherever .cpp file located don't know equivalent java.

javascript - Deploying First Express.js App, Someone please tell me how bad my server logic is -

i deploy first express.js app , need tell me if messing up. i running ubuntu ec2 using nginx proxy port 80 requests socket node.js app listening on. to start app, using pm2. when wrote server app, included node.js cluster module fork , cluster needed. deployment time, see pm2 offers clustering. here server pm2 running on production server: confus.at('development', () => { spawnworker() }) confus.at('production', () => { if(cluster.ismaster) { master() } if(cluster.isworker) { spawnworker() } }) function spawnworker() { const port = app.settings.server.port app.server = http.createserver(app) app.server.listen(port, () => { utils.success(util.format('[+] listening on %d', port)) }) } function master() { lodash.foreach(os.cpus(), () => { cluster.fork() }) cluster.on('fork', (worker) => { utils.success('[+] forked worker', worker.id) }) cluster

jquery - Create var's automatically from json key,value pairs for global use -

update: remembered can store them jquery(document).data(key,value); later use, idea ? expensive option performance-wise ? i trying create var's automatically json array key,value pairs later use. so created 2 sets of settings, 1- default settings (defsets) 2- user settings (usrsets). idea use user setting if exists, otherwise fallback default setting. not want write in vars 1 one, there way create global vars these arrays later use in various places ? sth along lines like: var [key_name] = [key_value_read_from_user_setting_or_default_set]; here actual code below; problem is, seems create vars within each loop, cant access them globally think. jquery(document).ready(function(e) { // read default settings array cookie if exist, otherwise create initial default settings , save if (jquery.cookie("defsets") != null) { var defsets = jquery.parsejson(jquery.cookie("defsets")) } else { var defsets = { 'ord': 'true', '

cluster computing - How to see the current user's queue in SLURM -

on cluster managed slurm, want check queue of current user (and cluster). normally, have use command: squeue --user=username --clusters=clustername the problem this, apart fact rather long command use frequently, needs username. have created script in @ point want check queue of user, have username first. i have workaround these, great if use command respective 1 loadleveller: llu is there that? or can somehow specify "current user" in --user flag? you may use alias in /etc/bashrc file (or ~/.bashrc users): alias llu="squeue --user=$user --clusters=clustername" edit you use alias not depend on environment variable: alias llu="squeue --user=`whoami` --clusters=clustername" or alias llu="squeue --user=`logname` --clusters=clustername"

maven - Error putting item in DynamoDB with AWS Java SDK and Hadoop -

i'm using hadoop 2.7, hadoop-core version 1.1.2 , aws java sdk 1.10.50. when attempt put item on dynamodb, following error: java.lang.nosuchfielderror: instance @ com.amazonaws.http.conn.sdkconnectionkeepalivestrategy.getkeepaliveduration(sdkconnectionkeepalivestrategy.java:48) what found error due conflict of aws sdk , httpcore version. running in code: classloader classloader = myclass.class.getclassloader(); url resource = classloader.getresource("org/apache/http/message/basiclineformatter.class"; system.out.println(resource); the output is: jar:file:/usr/local/cellar/hadoop/2.7.0/libexec/share/hadoop/common/lib/httpcore-4.2.5.jar!/org/apache/http/message/basiclineformatter.class indicating still using conflicting version. but on pom.xml, i've added: <dependency> <groupid>org.apache.httpcomponents</groupid> <artifactid>httpclient</artifactid> <version>4.4.1</version> <scope>comp

javascript - bootstrap carousel acting weird -

so created website this template , found carousel not sliding automatically except first click prev or next button. i check javascript template , not finding related carousel except adjusting timing. and can't make carousel keep cycling when put mouse inside carousel, tried using pause option not working also carousel containing image, want add <a href='#'> warp image when user click carousel image direct them link prepared... here my website in main.js file put space in between #main-slider , .carousel right looks this: //#main-slider $(function(){ $('#main-slider.carousel').carousel({ interval: 8000 }); }); and should this: //#main-slider $(function(){ $('#main-slider .carousel').carousel({ interval: 8000 }); }); if not going have in carousel , want <a> tag in there put in item , position absolutely overlays entire item. want set z-index -1 can still use carousel controls so: ht

excel - Extract Top 5 Values for Each Group in a List Based on Specific Criteria without VBA -

i have developed formula extract top value list. update formula ability filter list identify top value if column q contains "y". =index('inventory turnover'!$b:$b,match(1,index(('inventory turnover'!$k:$k=large('inventory turnover'!$k:$k,rows('inventory turnover'!c$1:c1)))*(countif('inventory turnover'!c$1:c1,'inventory turnover'!$b:$b)=0),),0)) thanks in advance time , consideration! please let me know if request unclear and/or if have specific questions. appreciate support! something can done pivot table few clicks. insert pivot table points data, drag label rows panel, drag value field values panel. filter pivot table show top ten or adjust show top x numbers. now use slicer or page filter filter pivot table on other field.

java - Exception in the action url of liferay porlet -

i have written portlet, before work excellent, begin throw exception 16:20:04,592 error [portletrequestdispatcherimpl:137] javax.servlet.servletexception: pwc1243: filter execution threw exception javax.servlet.servletexception: pwc1243: filter execution threw exception @ org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:280) @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:217) @ org.apache.catalina.core.applicationdispatcher.doinvoke(applicationdispatcher.java:785) @ org.apache.catalina.core.applicationdispatcher.invoke(applicationdispatcher.java:649) @ org.apache.catalina.core.applicationdispatcher.doinclude(applicationdispatcher.java:604) @ org.apache.catalina.core.applicationdispatcher.include(applicationdispatcher.java:534) @ com.liferay.portlet.portletrequestdispatcherimpl.dispatch(portletrequestdispatcherimpl.java:316) @ com.liferay.portlet.portletrequestdispat

C++: Suggestions about a hash function for a sequence of strings where the order of the strings is irrelevant -

let's have these 2 sequences of strings abc cba bc bc abc cba i'm trying create mapping such sequences(the sequence string) above 2 sequences mapped same bucket. my initial thought add results of hashing function applied each string separately. in way order won't matter. if applied hashing function sequence string whole, of course hash result different. however i'm new world of string hashing functions , have no idea whether approach efficient. in website http://www.partow.net/programming/hashfunctions/index.html i found many different implementations string hashing, i'm not sure 1 "best" needs. some technical details each string in sequence each of them won't have more 25 characters. each sequence won't have more 3 strings. questions 1. approach of adding results of string hashing function each string of sequence work? 2. if yes string hashing function should use give low amount of collisions , time efficient? thank

jQuery autocomplete gives TypeError: this._renderItem(...) is undefined -

i'm using .data( "ui-autocomplete" )._renderitem = function( ul, item ) in 3 places in page. need add 1 more , i'm done. but time error message typeerror: this._renderitem(...) undefined the strange thing if if test false. .data( "ui-autocomplete" )._renderitem = function( ul, item ) { // if 1 row returned , id = 0, return 'no result' message if(item.id == '0') { return jquery( "<li></li>" ) .data( "item.autocomplete", item ) .append( "<div class='no-result'>"+ item.value + "</div>" ) .appendto( ul ); } i can't figure out why it's failing here, , not in other 3 places. there conflict somewhere? this code jquery('#my-selector').autocomplete({ minlength: 2, source: function( request, response ) { jquery.ajax({ url: callback_url, datatype: "json", data: {

android - Show data in listview from airport -

i doing project want display list of airports in listview. airports names retrieved local database. data database in sqliteopenhelper class public list<airportlist> getallairportlists() { list<airportlist> airportlist = new arraylist<airportlist>(); string selectquery = "select * " + table_airport; log.i("query", selectquery); sqlitedatabase db = this.getwritabledatabase(); cursor cursor = db.rawquery(selectquery, null); if(cursor.movetofirst()) { do{ airportlist airport = new airportlist(); airport.setid(integer.parseint(cursor.getstring(0))); airport.setname(cursor.getstring(1)); }while(cursor.movetonext()); } return airportlist; } and iam new android can 1 please give idea call method in main class , show airport list in listview. first of in method above need add airport o

scala - Why would sbt reload gen-idea use 6GB of memory? -

i'm using command sbt reload gen-idea to build largish (hundreds of thousands of lines of code) intellij scala project. after 30 minutes+, program autokilled because runs out of memory. checked, , used 6gb before getting killed. what's going on? can improve this? sorry can't add more details: know nothing sbt. thanks actually using reload iwth sbt useless, cause reload command reloads build configuration in opened sbt session , when r launching sbt command line, automaticaly read last version of config files. time guess that's problem plugin. try add sbt_opts="-xx:+useconcmarksweepgc -xx:+cmsclassunloadingenabled -xx:permsize=256m -xx:maxpermsize=512m" /.sbtconfig file, limit amount of memory used sbt.

stl - deleting elements completely from multimap (C++) -

so have multimap, key struct, , values struct. multimap<struct, struct> multimap1; multimap1 contains (format key : value ) 1: random value 1 2: random value 2 3: random value 3 4: random value 4 i trying erase value , key multimap. let's want remove second entry of multimap. result should this: 1: random value 1 3: random value 3 4: random value 4 i have iterator points second value , when erase using multimap1.erase(it) , should remove second entry (at least think should). have been reading on removing entries , multimaps , seems value removed multimap, not key. if erase second entry iterator pointing second value , (correct me if wrong): 1: random value 1 2: 3: random value 3 4: random value 4 is there way middle value result? edit: apparently wrong. if erase, middle result. trying figure why not erasing correctly because, code segfaults when call erase. if call it->first , returns key of element want removed. if call it->second , returns val

python - Find the element "left" in a list -

i have list list1 = ["hello", "goodbye", "ohai"] . i have list, list2 = ["hello", "goodbye"] . i want remaining items in list1 , in case "ohai" . >>> list1 = ["hello", "goodbye", "ohai"] >>> list2 = ["hello", "goodbye"] >>> set(list1) ^ set(list2) set(['ohai']) if supposed use lists only, can iterate: >>> [item item in list1 if item not in list2] ['ohai'] but why when have sets ;-)

angularjs - ng-non-bindable only for the content of the element -

in our angular application, have link filled user content on server side. need tell angular not interpret link content. otherwise, if user, or attacker puts angular binding expressions in there (say {{user.password}}) angular evaluate it, opening security hole - kind of xss attack. ng-non-bindable that. however, want link manipulated angular. <a href="" class="side-bar-element" ng-class="{ 'side-bar-element-selected': issiteselected(@site.value.id) }">@site.value.name</a> @site.value.name server side code insert content. if put ng-non-bindable on element, ng-class won't work. solution can see insert span/div inside , apply ng-non-bindable that: <a href="" class="side-bar-element" ng-class="{ 'side-bar-element-selected': issiteselected(@site.value.id) }"><span ng-non-bindable>@site.value.name</span></a> this seems clunky, having modify html structure stop

Multiple source files in a C/C++ Application project ( NetBeans ) -

i created new c/c++ project via file > new project > c/c++ > c/c++ application . however, under source files folder, 1 source file main allowed. is there way include more 1 main source file in source files folder ? or have create new project each source file ? in contrast, each java project, there can many .java files in it. trying find same functionality c/c++ applications. thanks. for same project have many source files *.c , *.h , others but same project have 1 main() function in of source files example: code architecture: . └── source_folder ├── file1.c ├── file2.c └── main.c file1.c #include <stdio.h> void printfile1() { printf("this file1.c\n"); } file2.c #include <stdio.h> void printfile2() { printf("this file2.c\n"); } main.c #include <stdio.h> void printfile1(); //prototype definition void printfile2(); //prototype definition int main() { printfile1();

h2 - No response, while connecting to the database -

i using h2 java swing desktop application. i cannot able connect database, in server mode. url : jdbc:h2:tcp://115.241.34.158:9092/lion/companies/1(2012-2013)/1(2012-2013);db_close_on_exit=false;db_close_delay=5;ifexists=true the system, hangs, while giving java.sql.drivermanager.getconnection(url, username, password); not throwing exception (or) messages. it works fine, in single user mode. (without server) what possible solution ?. please advice. thanks , regards, i.murugesan if start tcp server without base directory, should use different database url. following database url jdbc:h2:tcp://115.241.34.158:9092/~/lion/companies means database file companies.h2.db stored in directory lion within current user home directory . if use jdbc:h2:tcp://115.241.34.158:9092/lion/companies/1(2012-2013)/1(2012-2013) then database file 1(2012-2013).h2.db stored in directory lion/companies/1(2012-2013) relative current working directory . , working directory

sublimetext2 - SublimeLinter fails with 'undefined' is not a function, emitter.on(name, listener); -

i've had sublimelinter working fine javascript files on macbook 10.6 while, see single error when save js files. e.g file has comment on first line: 'undefined' not function (evaluating 'function (name) { emitter.on(name, listener); }.bind(this)') 1:// i see same error regardless of have in js file or project file in. i've tried removing , re-installing sublimelinter, still same error. see here possible fix https://github.com/sublimelinter/sublimelinter/pull/507#issuecomment-21831056 for me worked: add global.window = {}; on top linter.js linter.js located @ .../sublime text 2/packages/sublimelinter/sublimelinter/modules/libs/jshint/linter.js