Posts

javascript - JSON string created in Rails replaces whitespace with plus sign (+) -

javascript - JSON string created in Rails replaces whitespace with plus sign (+) - rails: object = object.find_by(params[:id]) object_items = { "1" => { :id => "123456", :name => "pancakes yum!" }, "2" => { :id => "789010", :name => "hello 123" }} cookies[:something] = { "id" => object.id, "title" => object.title, "object_items" => object_items }.to_json let's object.title produces string "hello world" cookie content: %7b%22id%22%3a2%2c%22title%22%3a%22hello+world%22%2c%22object_items%22%3a%7b%221%22%3a%7b%22id%22%3a%22123456%22%2c%22name%22%3a%22pancakes+yum!%22%7d%2c%222%22%3a%7b%22id%22%3a%22789010%22%2c%22name%22%3a%22hello+123%22%7d%7d%7d problem: the json string beingness created replaces/escapes whitespace plus sign ( + ) instead of %20 means if read string , grab value object.title in html/javascript read "hello+world...

groovy - Grails Join Table column name -

groovy - Grails Join Table column name - my alert has many location objects, , have bring together table alert_locations . the generated columns are: alerts_locations_id (i want alert_id ) location_id here's domain object: class alerts { static hasmany = [locations:locations,notifications:notifications] date alertdatetime string pest string crop static constraints = { alertdatetime (blank:false) pest (blank:false) crop (blank:false) } } static mapping = { locations jointable:[column:"location_id", key:"alert_id"] grails groovy gorm jointable

java - Creating 3x3 checkerboard over a picture using Graphics2D -

java - Creating 3x3 checkerboard over a picture using Graphics2D - i want create overlay of 3x3 checkerboard, non-solid squares should transparent. i don't want iterate pixels, rather draw squares using graphics2d create checkerboard. (do need loop, if statement, or both?) here's code far: picture mypict = new picture(mypathname); mypict.show(); graphics2d graphicsobj = mypict.getgraphics2d(); final int width = mypict.getwidth() / 3; final int height = mypict.getheight() / 3; (int = 0; > width; = width * 2) { rectangle2d.double shape1 = new rectangle2d.double(width, height, 0, 0); graphicsobj.draw(shape1); } i'd utilize combined (double) loop/if statement drawing solid parts of checkerboard. in pseudo-code might expressed as: draw image each row { each column { if 'odd' square number { graphics fill rectangle } } } java awt graphics2d

c# - query a list of dynamic objects for a FirstOrDefault -

c# - query a list of dynamic objects for a FirstOrDefault - the next code homecoming enumerable of dynamic objects. protected override dynamic get(int id) { func<dynamic, bool> check = x => x.id == id; homecoming enumerable.where<dynamic>(this.get(), check); } how select firstordefault single object not enumerable? similar this answer want singleordefault. simplest way probably protected override dynamic get(int id) { homecoming get().firstordefault(x=>x.id==id); } since people have had problem making work, test new .net 4.0 console project (if convert 3.5 need add together system.core , microsoft.csharp references) , paste program.cs. compiles , runs without problem on 3 machines i've tested on. using system; using system.collections.generic; using system.linq; using system.dynamic; namespace consoleapplication1 { internal class programme { protected dynamic get2(int id) { fun...

Why is fortran used for scientific computing? -

Why is fortran used for scientific computing? - i've read fortran still heavily used scientific computing. code heavily invested in fortran makes sense me. but there reason utilize fortran on other modern languages new project? there language design decisions in fortran makes much more suitable scientific computing compared more popular languages (c++, java, python, ruby, etc.)? example, there specific language features of fortran maybe allow numeric optimization in compilers much higher grade compared other languages mentioned? fortran is, improve or worse, major language out there designed scientific numerical computing. it's array handling nice, succinct array operations on both whole arrays , on slices, comparable matlab or numpy super fast. language designed create hard accidentally write slow code -- pointers restricted in such way it's obvious if there might aliasing, standard illustration -- , optimizer can go town on code. current incarnat...

terminal - How to set vim key mapping to normal? -

terminal - How to set vim key mapping to normal? - i know "normal" subjective term, know mean. i'm on mac. want "delete" backspace, hitting left @ origin of line jumps end of previous line, , other keys i'm used to. i'm typing right now. there simple way , still able utilize terminal non-gui version without having remap each key individually? please no "get used it" answers. need 1 class. don't want used it. :) terminal type (or whatever phone call it) xterm-256color/tcsh. you should take @ vim's easy mode - start vim -y flag(or run evim ) create behave regular text editor. when in easy mode, in insert mode. if ever need regular vim commands, utilize ctrl-l come in vim's normal mode, or ctrl-o come in single normal mode command , homecoming insert mode. more info in :help easy , :help evim-keys . vim terminal

django middleware - Python changing modifying via imported function -

django middleware - Python changing modifying via imported function - i trying create function, when imported , called, check , modify tuple. able phone call multiple times. however, have function homecoming new variable, because can not figure out way alter variable in place. here examples 2 files, how work: **modifier.py** import variable def function(new_string): if new_string not in variable.tuple: variable.tuple = new_string, + variable.tuple **variable.py** import modifier tuple = ('one','two',) modifier.function('add this') modifier.function('now this') #--> tuple should equal ('now this', 'add this', 'one', 'two',) however right have this: **modifier.py** def function(tuple_old, new_string): if new_string not in tuple_old: homecoming new_string, + tuple_old **variable.py** import modifier tuple = ('one','two',) tuple = modifier.function(tup...