Skip to content

Instantly share code, notes, and snippets.

@igrigorik
igrigorik / ruby-1.9-tips.rb
Created February 3, 2011 17:19
Ruby 1.9 features, tips & tricks you may not know about...
def tip(msg); puts; puts msg; puts "-"*100; end
#
# 30 Ruby 1.9 Tips, Tricks & Features:
# http://www.igvita.com/2011/02/03/new-ruby-19-features-tips-tricks/
#
tip "Upgrading to Ruby 1.9 is simple: rvm install 1.9.2 && rvm --default 1.9.2"
tip "Ruby 1.9 supports named captures in regular expressions!"
@nchong
nchong / gist:884888
Created March 24, 2011 11:01
Recursive coordinate bisection
(* Recursive coordinate bisection is a technique for partitioning a list of coordinates
* into roughly equal sized partitions of spatially close elements. The general principle
* is find the dimension that spans the greatest distance and find a pivot that will
* split the list into two roughly equal halves. Then recurse down.
*)
(* Sort a list of floating point values *)
let sort_float_list l =
List.sort (fun x y -> int_of_float (x -. y)) l
@eric1234
eric1234 / 0_instructions.txt
Created April 9, 2011 01:12
Using Sprockets 2 in Rails 3.0.x with CoffeeScript & SASS
UPDATE: Please see some of the forks for an updated version of this guide. I
myself have moved onto the Rails 3.1 betas to get the asset pipeline. But if
you want to stay on stable there are other folks who are keeping this guide
relevant despite the changes constantly occurring on Sprockets 2. The comments
on this gist will lead you to the right forks. :)
Some brief instructions on how to use Sprocket 2 in Rails to get CoffeeScript
powered JS and SASS powered CSS with YUI compression all via the magic of rack.
This stuff will be native in Rails 3.1 and the layout of the files on the
@carsonmcdonald
carsonmcdonald / gist:911761
Created April 9, 2011 20:48
node.js SPDY proxy
var tls = require('tls');
var fs = require('fs');
var Buffer = require('buffer').Buffer;
var zlib = require('zlib');
var BufferList = require('bufferlist');
var Binary = require('bufferlist/binary');
var Put = require('put');
var http = require('http');
var options =
@mrflip
mrflip / RUNME-demo_of_async_fibers.log
Created April 25, 2011 20:57
A fully-commented demo showing execution flow in the fibers+eventmachine => linear asynchronous code pattern
>> load './RUNME-demo_of_async_fibers.rb'
/Users/flip/ics/backend/son_of_a_batch/RUNME-demo_of_async_fibers.rb:4: warning: already initialized constant FIBER_IDXS
814e5e90 0 f_0 beg main top level
814e5e90 1 f_0 beg em setup this block sets up the eventmachine execution, but no execution-order shenanigans yet
814e5e90 2 f_0 beg fiber stp the end-the-reactor block won't be called for 1.5s, so we get here immediately.
814e5e90 3 f_0 end fiber stp nothing from inside the Fiber.new{} block has run yet.
814e5e90 4 f_0 end fiber stp kick off the fiber...
80d829a0 5 f_1 beg fiber when my_fiber.resume is called, this runs. Now in a new fiber
80d829a0 6 f_1 beg get_result get_result is called from within fiber_1
80d829a0 7 f_1 setup callback set up some code to run 1.5s from now
@mattetti
mattetti / buggy_ABPeoplePickerView_example.rb
Created April 28, 2011 00:58
MacRuby sample showing that ABPeoplePickerView is buggy and that it even affects AB.
raise "MacRuby only code, please install http://www.macruby.org/files/nightlies/macruby_nightly-latest.pkg" unless RUBY_ENGINE == 'macruby'
framework 'Cocoa'
framework 'AddressBook'
# AB wrapper code
class ABAddressBook
def <<(record)
if record.is_a?(ABRecord)
"puts adding #{record.name}"
#!/usr/bin/env ruby
#
# A quick script to dump an overview of all the open issues in all my github projects
#
require 'octokit'
require 'awesome_print'
require 'rainbow'

Currently the RubyGems index is stored as a Gzip file that is a marshalled array. Whenever Bundler needs to install a gem that is not yet installed it downloads the index, gunzips it and unmarshals it. It then looks for dependencies that are described in another file that is also a gzipped and marshalled file. There are several issues that arise from this setup:

  • The full index must be downloaded and parsed, but does not contain dependency data, which must then be downloaded and parsed. This is a relatively time consuming process.
  • The index must be centralized.

Additionally the gems themselves are currently centralized since there is nothing in the meta data that indicates where the gem should be downloaded from. However in order to allow this it is important to find ways of keeping the index from being poisoned (is this an issue in the centralized system?)

Dependency Resolution

# robgleeson's fork much improved
class ErrorDelegate
attr_reader :pointer
alias_method :to_pointer, :pointer
def initialize
@pointer = Pointer.new_with_type '@'
end
anonymous
anonymous / gist:1081455
Created July 13, 2011 22:12
diff --git a/src/org/jruby/management/Runtime.java b/src/org/jruby/management/Runtime.java
index e013b43..9014e3f 100644
--- a/src/org/jruby/management/Runtime.java
+++ b/src/org/jruby/management/Runtime.java
@@ -31,6 +31,7 @@ package org.jruby.management;
import java.lang.ref.SoftReference;
import org.jruby.Ruby;
+import org.jruby.runtime.builtin.IRubyObject;