Skip to content

Instantly share code, notes, and snippets.

require 'rack'
class StackFrame
def initialize app
@app = app
end
def call env
p [:call, self.to_s, env]
_env = env.reduce(:merge)
$ env | grep LC
LC_ALL=en_US.UTF-8
LC_CTYPE=en_US.UTF-8
$ env | grep LANG
LANG=en_US.UTF-8
$ locale
locale: Cannot set LC_CTYPE to default locale: No such file or directory
locale: Cannot set LC_MESSAGES to default locale: No such file or directory
@benolee
benolee / curl.md
Last active August 29, 2015 14:06 — forked from btoone/curl.md

Introduction

An introduction to curl using GitHub's API

The Basics

Makes a basic GET request to the specifed URI

curl https://api.github.com/users/caspyin
# This computes the sum of the integers from a through b:
def sum_integers(a,b)
return 0 if a > b
a + sum_integers((a+1), b)
end
puts sum_integers(1,10)

RVM and Bash

Post-installation line

The rvm installation documentation instructs you to put the following line at the very end of your bash profile:

[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # This loads RVM into a shell session.

For those, like me, who are not very familiar with bash scripting, this is what the line above does: [[ condition ]] evaluates the condition inside the double brackets and returns true or false. The option -s file tells bash to look for file and decide whether it exists and is nonempty. So the line [[ -s "$HOME/.rvm/scripts/rvm" ]] looks inside the default rvm scripts folder ~/.rvm/scripts/ for rvm, and returns true or false.

require 'sinatra/base'
require 'erb'
class CIJoe
class Server < Sinatra::Base
[...]
def self.project_path=(project_path)
# next line does something screwy
user, pass = Config.cijoe(project_path).user.to_s, Config.cijoe(project_path).pass.to_s
if user != '' && pass != ''
Then /^the (\d+)(?:st|nd|rd|th) post title should be "([^"]*)"$/ do |pos, title|
with_scope(".blog_info_top:nth-of-type(#{pos.to_i})") do
if page.respond_to? :should
page.should have_content(title)
else
assert page.has_content?(title)
end
end
end
require 'spec_helper'
describe User do
let(:user) { User.new }
subject{ user }
[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm"
[[ -r "$rvm_path/scripts/completion" ]] && . "$rvm_path/scripts/completion"
[[ -r "$PWD/.rvmrc" ]] && . "$PWD/.rvmrc"
# I just ripped off the deep_merge core extension from activesupport.
# The file is 'activesupport-3.0.3/lib/active_support/core_ext/hash/deep_merge.rb'
class Hash
# Returns a new hash with +self+ and +other_hash+ merged recursively.
def deep_merge(other_hash)
dup.deep_merge!(other_hash)
end
# Returns a new hash with +self+ and +other_hash+ merged recursively.