Skip to content

Instantly share code, notes, and snippets.

View xuncheng's full-sized avatar
🎯
Focusing

Xuncheng Wang xuncheng

🎯
Focusing
View GitHub Profile

tmux cheatsheet

As configured in my dotfiles.

start new:

tmux

start new with session name:

@xuncheng
xuncheng / polymorphic_factory.rb
Last active August 29, 2015 14:18
FactoryGirl with polymorphic associations
# a common polymorphic model
class Comment < ActiveRecord::Base
belongs_to :commentable, polymorphic: true
end
class Article < ActiveRecord::Base
has_many :comments, as: :commentable, dependent: :destroy
end
class Collection < ActiveRecord::Base
class ActionDispatch::Routing::Mapper
def draw(routes_name)
instance_eval(File.read(Rails.root.join("config/routes/#{routes_name}.rb")))
end
end
BCX::Application.routes.draw do
draw :api
draw :account
draw :session
# source: http://hashrocket.com/blog/posts/bridging-activerecord-and-mongoid
module Extensions::ActiveRecord::HasManyDocuments
extend ActiveSupport::Concern
module ClassMethods
def has_many_documents(association_name, options = {})
class_eval %<
def #{association_name}
#{association_name.to_s.singularize.classify}.where(#{name.underscore}_id: id)
end
@xuncheng
xuncheng / unsure.rb
Last active September 9, 2015 16:13 — forked from raggi/unsure.rb
$sure = false
t = Thread.new {
begin
# nada
ensure
sleep
$sure = true
# cleanup all the things
end
# => 2007-11-19T08:37:48-06:00 Safari下只能Parse这种格式的时间
Time.now.strftime("%FT%T%:z")
@xuncheng
xuncheng / gist:2354ea8656fac88d1f01
Last active September 10, 2015 07:58
generate a uuid in javascript
// JavaScript Version
uuid = function(e) {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
var r = Math.random() * 16 | 0, v = (c == 'x' ? r : (r & 0x3 | 0x8));
return v.toString(16);
});
}
module Foo
def bar
puts 'foobar'
end
end
class IncludeModule
include Foo
end
[General]
loglevel = notify
[Proxy]
Proxy = custom, 1.2.3.4, 443, rc4-md5, password, http://surge.run/SSEncrypt.module
[Rule]
DOMAIN-KEYWORD,google,Proxy,force-remote-dns
DOMAIN-KEYWORD,facebook,Proxy,force-remote-dns
DOMAIN-KEYWORD,youtube,Proxy,force-remote-dns

##Setup Textmate for Rails Dev on OS X

This guide was written by Jon Kinney for the Green Bay Ruby User Group. Jon works at Intridea and they graciously sponsor the Green Bay RUG meetings.

These guides were also partially completed using time from Intridea's SparkTime initiative which aims to give employees "outside projects" to work on during their normal work week.

If you find any issues with these suggestions please let me know. I've amassed these tips/tricks over several years of full time Rails development using Textmate but just because it works on my system doesn't always mean it will be problem free universally. Thanks to all the blog authors whose articles helped me learn Textmate over the years but whose links/posts I've lost or forgotten over time. If you have a cool Textmate tip or trick please post it in the comments!