Skip to content

Instantly share code, notes, and snippets.

@eliangcs
eliangcs / vim_cheatsheet.md
Last active August 29, 2015 14:10
My Vim cheatsheet

Insert

  • a: after cursor
  • i: before cursor
  • A: after line
  • I: before line
  • o: add a new line below
  • O: add a new line above

Select

@eliangcs
eliangcs / ipython_startup.py
Created December 1, 2014 22:05
Common imports for IPython startup
# ~/.ipython/profile_default/startup/00_common.py
import base64
import codecs
import cPickle as pickle
import cStringIO as StringIO
import csv
import hashlib
import importlib
import json
import math
@eliangcs
eliangcs / arrow2.zsh-theme
Last active August 29, 2015 14:16
My oh-my-zsh theme
# Forked from https://github.com/robbyrussell/oh-my-zsh/blob/master/themes/arrow.zsh-theme
git_describe() {
echo $(git describe --tag 2> /dev/null)
}
my_git_prompt_info() {
prompt=$(git_prompt_info)
if [ ! -z "$prompt" ]; then
echo "$(git_describe) ($(git_prompt_info))"
@eliangcs
eliangcs / export_import_vertica.sql
Last active August 29, 2015 14:17
Export/import data from Vertica
-- Export
\a -- Disable alignment
\t -- Disable column header
\o output.txt -- Set output filename
SELECT * FROM table; -- Select the data to export
-- Import
COPY table FROM '/path/to/output.txt' DELIMITER '|';
@eliangcs
eliangcs / time_celery_task.py
Last active December 16, 2016 17:45
Log execution time for every Celery task, working on Celery 3.1.x.
import logging
import time
from celery import shared_task as orig_shared_task
def timeit(func):
"""A decorator used to log the function execution time."""
logger = logging.getLogger('tasks')
@eliangcs
eliangcs / vsql_commands.txt
Last active August 29, 2015 14:27
vsql info
See the Vertica Programmer's Guide for information on available commands.
General
\c[onnect] [DBNAME|- [USER]]
connect to new database (currently "localdev")
\cd [DIR] change the current working directory
\q quit vsql
\set [NAME [VALUE]]
set internal variable, or list all if no parameters
\timing toggle timing of commands (currently off)
@eliangcs
eliangcs / shortcuts.sh
Last active January 18, 2016 06:29
Shell shortcuts
# Clear local merged branches
function clearbranches(){
cur_branch=`git rev-parse --abbrev-ref HEAD`
if [[ "$cur_branch" == "master" ]]; then
git branch --merged | grep -v "\*" | xargs -n 1 git branch -d
else
echo "Not on master branch!"
fi
}
@eliangcs
eliangcs / tornado_subprocess.py
Last active January 7, 2020 08:48
A minimal web server that runs shell commands, powered by Tornado and its Subprocess module
"""
A minimal web server that runs shell commands, powered by Tornado and its
Subprocess module. It does non-blocking IO and streams the response.
To start the server:
$ python tornado_subprocess.py
To send a shell command using httpie:
<!DOCTYPE html>
<meta charset="utf-8">
<style>
.background {
fill: #e7e7e7;
}
.axis path,
.axis line {
@eliangcs
eliangcs / index.html
Last active January 18, 2016 06:44
Integrating sine with Monte Carlo / Metropolis algorithm
<!DOCTYPE html>
<meta charset="utf-8">
<style>
.svg {
border: 1px solid #000;
}
.result {
color: #05c;