Skip to content

Instantly share code, notes, and snippets.

View beatak's full-sized avatar
🍄
Mushroom

Takashi M beatak

🍄
Mushroom
  • San Francisco, CA
View GitHub Profile
@beatak
beatak / pkg_to_delete.sh
Created April 16, 2012 21:05
how to delete files that .pkg installs on your machine...
# ${original.pkg} => the original name of .pkg file
pkgutil --expand ${original.pkg} expanded.pkg
# to find what Bom files you got
find gviz.pkg -name 'Bom'
# to show the files and directories
find gviz.pkg -name 'Bom' | xargs -I{} lsbom {}
# lsbom exports "tab delimited file". And also it's on relative path.
@beatak
beatak / shyiezeRecur.js
Created April 20, 2012 18:53
Add shy well
var shyiezeRecur = function () {
var $div = $('#something');
var MAX_CHAR = 55;
$div.data('shyed');
var w = $div.width();
$div.find('*').each(
function () {
var $this = $(this);
if ($this.find('*').length === 0 && $this.width() > w) {
$this.shyize({limit: MAX_CHAR});
@beatak
beatak / roundbytable.js
Created April 26, 2012 15:52
give a value and lookup array, and returns the closest value in the array.
var getRoundupValue = function (val, table) {
var result;
if (val <= table[0]) {
result = table[0];
}
else if (val >= table[table.length - 1]) {
result = table[table.length - 1];
}
else {
var v1, v0, d0, d1;
// http://stackoverflow.com/questions/962802/is-it-correct-to-use-javascript-array-sort-method-for-shuffling
Array.prototype.shuffle = function () {
var tmp, current, top = this.length;
if (top) {
while(--top) {
current = Math.floor(Math.random() * (top + 1));
tmp = this[current];
this[current] = this[top];
this[top] = tmp;
@beatak
beatak / isMobile.js
Created June 13, 2012 01:36
ghetto mobile checking
(function () {
var _mobile;
window.isMobile = function () {
if (!_mobile) {
var ua = navigator.userAgent;
_mobile = {
a: ua.match(/Android/i) ? true : false,
bb: ua.match(/BlackBerry/i) ? true : false,
ios: ua.match(/iPhone|iPad|iPod/i) ? true : false,
win: ua.match(/IEMobile/i) ? true : false
@beatak
beatak / dabblet.css
Created August 4, 2012 20:06
The first commented line is your dabblet’s title
/**
* The first commented line is your dabblet’s title
*/
#menu {
background-repeat: no-repeat;
background-position: center center;
background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAOcAAAHzCAYAAADbxAoZAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAAK8AAACvABQqw0mAAAABx0RVh0U29mdHdhcmUAQWRvYmUgRmlyZXdvcmtzIENTM5jWRgMAAAuTSURBVHic7d0/cxz1Hcfx715ofR1NfE9AVyQzKWIXMKbAPIG4sKEJFCZujAoIRSaZDCQFA4WBgkAh3HjswtB47EJqGMIMcnpO6ZJMTulZHsCmkPxH0lm6k066D/j1qkA+7e3t6X372z+323Rd19UCjcfj2hyP933M0nBY/X7/2Obh/vr6sU17Efr9fi0Nh8f+PG3b1sZodOzPc1yO/r43VdVN+O/pXF/5vJaGw7px6+bkqe+Os23b+vjah7W+vl4bo9Gh3+jZX/j0L67bfvRRpjn9NPabfFO157Otqa66o0/7ic8z+x9Bntlfw4P3a+L7NvF9OC7zX/5Xl9+oq8vLe59pd5xrq6t15fLrc33y/S36j23Rz3+cdr62/T+QDlgOBwQwaXRzmA/AjdGo2rad8bd2OuwH7+Mff0f+u5jyA2NpOKzN8bhu3Lq5ZyX4zO4Hf3n7i6qqevW11+pU/1RVNbU0XNqx4KdZKz55AR3uRZ8eDGowGMz8ez91Z86eXfQscESfr6zU7998q27curmjsz1rzrfffKuqqt774P2TnUN4il25/HoNBoP6w5/++PBnD9ecbdvWF7dv19rqar33wfvVtu2BO2HmuSPlpHZiQKL3Pni/Xnju+XrxpfMPR0MP15zj8bheeO75KSYz67B0Dtt0h9zgn/fQ+sl2T+/g6e+3XbT1b4
@beatak
beatak / gist:3750533
Created September 19, 2012 16:11
stack overflow
var obj = {
onBodyClick: function (ev) {
console.log('onBodyClick');
$(document).triggerHandler('onBodyClick', [this]);
}
};
$(document.body).on('click', obj.onBodyClick);
@beatak
beatak / strip console
Created October 18, 2012 16:52
testing esprima/escodegen
#!/usr/local/bin/node
var parse = require('esprima').parse;
var generate = require('escodegen').generate;
// MULTI ARGS ====================================
var code = "console.log('a', 'b', 'c');";
console.log(code);
console.log( '====' );
var ast = parse(code);
@beatak
beatak / strip_console.js
Created October 18, 2012 18:31
testing esprima/escodegen 2
#!/usr/local/bin/node
var parse = require('esprima').parse;
var generate = require('escodegen').generate;
var codes = [
"console.log('a', 'b', 'c');",
"console.log('a');",
"console.log();"
];
@beatak
beatak / cli_test
Created November 13, 2012 21:58
JavaScript file
#!/usr/bin/env node
var cli = require('cli');
var options = cli.parse({
boola: ['b', 'testing boolean value', 'bool', true]
});
console.log(options);