Skip to content

Instantly share code, notes, and snippets.

@mjlescano
mjlescano / waitFor.js
Last active August 29, 2015 14:15
Silly lib that executes a given callback when a variable is defined on window.
/**
* waitFor.js
*
* Silly lib that executes a given callback when a variable is defined on window.
*
* Matías Lescano | @mjlescano
* Licensed under the MIT license
*/
;if( !window.waitFor ) (function(w){
@mjlescano
mjlescano / retry
Last active August 29, 2015 14:20 — forked from dansimau/gist:842415
Bash function for running a command, checking the return code, and re-trying it `x` times after `y` sleep seconds.
#!/bin/bash
# Usage:
# retry <commands...>
# retry <retry times> <commands...>
# retry <retry times> <retry wait> <commands...>
if [[ $2 =~ ^-?[0-9]+$ ]]; then
cmd="${@:3}"
retry_times=$1
@mjlescano
mjlescano / m
Last active August 29, 2015 14:20
`mpg123` wrapper. It enables by default keyboard shortcuts and play directories.
#!/bin/bash
if [[ -d "$*" ]]; then
find "${*%/}" -iname '*.mp3' -print0 -exec $0 {} +
else
mpg123 -C "$@"
fi
@mjlescano
mjlescano / Readme.md
Last active December 15, 2023 06:52
Bash command to copy permissions from a file to other(s).
@mjlescano
mjlescano / democracyos-migrate-to-1.0.0.sh
Last active October 6, 2015 17:47
Gist to migrate a running instance of DemocracyOS on Heroku from `^0.17.0` to `1.0.0`.
log() {
echo "$(tput setaf 6) · $@$(tput sgr0)"
}
read -e -p 'Heroku App Name? (e.g. `legoland-democracyos`) ' APP_NAME
read -e -p 'Mongo Host:port/db? (e.g. `ds043991.mongolab.com:43991/heroku_app34008377`) ' MONGO_HOST
read -e -p 'Mongo User? ' MONGO_USER
read -e -p 'Mongo Pass? ' MONGO_PASS
log "Setting maintenance:on"
@mjlescano
mjlescano / onResize.js
Last active January 15, 2016 02:29
window.onresize handler with a debounced calling to avoid unnecessary re-paints
/**
* onResize.js
*
* `window.onresize` handler with a debounced calling to avoid unnecessary re-paints.
*
* e.g.:
* onResize.add(function(){
* console.log('Executed on window resize! But debounced.')
* })
*
@mjlescano
mjlescano / index.sh
Created January 7, 2016 19:37
Open all files with merge conflicts (with Sublime). From: https://coderwall.com/p/dy86xg/open-all-files-with-merge-conflicts-with-sublime
git config --global alias.cf '!sh -c "git diff --name-only | uniq | xargs subl"'
@mjlescano
mjlescano / log.sh
Created March 26, 2016 21:49
Minimal helper functions for logging on Bash
#! /bin/bash
info () {
echo "$(tput setaf 6) · $@$(tput sgr0)"
}
warn () {
echo "$(tput setaf 3) · $@$(tput sgr0)"
}
@mjlescano
mjlescano / script.js
Last active September 26, 2016 18:17
Mass-edit emails of users on DemocracyOS on mongoose
var OWNER_EMAIL = process.env.OWNER_EMAIL || '[email protected]'
//--------------------------
require('lib/models')()
var config = require('lib/config')
var models = require('lib/models')
var User = models.User
@mjlescano
mjlescano / tocsv.js
Created October 17, 2016 11:49
Topics with Author CSV export example - DemocracyOS | Runs with `NODE_PATH=. node tocsv.js`
var fs = require('fs')
var json2csv = require('json2csv')
var models = require('lib/models')
models()
var Topic = models.Topic
Topic
.find({deletedAt: null})