Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env python2
import sys
import os
import hashlib
def chunk_reader(fobj, chunk_size=1024):
"""Generator that reads a file in chunks of bytes"""
while True:
chunk = fobj.read(chunk_size)
@itsPG
itsPG / gist:42de79e2f236e95a39db
Created January 19, 2016 07:34
ExtUnderScore.js
Ext.define('Underscore', {
singleton: true,
constructor: function() {
// Underscore.js 1.8.3
// http://underscorejs.org
// (c) 2009-2016 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
// Underscore may be freely distributed under the MIT license.
(function() {
@itsPG
itsPG / urlDecode.js
Created January 4, 2016 06:30
urlDecode.js
function urlDecode(query) {
var queryString = query || window.location.search.slice(1),
decodeFn = window.decodeURIComponent,
options = decodeFn(queryString).split('&'),
pair, i, ret = {};
for (i = 0; i < options.length; ++i) {
pair = options[i].split('=');
ret[pair[0]] = pair[1];
}
@itsPG
itsPG / benchmark.py
Created November 22, 2015 13:51
python benchmark
import sys, itertools
from multiprocessing import Pool
def do_permutations(string):
for i in itertools.permutations(string):
pass
return 'Done count permutations of ' + string
@itsPG
itsPG / vnc.md
Last active November 12, 2015 01:56
Setup vncserver on ubuntu 14.04.3

Tested on Ubuntu 14.04.3 (2015/11/11)

install gnone related packages

apt-get install gnome-panel gnome-settings-daemon metacity nautilus gnome-terminal

install vnc server

apt-get install vnc4serve

start & stop vncserver to generate config

#!/bin/bash
#
# git-mv-with-history -- move/rename file or folder, with history.
#
# Moving a file in git doesn't track history, so the purpose of this
# utility is best explained from the kernel wiki:
#
# Git has a rename command git mv, but that is just for convenience.
# The effect is indistinguishable from removing the file and adding another
# with different name and the same content.
/* Assuming:
* dataview is a { xtype: "list" }
* dataview.itemTpl includes a <div class="deleteplaceholder"></div>
*
* Delete button will disappear as soon as something is touched
*/
dataview.on("itemswipe", function(dataview, ix, target, record, event, options) {
if (event.direction == "left") {
var del = Ext.create("Ext.Button", {
@itsPG
itsPG / casperjs-on-docker-note.txt
Last active August 29, 2015 14:23
install casperjs on Docker - Ubuntu
apt-get install nodejs
apt-get install npm
cd /usr/bin
ln -s nodejs node
npm install -g phantomjs
npm install -g casperjs
apt-get install libfreetype6-dev
apt-get install libfontconfig
@itsPG
itsPG / git_config.sh
Last active September 12, 2022 01:36
git config
# User
git config --global user.name YOUR_NAME
git config --global user.email YOUR_EMAIL@gmail.com
git config --global core.editor vim
# Common
git config --global alias.st status
git config --global alias.ci commit
git config --global alias.co checkout
git config --global alias.br branch