Skip to content

Instantly share code, notes, and snippets.

View chucai's full-sized avatar

He Xudong chucai

  • 北京
View GitHub Profile
@chucai
chucai / where_is.rb
Last active August 29, 2015 14:01 — forked from wtaysom/where_is.rb
module Where
class <<self
attr_accessor :editor
def is_proc(proc)
source_location(proc)
end
def is_method(klass, method_name)
source_location(klass.method(method_name))
@chucai
chucai / ruby.snippets
Created March 29, 2014 17:26
Snippet:Ruby Snippets with added rspec snippets
# #!/usr/bin/env ruby
snippet #!
#!/usr/bin/env ruby
# New Block
snippet =b
=begin rdoc
${1}
=end
snippet y
@chucai
chucai / B2Sprite.cpp
Last active August 29, 2015 13:56
COCOS2DX:B2Sprite extension Sprite
/* Copyright (c) 2012 Scott Lembcke and Howling Moon Software
* Copyright (c) 2012 cocos2d-x.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
@chucai
chucai / database.yml
Last active January 3, 2016 05:29
Rails: mysql active record
adapter: mysql2
username: username
password: password
database: database_name
@chucai
chucai / main.rb
Last active January 1, 2016 23:19 — forked from unnitallman/gist:944011
Rails: Single ActiveRecord File For Sqlite3
require 'active_record'
ActiveRecord::Base.logger = Logger.new(STDERR)
ActiveRecord::Base.colorize_logging = false # 注释掉,如果用 rails 4.0
ActiveRecord::Base.establish_connection(
:adapter => "sqlite3",
:dbfile => ":memory:"
)
class SimpleLinearRegression
def initialize(xs, ys)
@xs, @ys = xs, ys
if @xs.length != @ys.length
raise "Unbalanced data. xs need to be same length as ys"
end
end
def y_intercept
mean(@ys) - (slope * mean(@xs))
@chucai
chucai / dynamic_method_spec.rb
Created December 20, 2013 03:19 — forked from skwp/dynamic_method_spec.rb
Rspec: dynamic method spec test
require 'spec/support/grep_matcher'
describe do
disallow_presence_of pattern: "send(.*#",
location: "app/",
description: "Do not use dynamic method invocations",
failure: "Please change dynamic method call to something more sane."
end
@chucai
chucai / tracepoint_middleware.rb
Last active October 10, 2019 06:32 — forked from mattetti/tracepoint_middlware.rb
Rails: TracePoint rails request
# update application.rb
# config.middleware.insert_before(ActionDispatch::Static, TracePoint::Middleware)
class TracePoint
class Middleware
def initialize(app)
@app = app
end
def call(env)
@chucai
chucai / Rails:sqlite_database.yml
Created December 10, 2013 02:45
Rails:sqlite_database.yml, generate a common database.yml file for baseon sqlite rails application
# SQLite version 3.x
# gem install sqlite3
development:
adapter: sqlite3
database: db/development.sqlite3
pool: 5
timeout: 5000
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
@chucai
chucai / list-view-inset
Created November 25, 2012 13:07
JQueryMobile: list-view-inset
<ul data-role="listview" data-inset="true">
<li data-role="list-divider">contact options</li>
<li>
<a href="#">
test
</a>
</li>
</ul>