This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function busy (ms) { | |
var arr = '|/―\\', i = 0; | |
setInterval (function() { | |
i = !arr[i] ? 0 : i; | |
process.stdout.write ('\r' + arr[i] + ' '); | |
i++; | |
}, ms); | |
} | |
busy (90); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var geo = require ('geoip2ws') ('userId', 'licenseKey'); | |
// console.log is limited to only 3 levels | |
function output (err, data) { | |
console.dir (err || data, {depth: 10}); | |
} | |
// Lookup Google | |
geo ('insights', '173.194.65.100', output); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env node | |
/* | |
USAGE: cat file.json | parsejson [OPTION] [PROPERTY] | |
Name: parsejson | |
Description: Parse JSON text to human-readable tree with syntax coloring. | |
Source: https://frankl.in/code/json-cli-parser-with-syntax-coloring | |
Author: Franklin (https://github.com/fvdm) | |
License: Unlicense / Public Domain |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Force download for certain URLs with ?force_download | |
set $forceDownload ""; | |
set $filename ""; | |
if ($request_filename ~ /([^/]+)$) { | |
set $filename $1; | |
} | |
if ($request_uri ~ [\?&]force_download(=(?<filename>[^&$]+)|&|$)) { | |
set $forceDownload "attachment; filename=\"$filename\""; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
export arg=$@ | |
find . -name '.git' -type d -exec bash -c 'path=${1%/.git}; echo $path; cd "$path" && git gc $arg' 0 {} \; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
if [ $TERM = "screen" ]; then | |
sudo sh -c ' \ | |
apt-get update \ | |
&& apt-get $1 upgrade \ | |
&& apt-get $1 dist-upgrade \ | |
&& apt-get $1 autoremove \ | |
&& apt-get clean' | |
else | |
screen -S update ~/bin/update $1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Only copy new images to another folder: | |
require ('osx-photostream') ('~/Pictures/iCloud'); | |
// Do more stuff with them: | |
var ps = require ('osx-photostream') (); | |
ps.on ('update', function (file) { | |
console.log ('New image added: ' + file.filename); | |
};) |