Skip to content

Instantly share code, notes, and snippets.

View FrankFang's full-sized avatar
🎯
Focusing

Frank Fang FrankFang

🎯
Focusing
View GitHub Profile
@FrankFang
FrankFang / index.md
Created January 4, 2017 07:54 — forked from rstacruz/index.md
Rails models cheatsheet

Rails Models

Generating models

$ rails g model User

Associations

belongs_to

has_one

@FrankFang
FrankFang / square.coffee
Created June 20, 2016 08:02
Named function in CoffeeScript
# Classes are the only place CoffeeScript generates named functions.
# This might seem messy, but the extra wrapping is necessary in order
# to have consistent behavior in IE. See the FAQ for more details:
# https://github.com/jashkenas/coffee-script/wiki/FAQ
class square
constructor: (x) -> return x * x # constructors require an explicit return
console.log square 5 # 25
console.log square.name # square
@FrankFang
FrankFang / index.html.erb
Created June 15, 2016 08:07 — forked from lingceng/index.html.erb
Custom ransacker predicates to query date range
<%= search_form_for @q, url: production_status_changes_path, class: 'form-inline' do |f| %>
<%= f.label 'Create At' %>
<%= f.search_field :created_at_beginning_of_day, class: 'form-control input-sm', 'datepicker' => true %>
<%= f.search_field :created_at_end_of_day_lt, class: 'form-control input-sm', 'datepicker' => true %>
<% end %>
@FrankFang
FrankFang / .gitignore
Last active September 20, 2015 05:13 — forked from bergie/.gitignore
Node.js email handling examples
config.json
reading-image.png
@FrankFang
FrankFang / etchosts.sh
Last active September 3, 2015 17:55 — forked from mikeflynn/etchosts.sh
An /etc/hosts manager bash script (v1.1) -- Added import and export commands!
#!/bin/bash
HOSTSFILE="/etc/hosts"
BAKFILE="$HOSTSFILE.bak"
DOMAINREGEX="^[a-zA-Z0-9]{1}[a-zA-Z0-9\.\-]+$"
IPREGEX="^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$"
URLREGEX="^https?:\/\/[a-zA-Z0-9]{1}[a-zA-Z0-9\/\.\-]+$"
backup()
{
@FrankFang
FrankFang / window.location.origin.js
Last active August 29, 2015 14:26
window.location.origin IE fix
if (!window.location.origin) { // Some browsers (mainly IE) does not have this property, so we need to build it manually...
window.location.origin = window.location.protocol + '//' + window.location.hostname + (window.location.port ? (':' + window.location.port) : '');
}

OS X Screencast to animated GIF

This gist shows how to create a GIF screencast using only free OS X tools: QuickTime, ffmpeg, and gifsicle.

Screencapture GIF

Instructions

To capture the video (filesize: 19MB), using the free "QuickTime Player" application:

@FrankFang
FrankFang / 0_reuse_code.js
Last active August 29, 2015 14:16
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
# 0 is too far from ` ;)
set -g base-index 1
# Automatically set window title
set-window-option -g automatic-rename on
set-option -g set-titles on
#set -g default-terminal screen-256color
set -g status-keys vi
set -g history-limit 10000
this.collection.comparator = 'id';
this.collection.sort();
this.collection.trigger('reset');