Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env python
import sys, errno
if __name__ == "__main__":
try:
with open(sys.argv[1]) as f:
s = f.read()
print('read', len(s), 'bytes.')
except IOError as x:
if x.errno == errno.ENOENT:
@g1eb
g1eb / convertTime.js
Created September 23, 2017 09:21
Convert seconds to a human readable representation
export function convertTime(seconds) {
var seconds = parseInt(seconds, 10)
var hours = Math.floor(seconds / 3600)
var minutes = Math.floor((seconds - (hours * 3600)) / 60)
var seconds = seconds - (hours * 3600) - (minutes * 60)
if ( !!hours ) {
if ( !!minutes ) {
return `${hours}h ${minutes}m ${seconds}s`
} else {
return `${hours}h ${seconds}s`
@g1eb
g1eb / keybase.md
Created May 19, 2017 12:48
keybase verification

Keybase proof

I hereby claim:

  • I am g1eb on github.
  • I am g1eb (https://keybase.io/g1eb) on keybase.
  • I have a public key ASCb7EW_LWGKw2VsSv9cUNDey3jZO0BVd_4N6djn_RZqWAo

To claim this, I am signing this object:

@g1eb
g1eb / output.json
Created November 22, 2016 17:40
JSON of aggregated topics and counts acquired by parsing De Profundis by Oscar Wilde.
[{"text": "life", "size": 100.0}, {"text": "me", "size": 62.886597938144334}, {"text": "world", "size": 59.17525773195876}, {"text": "it", "size": 53.608247422680414}, {"text": "man", "size": 53.608247422680414}, {"text": "people", "size": 49.896907216494846}, {"text": "art", "size": 48.96907216494846}, {"text": "sorrow", "size": 48.04123711340206}, {"text": "soul", "size": 48.04123711340206}, {"text": "christ", "size": 46.18556701030928}, {"text": "love", "size": 37.83505154639175}, {"text": "great", "size": 35.97938144329896}, {"text": "prison", "size": 35.05154639175258}, {"text": "day", "size": 31.34020618556701}, {"text": "moment", "size": 28.556701030927833}, {"text": "time", "size": 26.701030927835053}, {"text": "greek", "size": 26.701030927835053}, {"text": "pleasure", "size": 26.701030927835053}, {"text": "god", "size": 25.77319587628866}, {"text": "nature", "size": 25.77319587628866}, {"text": "beautiful", "size": 24.84536082474227}, {"text": "live", "size": 24.84536082474227}, {"text": "heart", "si
@g1eb
g1eb / week_indexes_in_month.js
Created June 23, 2016 13:57
Array of week indexes in current month (requires moment.js)
scope.weeks = function () {
var n = moment.duration(
moment().endOf('month') - moment().startOf('month')
).weeks() + 1;
return Array.apply(null, {length: n}).map(Number.call, Number);
}();
# Git wrapper with [y/N] prompt
g () {
out="$(script -q /dev/null command git "$@" 2>&1)"; out="${out//$'\r'}"
echo "$out"
if [[ "$out" == *"Did you mean this?"* ]]; then
cmd="${out##*$'\n'}"; cmd="${cmd//$'\t'}"
tput bold; read -r -p "[y/N]? " < /dev/tty res
if [[ $res =~ ^$|^([yY]|[yY][eE][sS])$ ]]; then
echo; command git $cmd
fi