Skip to content

Instantly share code, notes, and snippets.

View chucai's full-sized avatar

He Xudong chucai

  • 北京
View GitHub Profile
@chucai
chucai / README.markdown
Created September 28, 2012 05:47 — forked from hooopo/README.markdown
Rails: nav_link helper for adding 'selected' class to navigation elements

#Behold, the nav_link:

The nav_link helper works just like the standard Rails link_to helper, but adds a 'selected' class to your link (or its wrapper) if certain criteria are met. By default, if the link's destination url is the same url as the url of the current page, a default class of 'selected' is added to the link.

For full usage details, see: http://viget.com/extend/rails-selected-nav-link-helper

Drop nav_link_helper.rb into app/helpers in your Rails 3.x app and enjoy.

@chucai
chucai / form.js
Created November 21, 2012 06:43
Javascript: Create a Form widget
//= require component/base
//= require component/placeholder
//= require component/form_helper
/**
* Form Component.
* @class
* @extends FW.Component
*/
FW.Form = Class.create(FW.Component,
@chucai
chucai / jquerymobile.html
Created November 21, 2012 13:49
JQueryMobile: base html template
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Title</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="jquery.mobile.css" />
<script type="text/javascript" src="jquery.js"></script>
<!--<script src="custom-scripts-here.js"></script>-->
<script type="text/javascript" src="jquery.mobile.js"></script>
@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?"
@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: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 / 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 / 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
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 / 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:"
)