Skip to content

Instantly share code, notes, and snippets.

@huydx
huydx / vim-setup
Last active October 12, 2015 09:38
personal vim setup
"------personalize
:set visualbell
:syntax on
:set number
filetype plugin on
set ofu=syntaxcomplete#Complete
:set gfn=Monaco:h14
:colorscheme desert
set mouse=a
set mouse=a
@huydx
huydx / alias remove
Created November 3, 2012 16:21
remove will ask whenever executed rm
% alias del rm -i
@huydx
huydx / gist:4007812
Created November 3, 2012 16:24
to remap ctrl-c ctrl-s in vim
##.bashrc
vim()
{
local STTYOPTS="$(stty --save)"
stty stop '' -ixoff
command vim "$@"
stty "$STTYOPTS"
}
##.vimrc
@huydx
huydx / pgessays.py
Created November 18, 2012 15:57 — forked from olasitarska/pgessays.py
Builds epub book out of Paul Graham's essays.
# -*- coding: utf-8 -*-
"""
Builds epub book out of Paul Graham's essays: http://paulgraham.com/articles.html
Author: Ola Sitarska <ola@sitarska.com>
This script requires python-epub-library: http://code.google.com/p/python-epub-builder/
"""
import re, ez_epub, urllib2, genshi
@huydx
huydx / vim prepend regex
Created November 28, 2012 17:22
prepend to top of each file with Regex VIM
:args **/*.ruby
:set hidden
:argdo norm! O# encoding: UTF-8
:wqa
@huydx
huydx / valid.js
Created November 29, 2012 17:54
javascript url validation regex
/^(https?|ftp):\/\/(((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?(((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?)(:\d*)?)(\/((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)?)?(\?((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|
@huydx
huydx / matrix.py
Created December 7, 2012 07:32
multidimensional matrix python
matrix = [[0 for col in range(size)] for row in range(size)]
@huydx
huydx / constructor.js
Created December 10, 2012 16:53
tweek object constructor js
function Library(a,b,c) {
if (window == this) {
return new Library(a, b, c);
}
}
@huydx
huydx / hiragana regex
Created January 6, 2013 14:13
hiragana regex
/^(?:\xE3\x81[\x81-\xBF]|\xE3\x82[\x80-\x93])+$/
@huydx
huydx / https.rb
Last active December 11, 2015 09:59
https get with parameters in Ruby
def get_currentuser_info cookies=nil
uri_domain = "https://www.googleapis.com"
uri_path = "/oauth2/v1/userinfo"
params = {alt: "json", access_token: cookies[:access_token]}
uri_string = uri_domain + uri_path + "?" +
params.map{|k,v| "#{k}=#{CGI::escape(v.to_s)}"}.join('&')
uri = URI(uri_string)
response_hash = nil
Net::HTTP.start(uri.host,
uri.port,