Skip to content

Instantly share code, notes, and snippets.

@mjlescano
mjlescano / publish-if-needed
Last active September 17, 2018 17:28
Shell command to publish an npm package only if its needed
#!/bin/bash
CURRENT_VERSION=$(npm show $(node -pe 'require("./package.json").name') version)
NEXT_VERSION=$(node -pe 'require("./package.json").version')
[ "$CURRENT_VERSION" != "$NEXT_VERSION" ] && npm publish
@mjlescano
mjlescano / index.js
Created October 26, 2017 17:04
Auto-merge GitHub PR when all checks passed
(() => {
const check = () => {
const status = document.querySelector('[data-combined-status]').dataset.combinedStatus
switch(status) {
case 'success':
const btn = document.querySelector('[data-details-container=".js-merge-pr"]')
if (!btn) {
alert('PR already merged.')
break
@mjlescano
mjlescano / .gitignore
Last active June 21, 2017 17:06
Filstack PDF Preview - PoC
dist
node_modules
@mjlescano
mjlescano / import.js
Created February 1, 2017 18:43
Imports Topics to DemcoracyOS from a JSON file
const fs = require('fs')
const mongoose = require('mongoose')
const Batch = require('batch')
const models = require('lib/models')
const data = require('./topics.json')
const ObjectId = mongoose.Schema.ObjectId
models()
@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})
@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 || 'debug-email@gmail.com'
//--------------------------
require('lib/models')()
var config = require('lib/config')
var models = require('lib/models')
var User = models.User
@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 / 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 / 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 / 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"