Skip to content

Instantly share code, notes, and snippets.

View caoer's full-sized avatar
🎯
Focusing as always

Zitao Xiong caoer

🎯
Focusing as always
View GitHub Profile
@caoer
caoer / 0_reuse_code.js
Last active August 29, 2015 14:14
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
for (int i = 0; i < 30; i++) {
__block __weak id ob1 = nil;
__block __weak id ob2 = nil;
void (^block)(NSNotification *) = ^(NSNotification *note) {
NSLog(@"got noti %@, ob1: %@, ob2: %@", note.name, ob1, ob2);
[[NSNotificationCenter defaultCenter] removeObserver:ob1];
[[NSNotificationCenter defaultCenter] removeObserver:ob2];
};
#ifdef DEBUG
//Lumberjack
DDTTYLogger *log = [DDTTYLogger sharedInstance];
// we also enable colors in Xcode debug console
// because this require some setup for Xcode, commented out here.
// https://github.com/CocoaLumberjack/CocoaLumberjack/wiki/XcodeColors
[log setColorsEnabled:YES]; */
[log setForegroundColor:[UIColor orangeColor] backgroundColor:nil forFlag:LOG_FLAG_INFO];
[log setForegroundColor:[UIColor redColor] backgroundColor:nil forFlag:LOG_FLAG_ERROR];
" copy all this into a vim buffer, save it, then...
" source the file by typing :so %
" Now the vim buffer acts like a specialized application for mastering vim
" There are two queues, Study and Known. Depending how confident you feel
" about the item you are currently learning, you can move it down several
" positions, all the way to the end of the Study queue, or to the Known
" queue.
" type ,, (that's comma comma)
import sublime, sublime_plugin, os
class ExpandSelectionToDelimsCommand(sublime_plugin.TextCommand):
def run(self, edit):
begindelims = ["\"", "\'", "(", "<", "[", "{"]
enddelims = ["\"", "\'", ")", ">", "]", "}"]
view = self.view
oldSelRegions = list(view.sel())
for thisregion in oldSelRegions:
thisRegionBegin = thisregion.begin() - 1
@caoer
caoer / deploy.rb
Created June 14, 2013 05:05 — forked from stas/deploy.rb
require 'mina/bundler'
require 'mina/rails'
require 'mina/git'
require 'mina/rbenv' # for rbenv support. (http://rbenv.org)
# require 'mina/rvm' # for rvm support. (http://rvm.io)
# Basic settings:
# domain - The hostname to SSH to.
# deploy_to - Path to deploy into.
# repository - Git repo to clone from. (needed by mina/git)
@caoer
caoer / gist:5178242
Created March 16, 2013 20:42
redis
#!/bin/bash
# from here: http://www.codingsteps.com/install-redis-2-6-on-amazon-ec2-linux-ami-or-centos/
# and here: https://raw.github.com/gist/257849/9f1e627e0b7dbe68882fa2b7bdb1b2b263522004/redis-server
###############################################
# To use:
# wget https://raw.github.com/gist/2776679/04ca3bbb9f085b192f6aca945120fe12d59f15f9/install-redis.sh
# chmod 777 install-redis.sh
# ./install-redis.sh
###############################################
echo "*****************************************"
#!/bin/bash
# from here: http://www.codingsteps.com/install-redis-2-6-on-amazon-ec2-linux-ami-or-centos/
# and here: https://raw.github.com/gist/257849/9f1e627e0b7dbe68882fa2b7bdb1b2b263522004/redis-server
###############################################
# To use:
# wget https://raw.github.com/gist/2776679/04ca3bbb9f085b192f6aca945120fe12d59f15f9/install-redis.sh
# chmod 777 install-redis.sh
# ./install-redis.sh
###############################################
echo "*****************************************"
@caoer
caoer / unicorn_init.sh
Created February 8, 2013 00:59
unicorn startup script
#!/bin/sh
set -e
# Example init script, this can be used with nginx, too,
# since nginx and unicorn accept the same signals
# Feel free to change any of the following variables for your app:
TIMEOUT=${TIMEOUT-60}
APP_ROOT=/u/apps/the_app/current
PID=$APP_ROOT/tmp/pids/unicorn.pid
CMD="/usr/bin/unicorn -D -c $APP_ROOT/config/unicorn.rb"
@caoer
caoer / unicorn.conf.rb
Created February 8, 2013 00:59
uncorn config file
# Sample verbose configuration file for Unicorn (not Rack)
#
# This configuration file documents many features of Unicorn
# that may not be needed for some applications. See
# http://unicorn.bogomips.org/examples/unicorn.conf.minimal.rb
# for a much simpler configuration file.
#
# See http://unicorn.bogomips.org/Unicorn/Configurator.html for complete
# documentation.