Skip to content

Instantly share code, notes, and snippets.

// Exercise 2 - Closures
// Wrap the following code in a closure and export only the "countdown" function.
// Code
(function() {
var index;
function log(){
// Exercise 2 - Closures
// Wrap the following code in a closure and export only the "countdown" function.
// Code
(function(scope) {
var index;
function log(){
(function(scope) {
var index;
function log(){
console.log(index);
}
function iterate(){
log();
if(index>1) setTimeout(iterate, 1000);
// 1. Write a class to support the following code:
Person = function(name) {
this.name = name;
}
var thomas = new Person('Thomas');
var amy = new Person('Amy');
thomas.name // --> "Thomas"
// Part 1.
// Implement a function prototype extension that caches function results for
// the same input arguments of a function with one parameter.
//
// For example:
// Make sin(1) have the result of Math.sin(1), but use a cached value
// for future calls.
Function.prototype.cached = function() {
var fn = this,
<div id="the_div">
<ul id="the_list">
<li id="the_item">Click me!</li>
</ul>
</div>
<p id="log"></p>
<script type="text/javascript" charset="utf-8">
function log(string){
@alexgb
alexgb / activerecord-jdbc-adapter monkey patch
Created January 24, 2012 02:21
Monkey patch for activerecord-jdbc-adapter to allow querying Oracle views
require 'arjdbc/oracle/adapter'
module ArJdbc
module Oracle
# fix so that we can read column names for Oracle views
def ora_columns(table_name, name=nil)
jdbc_columns(table_name).map do |column|
column.extend(::ArJdbc::Oracle::Column)
@alexgb
alexgb / gist:3809794
Created October 1, 2012 06:21
jitsu deploy error
info: Welcome to Nodejitsu algae
info: jitsu v0.9.8
info: It worked if it ends with Nodejitsu ok
info: Executing command deploy
info: Analyzing application dependencies in app.js
info: Creating snapshot 0.1.0-8
error: Error running command deploy
error: Nodejitsu Error (500): Internal Server Error
error: npm http GET http://nj-npm.irisnpm.com/express/2.5.9
npm http GET http://nj-npm.irisnpm.com/jade/0.22.1
info: Welcome to Nodejitsu algae
info: jitsu v0.9.8
info: It worked if it ends with Nodejitsu ok
info: Executing command deploy
info: Analyzing application dependencies in app.js
info: Creating snapshot 0.1.0-8
info: Updating app web-desktop
info: Activating snapshot 0.1.0-8 for web-desktop
info: Starting app web-desktop
error: Error running command deploy
require 'rubygems'
require 'capybara-webkit'
counter = 0
app = proc do |env|
counter += 1
[200, { 'Content-Type' => 'text/html' }, [counter.to_s]]
end
session = Capybara::Session.new(:webkit, app)