Posts

Featured post

java - Last square of 8x8 grid not drawn, using two nested FOR loops -

i'm having trouble understanding why code isn't working. should display checkerboard grid 8x8, but last square doesn't drawn ! idea why? i searched see if had been asked before, , didn't find anything. in advance! code: /* * file:checkerboard.java * ---------------------- */ import acm.graphics.*; import acm.program.*; public class checkerboard extends graphicsprogram { int row, column, x, y; public void run() { // checkerboard (row = 0; row < 8; row++) { (column = 0; column < 8; column++) { // x, y, x width, y width add(new grect(x, y, 50, 50)); x = column * 50; y = row * 50; } } } } btw: book i'm reading asks use 2 nested loops ( "the art , science of java" , chapter 4, exercise 11, cs-106a) you need set x , y before drawing rectangle. otherwise, last rectangle not going display: for (row = 0; row <

What design pattern is this code in Javascript? -

this question has answer here: why write “.call(this)” @ end of javascript anonymous function? [duplicate] 4 answers what kind of design pattern , significance of using closure? (function(){ // code here }).call(this); edit then difference between above code , following this keyword still refer same object in both ways. (function(){ // code here })(); thats invoked function expression. more info here: http://benalman.com/news/2010/11/immediately-invoked-function-expression/ the purpose run code while protecting scope (so variables declared within don't leak out global scope. update call sets value of this function being applied on. without it, value set window object, there set outer scope.

javascript - Unusual behaviour when drawing lots of images onto a large canvas -

in javascript code, download bunch of links of images, , draw them canvas in grid theme. number of links there are, , set width , height of canvas accordingly, there 200 images per row. height based on total number images. problem noticing based on height use, images show on canvas. example, if set height 12 rows, see images, if set on that, no images show up. when setting in 1 row, images show in firefox 23. ie9 , chrome29 shows nothing. does know if there wrong here, or stable way drawing lots of images large canvas? thanks. function onprofilesuccessmethod(sender, args) { alert("request arrived"); var listenumerator, piccount, item, picobj, path, office, ctx, x, y, imageobj; listenumerator = listitems.getenumerator(); piccount = listitems.get_count(); var w = 125; var h = 150; var rl = 200; var canvas = document.createelement('canvas'); canvas.id = "picgallery"; canvas.width = w * rl; canvas.

mysql - Rails refuses to insert one field into the database -

basically grab id of element table , insert another. vuln_id = activerecord::base.connection.execute("select blah ...") pid = vuln_id.first puts "==============================" puts pid # echos id puts "==============================" if pid.empty? puts "pid empty" end rd = report.new(:plugin_id => pid, :report_id => report_id) rd.save() in rails console, when report.dbaction(params) it runs model , here output (0.3ms) select statement..... ============================== 186 ============================== (3.0ms) begin sql (0.3ms) insert `report_data` (`created_at`, `report_id`, `updated_at`) values ('2013-07-10 22:03:59', 6, '2013-07-10 22:03:59') (33.9ms) commit it inserts report_id doesnt insert pid value database, though exists. why this? quick edit: plugin_id exists in table. triple checked. here rest of model file looks like class report < activerecord::base

javascript - Count length of each class -

i have below code in this fiddle . html <span class="myname">john smith</span> <span class="myname">john smith</span> <span class="myname">john smith</span> <span class="myname">john smith</span> <span class="myname">john smith</span> <span class="myname">john smith</span> javascript $('.myname').each(function(){ var text = $(this).html().split(' '), len = text.length, test = $(this).val().length, result = []; console.log('outside: ' + test); for( var = 0; < len; i++ ) { result[i] = '<span class="name-'+[i]+'" >' + text[i] + '</span>'; console.log('inside: ' + test); } $(this).html(result.join(' ')); console.log('after

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -

i have have cloudera cdh3u4 cluster setup. have secondarynamenode daemon running on 1 of nodes. i have ensure user has root access node on cluster (for example, datanode not have other daemons running) should not able start instance of secondarynamenode daemon on node (thereby having 2 secondarynamenodes on cluster) how can achieve this? thanks in advance. add property hdfs-site.xml namedfs.secondary.http.address valuesecondarynamenode-host address or ip:50090

gruntjs - Grunt usemin task to replace resources -

using gruntjs , possible replace resources in html file remote path (or perhaps anypath)? i'm particularly interested in doing usemin plugin. possible sample functionality: before <!-- build:js //cdnjs.cloudflare.com/ajax/libs/angular.js/1.1.3/angular.js --> <script src="/lib/angular.js"></script> <!-- endbuild --> after <script src="//cdnjs.cloudflare.com/ajax/libs/angular.js/1.1.3/angular.js"></script> this idea similar usemin plugin skips concatenation of enclosed resources new file of specified name. in other words, replaces enclosed html single resource of specified path. i wrote grunt-dom-munger because found usemin specific. can use grunt-dom-munger alter html see fit , read script tags , send concat/uglify/etc. grunt-dom-munger