Skip to content

Instantly share code, notes, and snippets.

View fvdm's full-sized avatar
🦖
I may be slow to respond

Franklin fvdm

🦖
I may be slow to respond
View GitHub Profile
@fvdm
fvdm / humanBytes.js
Last active October 7, 2015 08:07
Convert bytes to KiB, MiB, etc.
// Convert bytes to KiB, MiB, etc. (object)
// humanBytes( number, numDecimals )
// ex. humanBytes( 10714 ) = { number: 10, str: "10 KiB", unit: "KiB" }
// ex. humanBytes( 10714 ).str = "10 KiB"
// ex. humanBytes( 10714, 2 ).str = "10.46 KiB"
function humanBytes( bytes, decimals ) {
var units = ['KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB'];
var unit = 'B';
var num = bytes;
var dec = decimals !== undefined ? Math.pow( 10, decimals ) : 1;
@fvdm
fvdm / sabnzbd_push.js
Created September 8, 2012 01:57
Push notification script for SABnzbd+
#!/usr/bin/node
/*
Post-process script for SABnzbd and AppNotifications
~ when a download is completed this script will send a push
~ notification to your mobile device using AppNotifications.com
Depends:
- NodeJS: http://nodejs.org
- NPM: http://npmjs.org (comes with Node)
@fvdm
fvdm / appnet2netbot.js
Created October 20, 2012 23:56
Safari bookmarklet to open App.net user or post in Netbot app, may work in other browsers too.
javascript:window.location.href.replace(/app\.net\/([\w-]+)(\/post\/([\d]+))?/,function(s,u,s,p){if(p){window.location='netbot:///status/'+p}else{window.location='netbot:///user_profile/'+u}})
@fvdm
fvdm / twitter2tweetbot.js
Created October 20, 2012 23:58
Safari bookmarklet to open Twitter user or tweet in Tweetbot app, may work in other browsers too.
javascript:window.location.href.replace(/twitter\.com\/(\!#\/)?([\w-]+)(\/status\/(\d+))?/,function(s,h,u,s,p){if(p){window.location='tweetbot:///status/'+p}else{window.location='tweetbot:///user_profile/'+u}})
@fvdm
fvdm / evernote.js
Created December 30, 2012 00:38 — forked from codewzrd/evernote.js
CmdUtils.makeBookmarkletCommand({
name: "Evernote",
description: "Save a note on Evernote.",
icon: "http://www.evernote.com/favicon.ico",
homepage: "http://www.makadia.com",
author: {name: "Svapan Makadia", email: "codewzrd@hotmail.com"},
help: "Select content and invoke this command to save the selection as a note or just save the whole page without selecting anything.",
url: "javascript:(function(){EN_CLIP_HOST='http://www.evernote.com';try{var%20x=document.createElement('SCRIPT');x.type='text/javascript';x.src=EN_CLIP_HOST+'/public/bookmarkClipper.js?'+(new%20Date().getTime()/100000);document.getElementsByTagName('head')[0].appendChild(x);}catch(e){location.href=EN_CLIP_HOST+'/clip.action?url='+encodeURIComponent(location.href)+'&title='+encodeURIComponent(document.title);}})();"
})
@fvdm
fvdm / dud.php
Last active December 19, 2015 16:09
Mac OSX alternative script for `alias dud='du -ahd 1 | sort -hr | head -n 11'` on Debian. -- https://frankl.in/code/755-top-10-files-directories-by-size
#!/usr/bin/php
<?php
$results = 11; // add 1 for dir total
$cwd = getcwd();
$dir = scandir( $cwd );
foreach( $dir as $item ) {
if( $item === '..' ) { continue; }
$path = $cwd .'/'. $item;
@fvdm
fvdm / object_foreach.js
Created January 29, 2015 10:39
Object.forEach()
// Object.forEach( function( value, key, index ) {} )
Object.prototype.forEach = function( cb ) {
var keys = Object.keys(this);
for( var i = 0; i < keys.length; i++ ) {
var key = keys[i];
cb( this[key], key, i );
}
}
@fvdm
fvdm / number_humanBytes.js
Created January 29, 2015 11:01
Number.humanBytes()
// Convert bytes to string '123.6 KiB', MiB, etc.
// var bytes = 8765432
// var human = bytes.humanBytes( 2 )
// 8.36 MiB
Number.prototype.humanBytes = function( decimals ) {
var units = ['KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB'];
var unit = 'B';
var bytes = this.valueOf();
var dec = decimals ? Math.pow( 10, decimals ) : 1;
var i = 0;
#!/bin/sh
if [ "$1" == "-h" ]; then
echo "Colorful Homebrew update script"
echo
echo "USAGE: update [-y]"
echo
echo " -y skip questions"
echo " -h display this help"
echo
exit 0
// Add pre-exit script
process.on ('exit', code => {
console.log (`Whoa! Exit code ${code}, cleaning up...`);
// i.e. close database
});
// Add another for fun
process.on ('exit', code => {
if (code > 0) {
console.log ('Hmm something went wrong');