Skip to content

Instantly share code, notes, and snippets.

View he9lin's full-sized avatar

Lin He he9lin

View GitHub Profile
@he9lin
he9lin / fun_with_curry.md
Last active August 29, 2015 14:19
Fun with curry

spec

require 'spec_helper'

describe Pyramid::PathInterpolater do
  it 'replaces parts with corresponding value' do
    result = described_class.('entities/:entity_id', {entity_id: '1'})
    expect(result).to eq('entities/1')
@he9lin
he9lin / result.swift
Created December 15, 2014 21:56
Succinct Result enum for handling requests
enum Result<T> {
case Error(NSError)
case Value(T)
}
getUser(request) { result in
switch result {
case let .Error(error):
// display error message
@he9lin
he9lin / foreman-upstart.sh
Last active August 29, 2015 14:08
foreman upstart
sudo foreman export upstart /etc/init -a [app] -u [user]
@he9lin
he9lin / userful_feature_steps.rb
Created October 19, 2014 02:10
Some useful turnip steps
step "I should be subscribed to captain mode queue events" do
subscription = \
page.driver.evaluate_script("PrivatePub.subscriptionObjects['/captain']")
expect(subscription).not_to be_nil
end
step "I should be in the room" do
expect(page).to have_selector("#room-#{@room.id}")
expect(URI.parse(page.current_url).fragment).to eq("/rooms/#{@room.id}")
subscription = \
@he9lin
he9lin / interface_steps.rb
Created October 17, 2014 17:45
Interface steps
step "I visit the :page_path page" do |path|
path = send(path) unless path.is_a?(String)
visit path
end
step "I click :text" do |text|
click_on text
end
step "I click :text within the :page_element" do |text, element_css|
@he9lin
he9lin / layoutConstraint.swift
Last active August 29, 2015 14:07
Add layout constraint in swift
let leftConstraint = NSLayoutConstraint(item: self.containerView, attribute: NSLayoutAttribute.Leading, relatedBy: NSLayoutRelation.Equal, toItem: self.view, attribute: NSLayoutAttribute.Left, multiplier: 1.0, constant: 0)
self.view.addConstraint(leftConstraint)
let rightConstraint = NSLayoutConstraint(item: self.containerView, attribute: NSLayoutAttribute.Trailing, relatedBy: NSLayoutRelation.Equal, toItem: self.view, attribute: NSLayoutAttribute.Right, multiplier: 1.0, constant: 0)
self.view.addConstraint(rightConstraint)
@he9lin
he9lin / paginated.rb
Created September 4, 2014 06:44
Simple Paginate
#= Paginated
#
# Usage:
#
# customers = store.customers.extend Paginated
# customers.per_page(5) # defaults to 25
# customers.page(0) # returns an array
#
# count
# where.limit
@he9lin
he9lin / local_3000.conf
Created August 20, 2014 02:19
Local SSH setup on Ngnix
upstream local_3000 {
server 127.0.0.1:3000;
}
server {
server_name 3000.local;
listen 80;
listen 443 default ssl;
send_timeout 3600; # For debugging with breakpoints
@he9lin
he9lin / simple2.zsh-theme
Created August 12, 2014 19:35
Simple cyan zsh theme
PROMPT='%{$fg[cyan]%}%~%{$fg_bold[cyan]%}$(git_prompt_info)%{$reset_color%} '
ZSH_THEME_GIT_PROMPT_PREFIX="("
ZSH_THEME_GIT_PROMPT_SUFFIX=")"
ZSH_THEME_GIT_PROMPT_DIRTY=" ✗"
ZSH_THEME_GIT_PROMPT_CLEAN=" ✔"
@he9lin
he9lin / rbenv-zsh
Created August 10, 2014 18:11
Install rbenv on .zshrc
git clone https://github.com/sstephenson/rbenv.git ~/.rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.zshrc
echo 'eval "$(rbenv init -)"' >> ~/.zshrc
git clone https://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build
type rbenv