This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
| // 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'); |
This file contains hidden or 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 [ "$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 |
This file contains hidden or 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
| // 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; |
This file contains hidden or 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
| // 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 ); | |
| } | |
| } |