Skip to content

Instantly share code, notes, and snippets.

View vangberg's full-sized avatar

Harry Vangberg vangberg

View GitHub Profile
import React, { Component, PropTypes } from 'react'
import { connect } from 'react-redux'
/* ACTIONS */
export const ADD = 'something_clever/ADD'
export function add () {
return { type: ADD }
}
# 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
<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>
require "sequel"
db = Sequel.sqlite
db.create_table :items do
primary_key :id
String :file
end
set = db[:items]
$ 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
@vangberg
vangberg / validatorx.rb
Created April 3, 2012 07:41
validatorx
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
dices = [
[ 2,
3,1,6,5,
4
],
[ 3,
1,2,4,6,
5
],
[ 5,
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 February 13, 2012 20:35
speedy rails console / rake / whatever.
# 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

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: