Posts

javascript - How to use HTML5 history push state instead of window.location.hash? -

now using window.location.hash history management below, how can replace html5 history push state. var statehistory = []; function changehistory(page) { var l = statehistory.length, state = window.location.hash; if (l === 0) { statehistory.push(state); return; } if (state === statehistory[l - 2]) { statehistory.pop(); } else { statehistory.push(state); } }; you can use html5 history pustate function more info...... function changehistory(page) { window.history.pushstate({page:""+page},""+page); };

Wrongly implemented Fibonacci Sequence in Scala -

was @ scala meetup , discussing "scala way" of doing things... someone asked different developer how / implement fibonacci sequence in scala... person answered following code (only told while worked, non-optimal): def fibonacci(n: int):bigint = n match { case 0 => 0 case 1 => 1 case _ => fibonacci(n - 1) + fibonacci(n - 2) } what's wrong method? what ways improve code, scala way? the problem function, described non-tail recursive calls. means recursivity involved here needs stack work (in sample, it's call stack ). in other words, function equivalent of: import scala.collection.mutable.stack def fibonacci(n: int): bigint = { var result = bigint(0) val stack = stack.empty[int] stack.push(n) while (stack.nonempty) { val x = stack.pop() if (x == 1) { result += 1 } else if (x > 1) { stack.push(x - 2) stack.push(x - 1) } } result } as can see, that's not efficient, it...

ruby - Fill the array elements with nil -

i have array this: [[1,2],[2],[3,4,5,6],[7]] i want fill array elements nil . how result: [[1,2,nil,nil],[2,nil,nil,nil],[3,4,5,6],[7,nil,nil,nil]] i tried: arr=[[1,2],[2],[3,4,5,6],[7]] l=arr.max_by{|x|x.size}.size arr.map{|x|x+[nil]* (l-x.size)} is there easier way it? an orthodox way be: a = [[1,2], [2], [3, 4, 5, 6], [7]] max = a.map(&:length).max - 1 a.each{|a| a[max] ||= nil} # => [[1, 2, nil, nil], [2, nil, nil, nil], [3, 4, 5, 6], [7, nil, nil, nil]] a more interesting way be: a = [[1,2], [2], [3, 4, 5, 6], [7]] a.max_by(&:length).zip(*a).transpose.drop(1) # => [[1, 2, nil, nil], [2, nil, nil, nil], [3, 4, 5, 6], [7, nil, nil, nil]]

java - How to fetch SQLite data from selected Spinner item in Android -

i have retrieved first column data in spinner . want retrieve sqlite data when select spinner item. data displayed in edittext s. when run app, data cannot displayed in edittext . can give me suggestion?thanks in advance. here code spinner_searchbyempname = (spinner)findviewbyid(r.id.searchbyempname); loadserachbyproject() ; spinner_searchbyempname = (spinner)findviewbyid(r.id.searchbyempname); loadserachbyproject() ; spinner_searchbyempname.setonitemselectedlistener(new onitemselectedlistener() { @override public void onitemselected(adapterview<?> arg0, view arg1, int arg2, long arg3) { // todo auto-generated method stub selectedemployeename = spinner_searchbyempname.getselecteditem().tostring().trim(); system.out.println("selectedprojectname " + selectedemployeename); } @override public void onnothingsele...

mysql - How can I write a SELECT query with starting row of particular PK? -

i'm using mysql, support offset , limit, it's great. if want query first row equal particular primary key instead of page index? e.g. have table: id name height 1 kevin 1.67 2 bob 1.82 3 jane 1.70 4 wayne 1.59 i want list of people order height asc first page's last id 1, whole view 4 1 3 2 (page size = 2) something should like: select id,name,height table offset ???? limit 2 order height asc so should get: 3 jane 1.70 2 bob 1.82 try this logic : page_size page_number offset 2 1 (2*1)-1 = 1 2 2 (2*2)-1 = 3 2 3 (2*3)-1 = 5 query : select id,name,height table order height asc, id asc limit 2 offset (page_size * page_number)-1

Android: App shows xml file data in emulator but not in device -

i have app performs task xml file , file in /data/data/my.package/files/test.xml. data extracted xml file in emulator in real device there no data all. i thought there might me permission problem , have set permission these <uses-permission android:name="android.permission.internet" /> <uses-permission android:name="android.permission.write_external_storage" /> <uses-permission android:name="android.permission.read_external_storage" /> <uses-permission android:name="android.permission.access_network_state" /> but there no data display in real device. app running in emulator. any appreciable.

mysql - php5-msql installed on Ubuntu but not shown in phpinfo.php -

i setting nginx+php+mysql on ubuntu 12.04. i used apt-get install php5-mysql to install mysql module php. however, seems installed , enabled, yet shown in phpinfo.php , cant php application connect mysql server. php app accessible, , can view things on phpinfo.php. btw, mysql running normally, because running rails app using it, know working fine. as @vstm said quick summary others answer quicker: 1. kill php-cgi killall php-cgi 2. restart php-fpm /etc/init.d/php5-fpm restart or service php5-fpm restart 3. double check with grep -e 'extension=(pdo_)?mysql.so' -r /etc/php5