Skip to content

Instantly share code, notes, and snippets.

View eventualbuddha's full-sized avatar

Brian Donovan eventualbuddha

View GitHub Profile
>> ActiveSupport::JSON.decode(ActiveSupport::JSON.encode("<groups>"))
=> "\\u003Cgroups\\u003E"
>> JSON.parse(JSON.dump({:foo => '<groups>'}))
=> {"foo"=>"<groups>"}
Ruby C
crc = ceffffff crc = ceffffff
crc = 993ee24a crc = 993ee249
crc = 36bcd924 crc = 36bcd925
crc = 6d79b248 crc = 6d79b24a
crc = daf36490 crc = daf36494
crc = b127d498 crc = b127d49f
crc = 668eb488 crc = 668eb489
crc = cd1d6910 crc = cd1d6912
crc = 9efbcf98 crc = 9efbcf93
fish+rvm
========
Since rvm is a large collection of bash scripts and fish is not bash-compatible,
users of fish need a wrapper around rvm to make it work properly with that shell.
Since rvm just manipulates environment variables, we just need a way to preserve
those changes.
Install
-------
@eventualbuddha
eventualbuddha / debug_proxy.rb
Created March 23, 2010 22:08
Trace method calls on objects
# ruby -rdebug_proxy -e "DebugProxy.new('foo', :string).gsub!(/o/, 'a')"
#
# DebugProxy (string) -------------------------
# | |
# | Method called on proxy object: |
# | gsub!(/o/, "a") |
# | |
# | Stack trace of method call: |
# | -e:1 |
# | |
@eventualbuddha
eventualbuddha / command.rb
Created March 26, 2010 20:55
Execute shell commands and raise if it fails
class Command
attr_accessor :command, :stdout, :stderr, :process
class Error < RuntimeError
def initialize(command)
error = "command failed"
error << " ($?=#{command.process.exitstatus})" if command.process
error << ": #{command.command_string}"
error << "\n\nOUTPUT:\n\n#{command.stdout}" if command.stdout && !command.stdout.empty?
@eventualbuddha
eventualbuddha / coffee-script.thor
Created March 26, 2010 21:41
Tasks to install CoffeeScript (and Node.js) on Mac OS X using Homebrew
require 'fileutils'
module Helpers
def capture(*cmd)
Command.capture(*cmd)
end
def system_or_die(*cmd)
Command.system_or_raise(*cmd)
rescue => e
@eventualbuddha
eventualbuddha / fish_lexer.py
Created April 2, 2010 22:49
pygments lexer for fish scripts
import sys
from pygments import highlight
from pygments.lexer import RegexLexer, bygroups, include
from pygments.token import *
from pygments.formatters import *
class FishLexer(RegexLexer):
name = 'Fish'
aliases = 'fish'
filenames = ['*.fish']
function mcd --description 'make and cd to a directory'
mkdir -p $argv
cd $argv
end
donovan ~ $ rbx
>> require 'iconv'
FFI::NotFoundError: Unable to find 'iconv_open'
from FFI::Library(Class)#attach_function at kernel/platform/library.rb:98
from Iconv.__class_init__ (Iconv) at /usr/local/rubinius/1.0.1/lib/iconv.rb:11
from main.__script__ at /usr/local/rubinius/1.0.1/lib/iconv.rb:4
from Rubinius::CodeLoader.require at kernel/common/codeloader.rb:145
from Kernel(Object)#require at kernel/common/kernel.rb:693
from Object#irb_binding {} at (irb):1
[2010-07-07 07:30:41] tar zxf /home/vadmin/.rvm/archives/zlib-1.2.5.tar.gz -C /home/vadmin/.rvm/src
gzip: stdin: invalid compressed data--crc error
tar: Child returned status 1
tar: Exiting with failure status due to previous errors
[2010-07-07 07:31:09] tar zxf /home/vadmin/.rvm/archives/zlib-1.2.5.tar.gz -C /home/vadmin/.rvm/src
gzip: stdin: invalid compressed data--crc error
tar: Child returned status 1
tar: Exiting with failure status due to previous errors