Skip to content

Instantly share code, notes, and snippets.

@sp3c73r2038
sp3c73r2038 / apt-cyg
Created December 23, 2013 08:54
patched apt-cyg for architect change of cygwin.
#!/bin/bash
# apt-cyg: install tool for cygwin similar to debian apt-get
#
# Copyright (C) 2005-9, Stephen Jungels
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
@sp3c73r2038
sp3c73r2038 / update.vbox.guest.addtion.markdown
Created November 18, 2013 08:10
update virtualbox guest addition (aka guest kernel modules)

assuming we are using ubuntu server as guest system

insert the additions image

usually ctrl-d (or cmd-d on OSX) when booted with GUI mode in virtualbox.

if the vagrant box has been booted, then open virtualbox GUI => modify machine settings => select storage, insert the additions image(iso file) by hand

install packages

@sp3c73r2038
sp3c73r2038 / using.ansible.with.pyenv.without.install.markdown
Last active December 28, 2015 07:09
ansible's installation just sucks. I want to use it while I'm hacking it, but not messing with PATH and PYTHONPATH !

Using Ansible with virtualenv (or pyenv if you prefer) without Install

assuming we are using $HOME/src as source code directory and $HOME/bin is in PATH so we can add script more easily.

get

get ansible source code first.

$ cd $HOME/src
@sp3c73r2038
sp3c73r2038 / call_by_name.py
Created October 21, 2013 03:43
call function by its name
import sys
if sys.version_info[0] == 3:
xrange = range
import functools
registered_functions = {}
def register_function(params):
@sp3c73r2038
sp3c73r2038 / rs_keywords.py
Last active December 25, 2015 20:39
grabing suggested search keywords on baidu
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from urllib.request import urlopen
from lxml import etree
res = urlopen('http://www.baidu.com/s?wd=keywords')
if res.code != 200:
sys.exit()
@sp3c73r2038
sp3c73r2038 / hatena.bookmark.js
Created October 15, 2013 08:44
hatena bookmark javascript expanded.
// javascript:
(
function () {
var d = (new Date);
var s = document.createElement('script');
s.charset = 'UTF-8';
s.src = 'http://b.hatena.ne.jp/js/Hatena/Bookmark/let.js?' + d.getFullYear() + d.getMonth() + d.getDate();
(document.getElementsByTagName('head')[0] || document.body).appendChild(s);
}
)();
@sp3c73r2038
sp3c73r2038 / instapaper.js
Created October 15, 2013 08:41
instapaper read later javascript expanded.
// javascript:function
iprl5 () {
var d=document, z=d.createElement('scr'+'ipt'), b=d.body,l=d.location;
try {
if (!b) throw(0);
d.title='(Saving...) ' + d.title;
z.setAttribute('src',
'https://www.instapaper.com/j/xxxxxxxxxxxxx=' + encodeURIComponent(l.href) + '&t=' + (new Date().getTime())
);
b.appendChild(z);
@sp3c73r2038
sp3c73r2038 / lazy.py
Last active December 21, 2015 17:19
lazy loading property decorator and Lazy class.
#
# lazy loading decorator and class, idea stolen from ruby's lazy class and
# http://stackoverflow.com/questions/3012421/python-lazy-property-decorator
#
from __future__ import print_function
#
# lazy loading decorator for class property
#
@sp3c73r2038
sp3c73r2038 / git_diff.py
Last active December 21, 2015 08:09
play with the git diff, retrieve info from the raw format, via cdiff (https://github.com/ymattw/cdiff)
#!/usr/bin/env python
from sys import stdin
from cdiff import PatchStream, DiffParser, markup_to_pager
diff_hdl = stdin
stream = PatchStream(diff_hdl)
class Option:
def __init__(self, **kwargs):
@sp3c73r2038
sp3c73r2038 / use.pyenv.markdown
Created August 7, 2013 03:12
use pyenv then!

Use PyEnv Then!

Pythonbrew is now deprecated. So we should use pyenv then.

pyenv is inspired by rbenv and ruby-build, and is pretty handy.

install

cd ~