Skip to content

Instantly share code, notes, and snippets.

@bootleq
bootleq / .zshrc
Created March 5, 2014 09:31
Currently in use messy zshrc
# References:
# GRML - https://github.com/grml/grml-etc-core
# zsh-users - https://github.com/zsh-users
[[ $ZDOTDIR == '' ]] && export ZDOTDIR=$HOME
if [[ $ZDOTDIR == '/etc/users/bootleq' && -f $ZDOTDIR/.vimrc ]]; then
alias vim="vim -u $ZDOTDIR/.vimrc"
fi
@bootleq
bootleq / .gitconfig
Created April 4, 2014 08:31
Currently in use messy ~/.gitconfig
[user]
name = bootleq
email = bootleq@gmail.com
[color]
ui = auto
; [help]
; format = web
module ActionController
class Metal
attr_internal :cached_content_for
end
module Caching
module Actions
def _save_fragment(name, options)
return unless caching_allowed?
@bootleq
bootleq / .zshrc
Created September 1, 2014 02:59
zsh function to restart Rails server (only support nginx server with passenger or unicorn_rails)
rtouch() {
emulate -L zsh
if [[ -d tmp ]]; then
if which passenger 2>&1 >/dev/null; then
touch tmp/restart.txt && echo 'file touched.'
elif which unicorn_rails 2>&1 >/dev/null; then
if [[ -r tmp/pids/unicorn.pid && -n $(ps h -p `cat tmp/pids/unicorn.pid` | tr -d ' ') ]]; then
kill -USR2 $(cat tmp/pids/unicorn.pid) && echo "process killed."
elif [[ -f config/unicorn.rb ]] && [[ -n $RAILS_ENV ]]; then
bundle exec unicorn_rails -D -E $RAILS_ENV -c config/unicorn.rb && echo "process started."
@bootleq
bootleq / quickrun-as-sql-client.vim
Created June 12, 2015 08:30
Use vim-quickrun as SQL client
" First, install thinca/vim-quickrun
"
" https://github.com/thinca/vim-quickrun
"
" Then write some vimrc:
"
@bootleq
bootleq / .zshrc
Last active August 29, 2015 14:27
Find ssh-agent and do ssh-add if needed
sshAgentFind() {
# Ref https://github.com/wwalker/ssh-find-agent
local -a sockets
if [[ -z "$SSH_AUTH_SOCK" ]] ; then
sockets=("${(@f)$(find /tmp/ -type s -path '/tmp/ssh-*/agent.*' -user $USER)}")
for socket in $sockets; do
SSH_AUTH_SOCK=$socket ssh-add -l 2> /dev/null > /dev/null
if [[ $? -eq 0 ]]; then
export SSH_AUTH_SOCK=$socket
@bootleq
bootleq / gist:541723
Created August 21, 2010 03:36
[.vimrc] toggle between CamelCased/under_scored word
" TODO when no keyword is under/after the cursor, try looking backward to find a word.
fun! WordTransform()
let w = expand("<cword>")
let x = ''
let c = strpart(getline('.'), col('.') - 1, 1)
if match(w, '_') > -1
let x = substitute(w, '_\([a-z]\)', '\u\1', 'g')
else
let x = substitute(w, '\C[A-Z]', '_\L\0', 'g')
endif
@bootleq
bootleq / bootleg.vim
Created August 22, 2010 11:00
Gist stopped. For new version, see https://github.com/bootleq/vim-color-bootleg
" Vim color file
" Maintainer: bootleq <bootleq@gmail.com>
" Last Change: 2010-09-17
" Version: 0.2
"
" Summary:
" Modified from "slate" theme in 256 color term.
" Dark background, high contrast, similar color in cterm/gui, and avoid bold attribute in gui.
"
" Test:
command! -bang -nargs=* JsCompress call JsCompress(<bang>0, <f-args>)
" @param boolean save 0: save to temp file and return compressed content.
" 1: save with alternative filename, return the new name.
" @param boolean interact 1 to prompt before starting compression.
" @param string options extra options for running the compiler.
fun! JsCompress(save, ...)
let jar = '/scripts/google-compiler-20100616.jar'
let defaults = ' --compilation_level=SIMPLE_OPTIMIZATIONS'
\ . ' --warning_level=QUIET'
let input = expand('%')
command! -nargs=* Bookmarklet call Bookmarklet(<f-args>)
fun! Bookmarklet(...)
let result = JsCompress(0, 0, '--compilation_level=WHITESPACE_ONLY')
if len(getqflist()) == 0 && strlen(result) > 0
let reuse_win = 0
for winnr in tabpagebuflist(tabpagenr())
if bufname(winnr) == '[Bookmarklet]'
exec winnr . 'wincmd w'
let reuse_win = winnr
endif