Skip to content

Instantly share code, notes, and snippets.

;;
;; NS CHEATSHEET
;;
;; * :require makes functions available with a namespace prefix.
;;
;; * :use makes functions available without a namespace prefix
;; (i.e., refers functions to the current namespace).
;;
;; * :import refers Java classes to the current namespace.
;;
@elarkin
elarkin / gist:4964461
Created February 15, 2013 23:27
ruby 1.9.* does not respect respond_to? :to_ary when calling flatten
def test_config klass
var = klass.new
unless !var.respond_to?(:to_ary) && [var].flatten == [var]
puts "#{klass.name} is misbehaved"
end
end
class RespondToMissingTest
def respond_to_missing? method, *rest
if method.to_sym == :to_ary
@elarkin
elarkin / proof.c
Last active December 13, 2015 18:29
If statements introduce scope.
#include <stdio.h>
int main()
{
int foo = 4;
if(1) {
int foo = 5;
printf("%i", foo);
}
printf("%i", foo);
}
@elarkin
elarkin / gist:4709748
Last active December 12, 2015 03:48
Handling Parsing errors using Rack middleware in Rails 3.2
#in application.rb
module YourApp
class Application < Rails::Application
config.middleware.insert_before ActionDispatch::ParamsParser, "ParsingFailureToJSON"
...
end
end
#The Parsing failure middleware
class ParsingFailureToJSON
@elarkin
elarkin / master.js
Created September 19, 2011 19:36
Child processes never exit
var child_process = require('child_process');
var child = child_process.fork('./slave.js');
child.on('exit', function() {console.log(1)})
@elarkin
elarkin / Gemfile
Created September 12, 2011 16:54
Bundler silently drops dependencies
source :rubygems
gem "chronic", "0.2.3"
gem "main", "4.7.1"
@elarkin
elarkin / deps
Created August 4, 2011 18:56
Splat gem dependancies
gem install --version '= 2.3.11' rails
gem install --version '= 1.0.4' uuid
gem install validatable
env ARCHFLAGS="-arch x86_64" gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
gem install --version '2.4.4' facets
gem install --version '4.0.0' htmlentities
gem install httpclient --version '= 2.1.2'
gem install --version '= 0.9.8' mocha
gem install --version '= 1.2.6' fakeweb
gem install --version '= 2.2.0' fattr
elarkin-vibes:splat evan.larkin$ gem install soap4r --version '= 1.5.8'
Abort trap
elarkin-vibes:splat evan.larkin$ rake gems:install --trace
(in /Users/evan.larkin/source/splat)
** Invoke gems:install (first_time)
** Invoke gems:base (first_time)
** Execute gems:base
** Invoke environment (first_time)
** Execute environment
=> QueryTrace disabled; CTRL-\ to toggle
@elarkin
elarkin / require.async.js
Created June 13, 2011 21:00
require.async
require.async = function require_async(module, continuation) {
//quick! pretend to be async!
continuation(require(module));
//alternately, actually be async:
//process.nextTick(function() {
// continuation(require(module));
//});
};
@elarkin
elarkin / ExampleRequire.js
Created December 31, 2010 05:03
An example of how module.declare and require would be defined on the client side
window.module = (function() {
var module = {};
var modules = {};
module.require = function require(mod_name) {
return modules[mod_name];
};
module.declare = function declare(f) {
if(typeof f === 'function') {
var m = {};