Skip to content

Instantly share code, notes, and snippets.

View hlxwell's full-sized avatar
⛷️
Focusing

Michael He hlxwell

⛷️
Focusing
View GitHub Profile
@zhengjia
zhengjia / capybara cheat sheet
Created June 7, 2010 01:35
capybara cheat sheet
=Navigating=
visit('/projects')
visit(post_comments_path(post))
=Clicking links and buttons=
click_link('id-of-link')
click_link('Link Text')
click_button('Save')
click('Link Text') # Click either a link or a button
click('Button Value')
@postmodern
postmodern / http_parser.rb
Created January 15, 2011 04:39
A pure Ruby HTTP parser using Parslet.
require 'parslet'
require 'pp'
class HTTPParser < Parslet::Parser
#
# Character Classes
#
rule(:digit) { match('[0-9]') }
rule(:digits) { digit.repeat(1) }
rule(:xdigit) { digit | match('[a-fA-F]') }
@JangoSteve
JangoSteve / ubuntu_rails_install.rb
Created January 22, 2011 17:58
Capistrano script to install Ruby, RVM, Rails in ubuntu (modified from deploy.rb scripts)
namespace :ubuntu do
desc "Setup Environment"
task :setup_env, :roles => :app do
update_apt_get
install_dev_tools
install_git
install_subversion
install_sqlite3
# Install and setup RVM instead of old Rails stack
#install_rails_stack
@whereisciao
whereisciao / mongoid.rb
Created February 10, 2011 15:34 — forked from outoftime/observing.rb
Mongoid Observer using ActiveModel.
require "#{RAILS_ROOT}/lib/mongoid/lib/observing.rb"
# Initializer for Observers
User.observers = :user_observer
User.instantiate_observers
# The preferred syntax, similar to AR's setup
# Mongoid.configure do |config|
# config.observers = :user_observer
@Evangenieur
Evangenieur / Readme.md
Created March 27, 2011 23:30 — forked from grosser/Readme.md
Ruby Server / Node.js Benchmark

Sinatra

ruby 1.9.2 + async_sinatra + thin thin start

ab -n 10000 -c 100 http://localhost:3000/
-> 49ms / request

Node

node server.js
@huacnlee
huacnlee / nginx.conf
Created September 14, 2011 13:50
Nginx http proxy cache to mirror of Rubygems.org
# 在本地服务器建立 rubygems.org 的镜像缓存,以提高 gem 的安装速度
# 此配置设置缓存过期为1天,也就是说,新上的 gem 无法马上安装
# 做这个起什么作用?
# rubygems 的很多资源文件是存放到 Amazon S3 上面的,由于 GFW 对某些 S3 服务器又连接重置或丢包,导致 gem 安装异常缓慢或有时候根本无法连接安装。
# 而通过这种跳板的方式可以很好的解决这个问题,当然前提是 Nginx反向代理 服务器需要在国外
proxy_cache_path /var/cache/rubygems levels=1:2 keys_zone=RUBYGEMS:10m
inactive=24h max_size=1g;
server {
listen 80;
@shapeshed
shapeshed / nginx_rails_3_1
Created October 10, 2011 19:13
Nginx Config for Rails 3.1 with Unicorn and Asset Pipeline
upstream app {
server unix:/srv/app/current/tmp/sockets/unicorn.sock fail_timeout=0;
}
server {
listen 80;
server_name www.app.com;
rewrite ^/(.*) http://app.com/$1 permanent;
}
server {
@hlxwell
hlxwell / mysql-to-mongo
Last active October 4, 2015 14:27 — forked from shenzhaoyan/gist:824583
MySQL to MongoDB
MySQL: SELECT * FROM user WHERE name = "foobar"Mongo: db.user.find({"name" : "foobar"})
MySQL: INSERT INOT user (`name`, `age`) values ("foobar",25)
Mongo: db.user.insert({"name" : "foobar", "age" : 25})
MySQL: DELETE * FROM user
Mongo: db.user.remove({})
MySQL: DELETE FROM user WHERE age < 30
Mongo: db.user.remove({"age" : {$lt : 30}}) $gt : > ; $gte : >= ; $lt : < ; $lte : <= ; $ne : !=
MySQL: UPDATE user SET `age` = 36 WHERE `name` = "foobar"
Mongo: db.user.update({"name" : "foobar"}, {$set : {"age" : 36}})
MySQL: UPDATE user SET `age` = `age` + 3 WHERE `name` = "foobar"
@stefanobernardi
stefanobernardi / application_controller.rb
Created September 23, 2012 07:07
Multiple omniauth providers and omniauth-identity on the main user model
class ApplicationController < ActionController::Base
protect_from_forgery
protected
def current_user
@current_user ||= User.find_by_id(session[:user_id])
end
def signed_in?
@shmatov
shmatov / deploy.rake
Created November 15, 2012 13:17
rails + mina + unicorn
# lib/tasks/deploy.rake
namespace :deploy do
desc 'Deploy to staging environment'
task :staging do
exec 'mina deploy -f config/deploy/staging.rb'
end
end