Posts

Testing Rail's route's :constraints lambda with RSpec 2 -

question : how setup/mock rspec routing test more production rack environment? bonus points being able call controller's authentication function first (eg applicationcontroller.authenticate_user set session[:current_user_id] details : i using route :constraints have www.example.com/ route 2 different controllers & views depending on if user logged in or not. root :to => 'intentions#latest', :constraints => lambda {|r| r.env['rack.session'].has_key?(:current_user_id) } root :to => 'welcome#index' i wanted make sure bit of fragile routing has proper test around it. cukes testing wanted bit deeper of testing, messed :current_user_id , cukes did not catch that. example fat fingered :current_user_id in applicationcontroller's authenticate_user() method. love call in before(:each) , make sure setting correct session key. so created file called /spec/routing/auth_routing_spec.rb , tried follow guide @ http://relishapp.com/rspec/rs...

javascript - Replacing string in innerHTML -

so, simple thing i'm trying accomplish (javascript), it's taking me ages , still not work. i'm trying replace words (that within pre tag). example, word "static" should replaced "<span class="keyword">static</span>" . i'm using xhtml strict. my approach this: for (var j = 0; j < keywords.length; j++) { codeblock.innerhtml = codeblock.innerhtml.replace(new regexp(keywords[j], "g"), "<span class=\"keyword\">" + keywords[j] + "</span>"); } codeblock pre element, keywords array contains words replace. i've tried many ways, i'm stuck error messages these. firefox: [exception... "an invalid or illegal string specified" code: "12" nsresult: "0x8053000c (ns_error_dom_syntax_err)" location: "file:///c:/.../scripts.js line: 33"] chrome: error: invalid_state_err: dom exception 11 i'm g...

database - Django, is manual caching a bad idea? -

some of reports taking far long. i've implemented "cache" fields solve problem. example student's gpa involved calculation. i've add non normalized gpa field student. on each grade update, gpa recalculated , can assumed gpa field current. i know there number of caching mechanisms in django. correct wouldn't able this? you work around problem using django's cache framework, you'd go things differently. can cache want it, it's not designed save results on object. if want avoid calculating gpa , still able access off each model instance way going simple , best way it.

c# - search my list help with linq -

i have list<fruitobj> fruit fruitname, fruitcolor banana, yellow orange, orange cherry, red list<fruitobj> test = new list<fruitobj>(); is there inline way of searching list starts ban , return true if contain string? bool hasban = test.any( x => x.fruitname.startswith("ban")); note case sensitive, match "banana" do: bool hasban = test.any( x => x.fruitname.startswith("ban", stringcomparison.invariantcultureignorecase));

r - RODBC returning 0 values -

i accessing commercial db. via prompt: select personcode, persondate codb.mastertable personcode=42 personcode persondate ----------- ------------ 42 jan 3 2011 42 jan 3 2011 42 jan 3 2011 42 jan 3 2011 42 jan 3 2011 42 jan 3 2011 42 jan 3 2011 42 jan 3 2011 42 jan 3 2011 42 jan 3 2011 in r: library(rodbc) query <- "select personcode, persondate codb.mastertable personcode=42" connection1 <- odbcconnect("resdb", uid="userid", pwd="pwdaccess", believenrows=false) sqlquery(connection1,query) sqlquery(connection1,query) personcode persondate 1 42 01/03/2011 00:00:00.000 utc 2 42 01/03/2011 00:00:00.000 utc 3 42 01/03/2011 00:00:00.000 utc 4 42 01/03/2011 00:00:00.000 utc 5 42 01/03/2011 00:00:00.000 utc 6 0 01/03/2011 00:00:00.000 utc 7 0 01/03/2011 00:00:00.000...

android - I am trying to update a textview from a different activity and it keeps crashing -

on button click reading information file , need display in textview, code works while in activity layout if in different screen same code doesn't work. string sdcard = environment.getexternalstoragedirectory().getabsolutepath(); file file = new file(sdcard + "/mult/","boardname.cfg"); //read text file try { bufferedreader br = new bufferedreader(new filereader(file)); string line; while ((line = br.readline()) != null) { global.defaultboard = line; } textview defaultboard = (textview) findviewbyid(r.id.currentboard); defaultboard.settext(global.defaultboard); } catch (ioexception e) { //you'll need add proper error handling here } finish(); can see whats wrong? if remove lines aor comment lines of textview doesn't crash. thanks mrc ok my solution - value stored in global variable use onresume() refresh textview. public void onresume() { super.onresume(); textview defaultboard = (tex...

javascript - Cached content for image element kept in browser after being removed and added again -

we developing web app interface uses ajax/javascript entirely. there dynamic images cache expiration times of access + 15 minutes. so, when images accessed cached 15 minutes , after time browser fetch new version, caching again 15 minutes , on. the issue in ajax setup, when image elements removed , added, newly added image element (which on 15 minutes later, when browser fetch new image version) not contain new content. i.e. once image loaded in once, after element removed, if element re-added @ other stage without page being changed, loaded version display. so far issue chrome, i've not tested other browsers yet. image appears sort of held in "memory" when image element removed, image shows under "resources" in chrome developer tools - again, long after image element specifying image source has been removed. what can this? solution far change image filename on subsequent loads (the old query string trick perhaps). issue here these images stack in ...