Skip to content

Instantly share code, notes, and snippets.

@jots
jots / gist:669415
Created November 9, 2010 17:18
better way to return a hash?
getstyles ->
result = {}
for key in arguments
result[key] = this.getStyle(key)
return result
@jots
jots / gist:1040943
Created June 22, 2011 19:37
create directory structure
#!/usr/bin/env coffee
# looking to generate something like:
# {"root":[{"name":"a","branches":[{"name":"aa"},{"name":"bb"}]},{"name":"b"},{"name":"c"}]}
fs = require 'fs'
Path = require 'path'
dir_tree = (path,name=null) ->
if not name
@jots
jots / create directory structure in ruby
Created June 22, 2011 19:43
create directory structure
def dt(path,name=nil)
if not name
data = {}
data[:root] = children = []
else
data = {:name => name }
data[:branches] = children = []
end
dirs = []; files = []
@jots
jots / gist:1548743
Created January 2, 2012 00:12
em.watch
require 'rubygems'
require 'em-websocket'
require 'json'
require 'open4'
EventMachine.run {
EventMachine::WebSocket.start(:host => "0.0.0.0", :port => 4452) do |ws|
ws.onopen {
puts "WebSocket connection open"
@jots
jots / gist:6234022
Created August 14, 2013 18:30
try to create ubuntu 13.04 image from Dockerfile errors upgrading upstart
# Ubuntu Raring
# Version 0.1
FROM ubuntu:12.10
# https://github.com/dotcloud/docker/issues/1024
run dpkg-divert --local --rename --add /sbin/initctl
run cp /bin/true /sbin/initctl
# these resources helped...
# http://askubuntu.com/questions/250733/can-i-do-a-silent-or-unattended-release-upgrade
@jots
jots / gist:6234126
Created August 14, 2013 18:41
raring dockerfile?
from scratch
add http://cdimage.ubuntu.com/ubuntu-core/releases/13.04/release/ubuntu-core-13.04-core-amd64.tar.gz /
version raring
version 13.04
# lxc-start: No such file or directory - failed to mount 'proc' on '/usr/lib/x86_64-linux-gnu/lxc//proc'
# lxc-start: failed to setup the mount entries for 'ea0530624206181037ad33d02232a35eafe146b816df8dea446413795db2e842'
# lxc-start: failed to setup the container
# lxc-start: invalid sequence number 1. expected 2
# lxc-start: failed to spawn 'ea0530624206181037ad33d02232a35eafe146b816df8dea446413795db2e842'
wget -O chruby-0.3.4.tar.gz https://github.com/postmodern/chruby/archive/v0.3.4.tar.gz
tar -xzvf chruby-0.3.4.tar.gz
cd chruby-0.3.4
PREFIX=$HOME/chruby make install
echo 'source ~/chruby/share/chruby/chruby.sh' >> ~/.bash_login
git clone git://github.com/sstephenson/ruby-build.git ~/chruby-0.3.4/ruby-build
cd ~/chruby-0.3.4/ruby-build
PREFIX=$HOME/chruby ./install.sh
~/chruby/bin/ruby-build 2.0.0-p0 ~/.rubies/2.0.0-p0
echo 'chruby 2.0.0-p0' >> ~/.bash_login
@jots
jots / gist:7382177
Created November 9, 2013 05:44
icedcoffeescript question
# can await be made to not return from function until it is done?
fs = require("fs")
readfile = (fn) ->
await fs.readFile fn, "utf8", defer(err,res)
#console.log "res: ", res
return res
a = readfile("dbtest.coffee")
#iced = require('iced-coffee-script').iced
fs = require("fs")
class T
constructor: (cb) ->
console.log "asdf"
await fs.readFile __filename, "utf8", defer(err,res)
cb(err,res)
module.exports = T
@jots
jots / gist:8486945
Created January 18, 2014 06:22
ruby vs elixir
$ cat b.rb
array = (1..5_000_000).map { rand }
$ time ruby b.rb
real 0m0.911s
user 0m0.822s
sys 0m0.088s
$ cat b.ex
array = Enum.map (1..5_000_000), fn(_) -> :random.uniform end