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
#!/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
function busy (ms) {
var arr = '|/―\\', i = 0;
setInterval (function() {
i = !arr[i] ? 0 : i;
process.stdout.write ('\r' + arr[i] + ' ');
i++;
}, ms);
}
busy (90);
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];
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);
#!/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
# 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\"";
#!/bin/sh
export arg=$@
find . -name '.git' -type d -exec bash -c 'path=${1%/.git}; echo $path; cd "$path" && git gc $arg' 0 {} \;
# 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
#!/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
// 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);
};)