Skip to content

Instantly share code, notes, and snippets.

View hlee's full-sized avatar

Ken Lu hlee

View GitHub Profile
@iannono
iannono / notes_of_rails4_patterns.md
Last active December 21, 2015 12:19
notes of rails 4 patterns

models

  • controllers should be responsible for orchestrating the models. means that you should always tell objects what to do, and not ask them question about there state
# controller
if @item.publish
  flash[:notice] = "xxxx"
end
# modle
class Item < ActiveRecord::Base
@SaitoWu
SaitoWu / graph.rb
Last active December 25, 2017 07:30
Github Contribution Graph
require 'date'
author = "Saito"
email = "saitowu@gmail.com"
date = Date.new(2012, 7, 30)
s = %w{
. . . . . . .
. . o o o . .
. o . . . . .
@songjiayang
songjiayang / gist:5567955
Last active December 17, 2015 06:48
cap deploy.rb
namespace :deploy do
desc "重启服务器"
task :restart, :roles => :app do
run "touch #{current_path}/tmp/restart.txt"
end
desc "在本地生成配置文件"
task :setup_local_configs do
@hlee
hlee / git_report
Created April 19, 2013 23:18
git report
#! /usr/bin/perl -w
use strict;
my $since;
if ($ARGV[0]) {
$since = $ARGV[0];
} else {
$since = "1 week ago";
}
@nightire
nightire / Changes in Rails 4_1.md
Last active May 11, 2022 04:50
拥抱 Rails 4 —— 详述 Rails 4 的新变化

Routes

小心地使用 Match(Rails 3 已实现)

Rails 3 提供了 match 方法供我们自定义 routes,然而我们要小心使用它以避免“跨站脚本攻击”(XSS Attack)。比如像这样的 routes:

注:(r3 代表 Rails 3,r4 代表 Rails 4)

# routes.rb
@afeld
afeld / gist:4952991
Last active February 8, 2022 03:13
good APIs for mashups

This list has been superseded by Public APIs. Check there for APIs with Auth: No, HTTPS and CORS Yes.


List of data APIs that require no server-side auth or private credentials, and are thus good for small browser-only JS projects.

@happypeter
happypeter / Traps.markdown
Created September 12, 2012 07:33 — forked from billie66/nginx.conf
Deploy Rails on Ubuntu server 12.04 with Nginx, Unicorn, Mysql
  1. the default index.html does not work well in prodution mode, so do not borther to config that, just delete it and go on.

  2. To put things in production mode, do

     rails g scaffold items name:string
     rake db:migrate RAILS_ENV=production
     rm public/index.html
     #change route.rb point root to items#index
     rake assets:precompile
     sudo service nginx restart
    

./config/unicorn_init.sh stop

@hooopo
hooopo / README.markdown
Created August 8, 2012 14:12 — forked from greypants/README.markdown
RAILS 3: 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.

@MohamedAlaa
MohamedAlaa / tmux-cheatsheet.markdown
Last active May 23, 2024 18:01
tmux shortcuts & cheatsheet

tmux shortcuts & cheatsheet

start new:

tmux

start new with session name:

tmux new -s myname