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 / 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;
@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 / 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;
#!/bin/sh
vn="/usr/bin/vnstat -i eth0 -s"
echo
$vn | head -n 2 | tail -n 1 # header
$vn | tail -n 2 | head -n 1 # today
$vn | head -n 5 | tail -n 1 # month
var bol = require ('bolcom') ('apikey');
// Find something
bol.catalog.search ({ q: 'node.js' }, function (err, data) {
if (err) {
console.log ('Search failed');
console.log (err);
} else {
for (var i = 0; i < data.products.length; i++) {
var product = data.products [i];
# swap when less than N % mem is available
vm.swappiness = 10
# cache inodes (50 = don't shrink inode cache)
vm.vfs_cache_pressure = 50
# % memory available for all processes -- some suggest 50
vm.overcommit_ratio = 100
# 0 = fuzzy available memory guessing : bad