Skip to content

Instantly share code, notes, and snippets.

@hfeeki
hfeeki / bytesToSize.js
Last active August 29, 2015 14:10 — forked from lanqy/bytesToSize.js
// from http://scratch99.com/web-development/javascript/convert-bytes-to-mb-kb/
function bytesToSize(bytes) {
var sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
if (bytes == 0) return 'n/a';
var i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)));
if (i == 0) return bytes + ' ' + sizes[i];
return (bytes / Math.pow(1024, i)).toFixed(1) + ' ' + sizes[i];
};
@hfeeki
hfeeki / install_pip3_in_mac.sh
Created November 28, 2014 15:14
Install pip3 in mac osx after installed python3 with brew
# download and install setuptools
curl -O https://bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py
python3 ez_setup.py
# download and install pip
curl -O https://raw.githubusercontent.com/pypa/pip/master/contrib/get-pip.py
python3 get-pip.py
@hfeeki
hfeeki / visitor.py
Last active August 29, 2015 14:10 — forked from devdave/visitor.py
from pynarcissus import jsparser
from collections import defaultdict
class Visitor(object):
CHILD_ATTRS = ['thenPart', 'elsePart', 'expression', 'body', 'initializer']
def __init__(self, filepath):
self.filepath = filepath
#List of functions by line # and set of names
function xhr(options) {
var deferred = Q.defer(),
req = new XMLHttpRequest();
req.open(options.method || 'GET', options.url, true);
// Set request headers if provided.
Object.keys(options.headers || {}).forEach(function (key) {
req.setRequestHeader(key, options.headers[key]);
});
@hfeeki
hfeeki / Aop.js
Last active August 29, 2015 14:08
Aop for javascript
// http://fredrik.appelberg.me/2010/05/07/aop-js.html
var Aop = {
// Apply around advice to all matching functions in the given namespaces
around: function(pointcut, advice, namespaces) {
// if no namespaces are supplied, use a trick to determine the global ns
if (namespaces == undefined || namespaces.length == 0)
namespaces = [ (function(){return this;}).call() ];
// loop over all namespaces
for(var i in namespaces) {
var ns = namespaces[i];
/**
* Converts an image to
* a base64 string.
*
* If you want to use the
* outputFormat or quality param
* I strongly recommend you read the docs
* @ mozilla for `canvas.toDataURL()`
*
* @param {String} url
@hfeeki
hfeeki / keychaindump.c
Last active August 29, 2015 14:08
keychaindump for mac osx
// Build instructions:
// $ gcc keychaindump.c -o keychaindump -lcrypto
// Usage:
// $ sudo ./keychaindump [path to keychain file, leave blank for default]
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <mach/mach.h>
@hfeeki
hfeeki / README
Last active August 29, 2015 14:07 — forked from rwest/README
These two files should help you to import passwords from mac OS X keychains to 1password.
Assumptions:
1) You have some experience with scripting/are a power-user. These scripts worked for me
but they haven't been extensively tested and if they don't work, you're on your own!
Please read this whole document before starting this process. If any of it seems
incomprehensible/frightening/over your head please do not use these scripts. You will
probably do something Very Bad and I wouldn't want that.
2) You have ruby 1.9.2 installed on your machine. This comes as standard with Lion, previous
versions of OS X may have earlier versions of ruby, which *may* work, but then again, they
@hfeeki
hfeeki / README
Last active August 29, 2015 14:07 — forked from rwest/README
These two files should help you to import passwords from mac OS X keychains to 1password.
Assumptions:
1) You have some experience with scripting/are a power-user. These scripts worked for me
but they haven't been extensively tested and if they don't work, you're on your own!
Please read this whole document before starting this process. If any of it seems
incomprehensible/frightening/over your head please do not use these scripts. You will
probably do something Very Bad and I wouldn't want that.
2) You have ruby 1.9.2 installed on your machine. This comes as standard with Lion, previous
versions of OS X may have earlier versions of ruby, which *may* work, but then again, they
@hfeeki
hfeeki / Image_Filter.java
Last active August 29, 2015 14:07
steganography with java
/*
*@author William_Wilson
*@version 2.0
*Created May 10, 2007
*/
/*
*Import List
*/