Skip to content

Instantly share code, notes, and snippets.

View SomethingClever.js
import React, { Component, PropTypes } from 'react'
import { connect } from 'react-redux'
/* ACTIONS */
export const ADD = 'something_clever/ADD'
export function add () {
return { type: ADD }
}
View gist:4232080
# config/boot.rb
if ENV["MANUAL_GC"].to_i == 1
GC.disable
Thread.new {
while true
sleep 2
GC.enable
GC.start
GC.disable
end
View index.html
<html>
<head>
<script src="jquery-1.8.3.js"></script>
<script src="jquery.tmpl.min.js"></script>
<script src="knockout-2.2.0.js"></script>
</head>
<body>
<input data-bind='value: users()[0].name' />
<h2>Good</h2>
View sequel-group.rb
require "sequel"
db = Sequel.sqlite
db.create_table :items do
primary_key :id
String :file
end
set = db[:items]
View _INTRO.sh
$ ruby -v
ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-linux]
$ rails -v
Rails 3.2.6
$ mkdir memory_leak
$ cd memory_leak
$ rails new .
$ rails g model Stub
$ bundle exec rake db:create db:migrate
$ rails runner ml.rb
View validatorx.rb
require "ostruct"
require "active_support/deprecation"
require "active_model/validator"
require "active_model/validations"
require "active_model/naming"
require "active_model/translation"
class Validatorz < OpenStruct
include ActiveModel::Validations
end
View terning2.rb
dices = [
[ 2,
3,1,6,5,
4
],
[ 3,
1,2,4,6,
5
],
[ 5,
View dumper.rb
class Dumper
attr_accessor :object, :tables
def initialize(object, tables=nil)
@object = object
@tables = tables || Hash.new {|hash,key| hash[key] = []}
end
def dump
puts "Dumping #{object.class.name}##{object.id}"
@vangberg
vangberg / speedy.rb
Created Feb 13, 2012
speedy rails console / rake / whatever.
View speedy.rb
# drop this in the top of yr config/boot.rb if you have plenty of RAM to spare.
if ENV["MANUAL_GC"].to_i == 1
GC.disable
Thread.new {
while true
sleep 2
GC.enable
GC.start
GC.disable
View fibur.markdown

Fibur

Fibur is a library that allows concurrency during Ruby I/O operations without needing to make use of callback systems. Traditionally in Ruby, to achieve concurrency during blocking I/O operations, programmers would make use of Fibers and callbacks. Fibur eliminates the need for wrapping your I/O calls with Fibers and a callback. It allows you to write your blocking I/O calls the way you normally would, and still have concurrent execution during those I/O calls.

Example

Say you have a method that fetches data from a network resource: