This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Translate integer into Excel column index, such as: | |
# 1-26 -> A-Z | |
#27-52 -> AA-AZ | |
#53-78 -> BA-BZ | |
#... | |
num.to.LETTERS<-function(num,letter=""){ | |
if(num<=0){ | |
return(NA) | |
}else if(num/26<=1){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Rscript filename.R --host= --dbname= --user= --password= | |
options<-paste0("--",c("host","dbname","user","password")) | |
args <- commandArgs(TRUE) | |
if(length(args)!=4)stop("Please input the full options of host, dbname, user and password.") | |
db.options<-function(option){ | |
option.location <- grepl(option,args) | |
if(sum(option.location)!=1) | |
stop(paste0("Something wrong with ", option, ".")) | |
if(!grepl("=",args[option.location])) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pkg.install <- function(x) | |
{ | |
if (!require(x,character.only = TRUE)) | |
{ | |
install.packages(x,dep=TRUE) | |
if(!require(x,character.only = TRUE)) stop("Package not found") | |
} | |
} | |
pkg.install("DBI") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
abb2state <- function(name, convert = F, strict = F){ | |
data(state) | |
# state data doesn't include DC | |
state = list() | |
state[['name']] = c(state.name,"District Of Columbia") | |
state[['abb']] = c(state.abb,"DC") | |
if(convert) state[c(1,2)] = state[c(2,1)] | |
single.a2s <- function(s){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def accepts(*types): | |
def check_accepts(f): | |
assert len(types) == f.func_code.co_argcount | |
def new_f(*args, **kwds): | |
for (a, t) in zip(args, types): | |
assert isinstance(a, t), "arg %r does not match %s" % (a, t) | |
return f(*args, **kwds) | |
new_f.func_name = f.func_name |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# unbind some default keybindings | |
unbind C-b | |
# set prefix key to ctrl-a | |
set -g prefix C-a | |
# pass through a ctrl-a if you press it twice | |
bind C-a send-prefix | |
# vim style bindings for pane movement | |
bind -r h select-pane -L | |
bind -r j select-pane -D |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
set noautofocus | |
set nocncpcompletion | |
set smoothscroll | |
set hud | |
set noregex | |
set noinsertmappings | |
set typelinkhints | |
set defaultnewtabpage | |
let scrollduration = 20 | |
let searchlimit = 30 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# -*-coding: utf-8 -*- | |
# This is a Flask app that accepts raw JSON from Slack with /json command and returns indented JSON | |
from flask import Flask, request, jsonify, abort | |
import json | |
import demjson | |
import requests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Convert long table like | |
# key long_column other_column_1 | |
# ------------------------------------ | |
# 0 Ann 1 A | |
# 1 Ann 3 A | |
# 2 Ann 5 A | |
# 3 John 3 B | |
# 4 John 5 B | |
# 5 George 1 A | |
# 6 George 3 A |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import dictmysql # or whatever db library | |
class LazyConnector: | |
def __init__(self, *args, **kwargs): | |
self.__dict__['__factory'] = dictmysql.DictMySQL | |
self.__dict__['__con'] = None | |
self.__dict__['__args'] = args | |
self.__dict__['__kwargs'] = kwargs | |
def _add_conn(self): |
OlderNewer