Skip to content

Instantly share code, notes, and snippets.

@danchoi
danchoi / .tmux.conf
Last active December 14, 2015 01:19
my current tmux
set -g prefix C-a
bind - split-window -v
bind-key C-a last-window
# Set status bar
set -g status-bg black
set -g status-fg white
set-window-option -g automatic-rename off
set-window-option -g mode-keys vi
require 'active_record'
class Grouping < ActiveRecord::Base
has_and_belongs_to_many :values
has_and_belongs_to_many :characteristics
end
class Characteristic < ActiveRecord::Base
has_and_belongs_to_many :groupings
has_many :values, :through => :groupings
@danchoi
danchoi / balanced.rb
Created March 18, 2013 20:28
balanced.rb
require 'httparty'
module Balanced
module_function
class HTTPError < StandardError
attr_reader :response
attr_reader :message
def initialize(response, message)
@response = response
@danchoi
danchoi / uri_patch.rb
Created March 29, 2013 15:36
uri encode by character boundaries
# encoding: utf-8
require 'uri'
module URI
class Parser
def escape2(str, unsafe = @regexp[:UNSAFE])
unless unsafe.kind_of?(Regexp)
# perhaps unsafe is String object
unsafe = Regexp.new("[#{Regexp.quote(unsafe)}]", false)
@danchoi
danchoi / .vimrc
Last active December 22, 2015 09:38
Custom Vim function to open hyperlinks
" Easily open hyperlinks in any Vim buffer:
" Place cursor before or at the beginning of a URL that
" begins with http: or https: and press <leader>o
let s:http_link_pattern = 'https\?:[^ >)\]]\+'
let g:browser_command = 'open '
func! s:find_href()
let res = search(s:http_link_pattern, 'cw')
if res != 0
let href = matchstr(expand("<cWORD>") , s:http_link_pattern)
@danchoi
danchoi / gist:6874170
Last active October 21, 2018 18:28
A simple git commit message prompt for Railsbridge Boston
Step 1:
In the Vagrant VM, we pre-configure git to use our own custom mini commit message editor:
git config --global core.editor rbcommit
Step 2:
We create this small Bash script called `rbcommit`, chmod +x it, and put it on the user's PATH.
@danchoi
danchoi / gist:6996870
Last active December 25, 2015 15:19
Lightweight Vim functions and keybindings for Rails project navigation
" Home-brewed Rails file-finder:
" Type :OP followed by a string fragment, and the app,test,spec,lib,config,db
" directories will be searched for files that match that string.
" Press TAB or shift-TAB to move through matches, and ENTER to open the file
" shown.
command -complete=custom,FasterOpenFunc -nargs=1 OP call s:faster_open(<f-args>)
func! FasterOpenFunc(A,L,P)
return system("find app test spec lib config db -name '*".a:A."*' 2>/dev/null | awk -F / '{print $NF \" -> \" $0}'")
endfun
@danchoi
danchoi / mso.hs
Created October 25, 2013 16:29
Draft HXT Haskell code to turn Microsoft exported HTML into nested HTML lists
{-# LANGUAGE Arrows, NoMonomorphismRestriction #-}
module Main where
import Text.XML.HXT.Core
import System.Environment
import Data.List
import Control.Arrow.ArrowNavigatableTree
import Text.XML.HXT.XPath.Arrows
import Data.Tree.NTree.TypeDefs
import Data.Tree.NavigatableTree.Class
@danchoi
danchoi / deploy.sh
Last active June 8, 2022 17:41
Simple Rails deploy bash script
#!/bin/bash
# deploy.sh
# Put this script on your production server and make it executable with chmod
# +x.
# Set the deploy_dir variable to the path on the production server to
# deployment directory. The script assumes the deployment directory is a git
# clone of the codebase from an upstream git repo. This script also assumes
@danchoi
danchoi / sparkline.sql
Created March 27, 2014 00:52
sparkline query
set @months := 1;
select
user_id,
group_concat(note_cnt_2 order by date) sparkline
from
(select user_id, date, coalesce(sum(note_cnt), 0) note_cnt_2 from
(select u.user_id, date_series.date, note_cnt from
(select id user_id from users) u cross join
(select selected_date date from (select adddate('1970-01-01',t4.i*10000 + t3.i*1000 + t2.i*100 + t1.i*10 + t0.i) selected_date from
(select 0 i union select 1 union select 2 union select 3 union select 4 union select 5 union select 6 union select 7 union select 8 union select 9) t0,