Skip to content

Instantly share code, notes, and snippets.

Avatar

Matías Lescano mjlescano

View GitHub Profile
@mjlescano
mjlescano / publish-if-needed
Last active Sep 17, 2018
Shell command to publish an npm package only if its needed
View publish-if-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 Oct 26, 2017
Auto-merge GitHub PR when all checks passed
View index.js
(() => {
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 Jun 21, 2017
Filstack PDF Preview - PoC
View .gitignore
dist
node_modules
@mjlescano
mjlescano / import.js
Created Feb 1, 2017
Imports Topics to DemcoracyOS from a JSON file
View import.js
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 Oct 17, 2016
Topics with Author CSV export example - DemocracyOS | Runs with `NODE_PATH=. node tocsv.js`
View 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 Sep 26, 2016
Mass-edit emails of users on DemocracyOS on mongoose
View script.js
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 Mar 26, 2016
Minimal helper functions for logging on Bash
View log.sh
#! /bin/bash
info () {
echo "$(tput setaf 6) · $@$(tput sgr0)"
}
warn () {
echo "$(tput setaf 3) · $@$(tput sgr0)"
}
View index.sh
git config --global alias.cf '!sh -c "git diff --name-only | uniq | xargs subl"'
@mjlescano
mjlescano / onResize.js
Last active Jan 15, 2016
window.onresize handler with a debounced calling to avoid unnecessary re-paints
View onResize.js
/**
* 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 Oct 6, 2015
Gist to migrate a running instance of DemocracyOS on Heroku from `^0.17.0` to `1.0.0`.
View democracyos-migrate-to-1.0.0.sh
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"
You can’t perform that action at this time.