Skip to content

Instantly share code, notes, and snippets.

View gibatronic's full-sized avatar
💭
&> /dev/null

Gibran Malheiros gibatronic

💭
&> /dev/null
View GitHub Profile
const crypto = require('crypto');
let hash;
let index = 0;
function check() {
const data = hash.read().toString('hex');
hash.removeListener('readable', check);
@gibatronic
gibatronic / leave
Created April 11, 2016 16:47
Stupid tool to calculate what time I should leave given the time I arrived at work to complete 8.5h with 1h of lunch.
#!/usr/bin/env node --harmony
const output = function(...data) {
process.stdout.write(data.join(''));
};
const main = function(hour, minute) {
hour = +hour;
minute = (minute / 60) || 0;
@gibatronic
gibatronic / options
Created April 11, 2016 14:00
bash snippet to parse arguments
#!/usr/bin/env bash
NAME=${NAME:-unknown}
main() {
while [ "$#" != 0 ]; do
case "$1" in
-h|--help) usage ;;
-n|--name) shift; set_name "$1" ;;
*) work $1; exit ;;
@gibatronic
gibatronic / spinner
Created April 11, 2016 13:58
bash spinner for indefinite progress
#!/usr/bin/env bash
spinner_abort() {
[ -n "$SPINNER_PID" ] && kill $SPINNER_PID
echo -e '\033[?25h'
exit 0
}
spinner_loop() {
while true; do
@gibatronic
gibatronic / README.md
Last active May 5, 2023 12:14
Node crypto.pbkdf2 example to securely store and check passwords.

password.js

Tiny Node.js module to securely hash and compare passwords using pbkdf2 with per password random salt.

Usage

To hash a password:

var password = require('./password');

integrity

Simple tool to generate the integrity attribute for subresource integrity.

Example

Let's say you want to use Backbone from this CDN:

https://cdnjs.cloudflare.com/ajax/libs/backbone.js/1.2.3/backbone-min.js
@gibatronic
gibatronic / spinner
Created October 1, 2015 13:04
nice shell spinner
#!/usr/bin/env python
# coding: utf-8
import sys
import time
cursor = '\033[1D'
frames = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏']
amount = len(frames)
hide = '\033[?25l'
@gibatronic
gibatronic / options
Created October 1, 2015 13:03
parse options in shell script
#!/usr/bin/env bash
ACTION=
OPTION_A='undefined'
OPTION_B='undefined'
OPTIONS=("$@")
LENGTH=${#OPTIONS[@]}
main() {
echo " Action: $ACTION"
@gibatronic
gibatronic / README.md
Created October 1, 2015 12:45
RGB shell color
# usage
./color <r> <g> <b>
@gibatronic
gibatronic / package.json
Last active January 18, 2017 13:32
using npm as a task runner
{
"scripts": {
"scripts": "node_modules/.bin/coffee scripts/*.coffee -o build",
"styles": "node_modules/.bin/node-sass styles/*.scss -o build",
"watch": "node_modules/.bin/vigilia 'scripts/**/*.coffee':'npm run scripts' 'styles/**/*.scss':'npm run styles'"
}
}