Skip to content

Instantly share code, notes, and snippets.

View xuncheng's full-sized avatar
🎯
Focusing

Xuncheng Wang xuncheng

🎯
Focusing
View GitHub Profile
@xuncheng
xuncheng / key_navigation.js
Last active January 1, 2016 23:58
Keyboard Navigation between Input Fields using JQuery: up/down key
// Need dom_element_find.js
// https://gist.github.com/xuncheng/8219581
jQuery(document).ready(function(){
$('input[type=text]()').bind('keyup', function(evt) {
if (evt.keyCode == 40) {
// down key
var target = $('input[type=text]()').elementAfter(this)
if (target) {
target.focus();
}
@xuncheng
xuncheng / enter_navigation.js
Created January 2, 2014 14:07
Keyboard Navigation between Input Fields using JQuery: enter key
// Need dom_element_find.js
// https://gist.github.com/xuncheng/8219581
$("input[type=text]").bind("keydown", function(event) {
var target;
if (event.keyCode === 13) {
target = $("input[type=text]").elementAfter(this);
if (target) {
target.select().focus();
}
event.preventDefault(); // 禁用提交事件
@xuncheng
xuncheng / gravatar_for.rb
Created January 4, 2014 14:18
Generates the Gravatar for given user.
# Returns the Gravatar (http://gravatar.com) for the given user.
def gravatar_for(user, options = {size: 40})
gravatar_id = Digest::MD5::hexdigest(user.email.downcase)
size = options[:size]
gravatar_url = "https://secure.gravatar.com/avatar/#{gravatar_id}?s=#{size}"
image_tag(gravatar_url, alt: user.full_name)
end
@xuncheng
xuncheng / database_cleaner.rb
Last active January 3, 2016 07:28
Database Cleaner
# spec/support/database_cleaner.rb
RSpec.configure do |config|
config.before(:suite) do
DatabaseCleaner.clean_with(:truncation)
end
config.before(:each) do
DatabaseCleaner.strategy = :transaction
end
# you have ctags but it does not work...
$ ctags -R --exclude=.git --exclude=log *
ctags: illegal option -- R
usage: ctags [-BFadtuwvx] [-f tagsfile] file ...
#you need to get new ctags, i recommend homebrew but anything will work
$ brew install ctags
#alias ctags if you used homebrew
$ alias ctags="`brew --prefix`/bin/ctags"
# Make mouse useful in copy mode
setw -g mode-mouse on
# Allow mouse to select which pane to use
set -g mouse-select-pane on
# Allow mouse dragging to resize panes
set -g mouse-resize-pane on
# Allow mouse to select windows
# .powrc
if [ -f "$rvm_path/scripts/rvm" ] && [ -f ".ruby-version" ] && [ -f ".ruby-gemset" ]; then
source "$rvm_path/scripts/rvm"
rvm use `cat .ruby-version`@`cat .ruby-gemset`
fi
@xuncheng
xuncheng / pry_pow
Created March 23, 2014 16:15
Using Pry with Pow
# In your Gemfile
gem 'pry-remote', :group => :development
# Install with bundler
$ bundle
# In your ruby code
binding.remote_pry
# In your terminal
class BasePresenter
attr_reader :object, :template
def initialize(object, template)
@object = object
@template = template
end
def self.presents(name)
define_method(name) { object }