have you been reading through my programming riddles?
have they been too easy for you?
try the python challenge. let me know how far you made it
have you been reading through my programming riddles?
have they been too easy for you?
try the python challenge. let me know how far you made it
this python snippet was a fun read:
http://code.activestate.com/recipes/576564-walkers-alias-method-for-random-objects-with-diffe/
(also here in ruby)
and now, while on break from our ongoing tutorial (table of contents).
are you tired of starting django and twisted via two separate processes, possibly having them run in two different shells for debugging purposes? i know i am.
fortunately, django and twisted can inter-operate – Django supports the Python wsgi interface, and twisted can be used to serve wsgi applications. this is actually the ideal method for having the two interact with each other (and is the first post in this tutorial that runs 100% counter to my disclaimer)
detailed documentation for this process is available at the twisted documentation site http://twistedmatrix.com/documents/current/web/howto/web-in-60/wsgi.html
give a shot to modifying your current tutorial code to make this work.
there are two components required to properly serve the django portions of this tutorial as wsgi resources:
this is slightly more complicated than it sounds, since, in newer versions, django dynamically searches through an ordered list of directories when serving its static components. using twisted to mimic that same functionality can take some work. i opted to use a custom directory scanning twisted resource
there aren’t very many decisions to make here; most of the work has to do with reading the documentation, and figuring out how to access the specific, relevant interfaces. if you’re stuck, you can find a clear example here; this basic resource might help, too.
tried it? given up? since i’ll be relying on this work when expanding the tutorial, it might be worth your time to see how i did it (and see if it makes sense to you). take a look at this commit/diff to get a list of the specific changes i made – let me know if it makes sense (or if i made a mistake/have a typo)
the git repository for the ongoing chat tutorial has this completed step tagged as v.0.2.1 – if you’ve already cloned the git repo, you can check out a clean version like so:
git checkout v0.2.1
given the following function:
function addInts(anArray){ var result = 0; for (var i = 0; i < anArray.length; ++i){ if (anArray[i] < 21) { result = result + anArray[i]; } else { result = result + anArray[i] - 21; } } return result; }
what would you expect will run faster?
addInts(sortedArray); #sorted addInts(unsortedArray); #unsorted
[More programming riddles]
what’s the shortest anagram detector you know how to write, in javascript?
there must be a shorter way to do this. highlight below to see a solution.
var anagramDetector = function (x,y) {
if (x.length != y.length) return false;
var alpha_x = x.split("").sort().join("");
var alpha_y = y.split("").sort().join("");
for ( j = 0; j<y.length;++j) {
if (alpha_x[j] != alpha_y[j]) return false;
}
return true;
}
PS: there’s a cool method for solving this for a fixed alphabet, using primes
[More programming riddles]
what’s the shortest anagram detector you know how to write, in python?
this is one that keeps feeling like it should be a one liner (because it’s very similar to this one liner), but i suspect can’t be done in one line
highlight to see a solution.
def fn(x,y):
if len(x) != len(y):
return False
for i in x:
y = y.replace(i,'',1)
return not len(y) > 0
PS: there’s a cool method for solving this for a fixed alphabet, using primes
[More programming riddles]
if you had to guess, which of the following two bits of javascript code would you say executes faster?
Exhibit A:
var keys = Object.keys(MyObj); //cloning the key array var length = keys.length; for (var i = 0; i < length; i++) { var val = MyObj[keys[i]]; };
Exhibit B:
for (var key in MyObj) { if (MyObj.hasOwnProperty(key)) { //hasOwnProperty is a native function var val = MyObj[key]; } }
[More programming riddles]
this is what things looked like last year in september, with an up to date version of chrome:
how well do you know your arrays?
figure out what you think each line does, and then check yourself by running them in a console
test = [1,2,3] test test.length test.length = 5 test.length test
[More programming riddles]
javascript riddle
does null == false?
if (null) { console.log("null"); } if (null == false) { console.log("null == false"); } if (!null) { console.log("!null"); }
[More programming riddles]
downwards growing, web-readable, activity logs, coupled with infinite scrolling. really cloudera? wtf:
this one should probably be listed as a ux anti-pattern. by default:
forcing users to scroll to the bottom of an infinite-downwards-scrolling page to see the most recent log entries makes the most common uses for an activity log, the most difficult ones to use