Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View chucai's full-sized avatar

He Xudong chucai

  • 北京
View GitHub Profile
@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 / Hacker_News_Ranking_Algorithm.sql
Created July 4, 2016 10:39 — forked from ChiChou/Hacker_News_Ranking_Algorithm.sql
Hacker News 排名算法的MYSQL函数实现
-- (p - 1) / (t + 2)^1.5
CREATE FUNCTION SP_POINTS(P SMALLINT(5), CREATED TIMESTAMP)
RETURNS TINYINT(3)
RETURN (P - 1) / POW(TIMESTAMPDIFF(HOUR, CREATED, NOW()) + 2, 1.5);
@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 / 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 / download.rb
Created November 25, 2015 09:29 — forked from jonforums/download.rb
Ruby HTTP/HTTPS/FTP file downloader
#!/usr/bin/env ruby
# An HTTP/HTTPS/FTP file downloader library/CLI based upon MiniPortile's
# HTTP implementation.
#
# Author: Jon Maken
# License: 3-clause BSD
# Revision: 2012-03-25 23:01:19 -0600
require 'net/http'
require 'net/https' if RUBY_VERSION < '1.9'
@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>
@chucai
chucai / rails_template.rb
Last active October 13, 2015 03:08 — forked from tonytonyjan/tj_rails_template.rb
Rails: template
# Usage:
# > rails new myapp -m https://gist.github.com/raw/4010690/d9106a1c3af695d1ed4ef8d16e3c8a06b5e3c7f3/tj_rails_template.rb
config = {}
puts "Gems:"
config[:install_devise_cancan_rolify] = yes? "install devise, cancan, rolify?"
config[:install_form_helpers] = yes? "install simple_form, dynamic_form, nested_form?"
config[:install_bootstrap_tjstyle] = yes? "install bootstrap, tjstyle?"
config[:install_rspec_spork] = yes? "install rspec, spork?"