Skip to content

Instantly share code, notes, and snippets.

View lxneng's full-sized avatar
🎯
Focusing

Eric Luo lxneng

🎯
Focusing
View GitHub Profile
@lxneng
lxneng / vim.rb
Created May 13, 2011 09:27 — forked from uasi/vim.rb
Vim formula for Homebrew
require 'formula'
class Vim < Formula
homepage 'http://www.vim.org/'
url 'ftp://ftp.vim.org/pub/vim/unix/vim-7.3.tar.bz2'
head 'https://vim.googlecode.com/hg/'
sha256 '5c5d5d6e07f1bbc49b6fe3906ff8a7e39b049928b68195b38e3e3d347100221d'
version '7.3.189'
def features; %w(tiny small normal big huge) end

on ubuntu

sudo apt-get install pandoc

on mac

install haskell-platform first

from sqlalchemy import not_
session.query(Region).filter(not_(Region.id.in_( (1,2,3) )))
alternately,
session.query(Region).filter(~ Region.id.in_( (1,2,3) ))
@lxneng
lxneng / Gemfile
Created April 23, 2011 00:05 — forked from rmoriz/Gemfile
UUID primary keys in Rails 3
# Gemfile
gem 'uuidtools'
Entry.where(:id => Entry.select('max(id) id').arel).to_sql
## {{{ http://code.activestate.com/recipes/577605/ (r1)
# -*- coding:utf-8 -*-
def Dict2Str(dictin):
# make dict to str, with the format key='value'
#tmpstr=''
tmplist=[]
for k,v in dictin.items():
tmp = str(k)+'='+'\''+str(v)+'\''
tmplist.append(' '+tmp+' ')
return ','.join(tmplist)
lang2Name = {'af': 'Afrikaans',
'am': 'Amharic',
'ar': 'Arabic',
'ast': 'Asturian',
'az': 'Azerbaijani',
'be': 'Belarusian',
'be@latin': 'Belarusian (Latin script)',
'bg': 'Bulgarian',
'bn': 'Bengali',
'bn_IN': 'Bengali (India)',
<script type="text/javascript">
function GetQueryString(name) {
var reg=new RegExp("(^|&)"+name+"=([^&]*)(&|$)");
var r=window.location.search.substr(1).match(reg);
if (r!=null)
return unescape(r[2]);
return null;
}
$(document).ready( function() {
"""RSA module
Module for calculating large primes, and RSA encryption, decryption,
signing and verification. Includes generating public and private keys.
http://hg.stuvel.eu/python-rsa/
"""
__author__ = "Sybren Stuvel, Marloes de Boer, Ivo Tamboer, and Barry Mead"
__date__ = "2010-02-08"
>>> from pyDes import *
>>> data = 'welcome to china'
>>> k = des('DESCRYPT', CBC, '\0\0\0\0\0\0\0\0', pad=None, padmode=PAD_PKCS5)
>>> d = k.encrypt(data)
>>> print "Encrypted: %r" % d
Encrypted: '\x7f\xd0\xdc\x1b\x86Y\xe7\xf2\xcb\xd5 tR\xa9G\x8a>-\x07\xec\xb3)\xce
\xa0'
>>> print "Decrypted: %r" % k.decrypt(d)
Decrypted: 'welcome to china'
>>> assert k.decrypt(d, padmode=PAD_PKCS5) == data