Skip to content

Instantly share code, notes, and snippets.

@cyeong
cyeong / postactivate
Created October 8, 2012 04:06
change cd behavior after activate
One handy hook I use is to overwrite some shell buildins. For example I have a custom cd, you can do so much with totally localized environments.
proj_name=$(echo $VIRTUAL_ENV|awk -F'/' '{print $NF}')
#this function will overwrite the default behavior of cd to go to the root of the venv, to go to HOME use cd ~
#change postdeactivate as well if you use this hook to revert cd back to ~
cd () {
if (( $# == 0 ))
then
builtin cd ~/projects/$proj_name
else
@cyeong
cyeong / postactivate
Created October 10, 2012 00:53
Lines to make pycscope environment aware (add this to your .virtualenv/postactivate file)
#add these lines to your .virtualenv/postactivate
#also add the cscope_maps.vim file at https://gist.github.com/3862602 to .vim/plugin/
#find $VIRTUAL_ENV/lib/python2.7/site-packages ${PWD} -name '*.py' > $VIRTUAL_ENV/cscope.files && cscope -R #-b -q -f $VIRTUAL_ENV/cscope.out -i $VIRTUAL_ENV/cscope.files
#(original cscope function)
nohup find ${PWD} -name '*.py' > $VIRTUAL_ENV/cscope.files && pycscope -f $VIRTUAL_ENV/cscope.out -i $VIRTUAL_ENV/cscope.files & disown
CSCOPE_DB=$VIRTUAL_ENV/cscope.out; export CSCOPE_DB
@cyeong
cyeong / postactivate
Created October 10, 2012 00:56
Ctags virtualenv
ctags -f $VIRTUAL_ENV/tags -R $VIRTUAL_ENV/lib/python2.7/site-packages ${PWD} &> /dev/null & disown
@cyeong
cyeong / cscope_maps.vim
Created October 10, 2012 01:28
enable cscope shortcuts and functions in vim
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" CSCOPE settings for vim
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"
" This file contains some boilerplate settings for vim's cscope interface,
" plus some keyboard mappings that I've found useful.
"
" USAGE:
" -- vim 6: Stick this file in your ~/.vim/plugin directory (or in a
" 'plugin' directory in some other directory that is in your
@cyeong
cyeong / nothing much really
Created October 10, 2012 10:49
headless arch
http://jeetworks.org/node/145
@cyeong
cyeong / config.py
Created October 12, 2012 10:15
Rope vim settings to enable auto completion for stuffs in virtal_env
_ _ _ ___ _ _ _ _
/_\ | |_ __ ___ __| |_ / _ \| |__ ___ ___| |___| |_ ___ _ _ ___| |_
/ _ \| | ' \/ _ (_-< _| (_) | '_ (_-</ _ \ / -_) _/ -_)_| ' \/ -_) _|
/_/ \_\_|_|_|_/__/|/|_.__/__//_|\___\___|\__|
In Glorious ASCII-VISION
Home
2011-04-17 Sun Using Rope or Ropemacs with Python Virtualenv
To make Rope use the libraries in your virtualenv: edit config.py in the .ropeproject directory (in the Rope project you want to set this up for) and add the following lines at the top of the "set_prefs" function:
@cyeong
cyeong / LOL
Created October 21, 2012 09:04
LOL trolling
CAPTAIN, I CAN SEE
THE rm -rf /usr LAND!
_____|\ .
_.--| LOL |: \O.===o
<____|.----|| ||`
.---''--;;
The ;..__..' _...
Lulz ,'/ ;|/..--'' \
Boat ,'_/.-/': :
_..-'''/ / | \ \ _|/|
@cyeong
cyeong / sort1mb.cpp
Created October 26, 2012 01:01 — forked from preshing/sort1mb.cpp
Sort one million 8-digit numbers in 1MB RAM
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
typedef unsigned int u32;
typedef unsigned long long u64;
//-------------------------------------------------------------------------
// WorkArea
//-------------------------------------------------------------------------
@cyeong
cyeong / forms.py
Created November 9, 2012 07:14 — forked from maraujop/forms.py
django-crispy-forms bootstrap form example
# -*- coding: utf-8 -*-
from django import forms
from crispy_forms.helper import FormHelper
from crispy_forms.layout import Layout, Div, Submit, HTML, Button, Row, Field
from crispy_forms.bootstrap import AppendedText, PrependedText, FormActions
class MessageForm(forms.Form):
text_input = forms.CharField()
@cyeong
cyeong / pre-commit
Created December 10, 2012 08:05 — forked from voldmar/pre-commit
git pre-commit hook that checks forgotten print’s and pyflakes errors
#!/bin/bash
cd ./$(git rev-parse --show-cdup)
result=$(mktemp /tmp/pre-commit.XXXXX)
STAGED=${STAGED:---staged}
changed_py=$(git diff --name-only --diff-filter=AM $STAGED | grep -E '\.py$')
changed_js=$(git diff --name-only --diff-filter=AM $STAGED | grep -E '\.js$')
[[ -z $changed ]] && exit 0