Skip to content

Instantly share code, notes, and snippets.

View xuncheng's full-sized avatar
🎯
Focusing

Xuncheng Wang xuncheng

🎯
Focusing
View GitHub Profile
# .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
# 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
# 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"
@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
@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 / 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 / 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 / dom_element_find.js
Created January 2, 2014 14:02
Find the next or the previous instance for a given selected range
jQuery.fn.elementAfter = function(other) {
for(i = 0; i < this.length - 1; i++) {
if (this[i]() == other) {
return jQuery(this[i + 1]());
}
}
};
jQuery.fn.elementBefore = function(other) {
if (this.length > 0) {
@xuncheng
xuncheng / user_interact_with_queue_spec.rb
Created July 22, 2013 06:18
feature spec for user interacts with the queue
require 'spec_helper'
feature "User interact with the queue" do
scenario "User adds and reorders videos in the queue" do
comedies = Fabricate(:category)
monk = Fabricate(:video, title: "Monk", categories: [comedies])
south_park = Fabricate(:video, title: "South Park", categories: [comedies])
futurama = Fabricate(:video, title: "Futurama", categories: [comedies])
sign_in
@xuncheng
xuncheng / macros.rb
Created July 22, 2013 06:17
user sign in using macors
def sign_in(a_user=nil)
user = a_user || Fabricate(:user)
visit signin_path
fill_in "Email", with: user.email
fill_in "Password", with: user.password
click_button "Sign in"
end