Skip to content

Instantly share code, notes, and snippets.

@joannecheng
joannecheng / example.coffee
Last active September 27, 2015 23:47
why I use coffeescript.
# For one, it's just nicer to look at.
# No more excessive brackets and semi colons
## js
function foo(bar){
if (bar == 0){
return "zero!";
} else {
return "Not zero!";
}
# I have no idea what I'm doing.
require 'java'
Dir["sigar/*.jar"].each { |jar| require jar }
# import sigar class
# Must be java 1.7
import_sigar = org.hyperic.sigar
sigar = import_sigar.Sigar.new
shell = import_sigar.cmd.Shell.new
@joannecheng
joannecheng / mongo-ruby.rb
Created August 7, 2012 06:16
Search for nested objects using mongo-ruby
require 'rubygems'
require 'mongo'
@conn = Mongo::Connection.new
@db = @conn['trails']
@collection = @db['bikeways']
puts @collection.find('properties.FCODE' => 203001).to_a
# BOOM
@joannecheng
joannecheng / Ackermann.java
Created August 8, 2012 21:06
Some more Jruby notes: compiled java classes vs ruby classes
public class Ackermann {
public static int ack(int m, int n){
if (m == 0){
return n + 1;
}
if (n == 0){
return ack(m - 1, 1);
}
@joannecheng
joannecheng / build.rb
Created August 15, 2012 21:16
ant build scripts in jruby
# Make sure ant is installed and available on the machine
require 'ant'
ant :name => 'hello', :default => 'hello' do
target :name => 'hello' do
echo :message => 'Hello world!'
end
end
# $ jruby build.rb
# > hello:
@joannecheng
joannecheng / quiz-1.md
Created September 26, 2012 16:29 — forked from ahoward/quiz-1.md
quiz-1.md
So you think you wanna be a web developer...

Fork this, update your copy with answers.

They don't need to be precise - pseudo-code is fine in most cases.

Some questions don't have correct answers.

@joannecheng
joannecheng / jruby-sigar.rb
Created October 4, 2012 16:39
More jruby/sigar notes
require 'java'
Dir["vendor/sigar/*.jar"].each { |jar| require jar }
@joannecheng
joannecheng / install.sh
Last active October 11, 2015 09:47
things I need on linux environments
# General things
sudo apt-get update
sudo apt-get install build-essential zlib1g-dev curl wget git-core postgresql mongodb
# install rbenv and Ruby 1.9.3
git clone git://github.com/sstephenson/rbenv.git ~/.rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.profile
echo 'eval "$(rbenv init -)"' >> ~/.profile
source .profile
@joannecheng
joannecheng / bind_test.rb
Created November 2, 2012 14:58
Ruby Bindings
class SampleClass
def initialize
@str = "The Quick Brown Fox"
end
def get_binding
binding
end
end
require 'spec_helper'
describe User do
describe "#initialize"
context 'with all parameters' do
it "works" do
user = User.new :first_name => "slkdfjlaskdf"
user.first_name.should == ""
user.last_name.should == ""
end