This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# update application.rb | |
# config.middleware.insert_before(ActionDispatch::Static, TracePoint::Middleware) | |
class TracePoint | |
class Middleware | |
def initialize(app) | |
@app = app | |
end | |
def call(env) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- (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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
adapter: mysql2 | |
username: username | |
password: password | |
database: database_name |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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:" | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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". |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<ul data-role="listview" data-inset="true"> | |
<li data-role="list-divider">contact options</li> | |
<li> | |
<a href="#"> | |
test | |
</a> | |
</li> | |
</ul> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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?" |
NewerOlder