Skip to content

Instantly share code, notes, and snippets.

View flyerhzm's full-sized avatar
🏠
Working from home

Richard Huang flyerhzm

🏠
Working from home
View GitHub Profile
Synvert::Rewriter.new "remote_rewriter", "Remote rewriter example" do
end
Synvert::Rewriter.new :use_taobao_gemsource do
within_file 'Gemfile' do
with_node type: 'send', message: 'source', arguments: {first: /rubygems.org/} do
replace_with 'source "http://ruby.taobao.org"'
end
end
end
R.input({
placeholder: 'City',
className: 'form-control',
type: 'text',
onChange: function(evt) {
this.setState({city: evt.target.value});
}.bind(this)
})
@flyerhzm
flyerhzm / gist:ca39e23100964623fc42
Last active August 29, 2015 14:07
remove trailing white spaces and use unix new line
Dir.glob("**/*.{rb,rake,erb}").each do |path|
content = File.read path
content.gsub! /\r\n?/, "\n"
content.gsub! /[ \t]+$/, ""
content.gsub! /^\t+/, " "
File.write path, content
end
@flyerhzm
flyerhzm / gist:0d836d8e60d5673872b7
Created October 21, 2014 08:31
nginx with unicorn conf
upstream codingstyleguide_upstream {
server unix:///home/deploy/sites/codingstyleguide/production/shared/tmp/sockets/puma.sock;
}
server {
listen 80;
server_name codingstyleguide-assets.xinminlabs.com;
access_log /var/log/nginx/codingstyleguide-asset.log;
error_log /var/log/nginx/codingstyleguide-error.log;
root /home/deploy/sites/codingstyleguide/production/current/public;
@flyerhzm
flyerhzm / exporter.rb
Last active August 29, 2015 14:14 — forked from jcasimir/exporter.rb
require 'csv'
module Exporter
DEFAULT_EXPORT_TABLES = [ Invoice, InvoiceItem, Item, Merchant, Transaction, User ]
DESTINATION_FOLDER = "tmp/"
def self.included(klass)
klass.extend ClassLevelMethods
end
@flyerhzm
flyerhzm / exporter.rb
Last active August 29, 2015 14:14 — forked from jcasimir/exporter.rb
require 'csv'
module Exporter
DEFAULT_EXPORT_TABLES = [ Invoice, InvoiceItem, Item, Merchant, Transaction, User ]
DESTINATION_FOLDER = "tmp/"
def self.included(klass)
klass.extend ClassLevelMethods
end
#!/usr/bin/env ruby
pid = `ps | grep script/serve[r] | awk '{ print $1 }'`.chomp
puts "Server PID: #{pid}"
url = ARGV.last
puts "URL: #{url}"
puts "Hit enter to go."
$stdin.gets
# To 2collegebums: This query generate a only one sql with left outer join,
# SELECT "comments"."id" AS t0_r0, "comments"."name" AS t0_r1, "comments"."post_id" AS t0_r2, "comments"."author_id" AS t0_r3, "base_users"."id" AS t1_r0, "base_users"."name" AS t1_r1, "base_users"."type" AS t1_r2, "posts"."id" AS t2_r0, "posts"."name" AS t2_r1, "posts"."category_id" AS t2_r2, "posts"."writer_id" AS t2_r3, "writers_posts"."id" AS t3_r0, "writers_posts"."name" AS t3_r1, "writers_posts"."type" AS t3_r2 FROM "comments" LEFT OUTER JOIN "base_users" ON "base_users".id = "comments".author_id LEFT OUTER JOIN "posts" ON "posts".id = "comments".post_id LEFT OUTER JOIN "base_users" writers_posts ON "writers_posts".id = "posts".writer_id AND ("writers_posts"."type" = 'Writer' ) WHERE (base_users.id = 1)
# so I think the test is not correct.
#
# this happens because it doesn't create an object association from post to writer
# by diving into the hash and creating those object associations
it "should detect preload of post => wr
>> variable = ['key', 'value']
>> key, value = *variable
>> key
=> "key"
>> value
=> "value"