Skip to content

Instantly share code, notes, and snippets.

View gabmontes's full-sized avatar

Gabriel Montes gabmontes

View GitHub Profile
const config = {
client: 'pg',
connection: {
host: 'localhost',
port: 5432,
user: 'user',
password: 'pass',
database: 'test'
},
debug: false
@gabmontes
gabmontes / not-jquery.js
Last active November 16, 2016 15:23
A partial (re)implementation of jQuery API as a polyfill for learning and teaching purposes
/**
* not-jquery
*
* A partial (re)implementation of jQuery API as a polyfill for learning and
* teaching purposes.
*
* https://gist.github.com/gabmontes/535a7b3b059b2a301a55b43e90ee0101
*/
// eslint-disable-next-line no-extra-semi
@gabmontes
gabmontes / not-react.js
Created November 16, 2016 15:27
A minimal (re)implementation of ReactDOM for learning and teaching purposes.
/**
* not-react
*
* A minimal (re)implementation of ReactDOM for learning and teaching purposes.
*
* https://medium.com/@gab_montes/react-in-200-bytes-28156e714165
*/
// eslint-disable-next-line no-extra-semi
;(function (global) {
@gabmontes
gabmontes / btc-balance.js
Last active November 28, 2016 15:30
Sum up the balances of a group of bitcoin addresses
const { Insight } = require('bitcore-explorers')
const promisify = require('tiny-promisify')
const addresses = [
/* bitcoin addresses here! */
]
const insight = new Insight()
const getUnspentUtxosAsync = promisify(insight.getUnspentUtxos.bind(insight))
@gabmontes
gabmontes / main.js
Created December 6, 2016 17:37
JsonParser coding exercise solution. 50 minutes to complete the exercise. Room for improvement? Definitely!
function JsonParser() {}
function convert(token, type) {
if (type === "number") {
return Number(token);
} else if (type === "string") {
return String(token);
}
}
@gabmontes
gabmontes / babel-presets-transforms-matrix.md
Created October 19, 2016 15:41
Summary of babel presets to transforms matrix

Presets to transforms

Data as of 18-oct-2016

| es2015 | es2016 | es2017 | latest | latest-minimal(*) | stage-3 | stage-2 | stage-1 | stage-0 --- |:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---: check-es2015-constants | x | | | x | x | | | | syntax-dynamic-import | | | | | | | x | | syntax-trailing-function-commas | | | x | x | x | x | | | transform-async-generator-functions | | | | | | x | | |

@gabmontes
gabmontes / slackbot-github-pr.js
Last active December 17, 2016 22:38
Slack bot that listens for GitHub's PR URLs and finds out if the PR was merged or not
const SlackBot = require('slackbots')
const GitHubApi = require('github')
const github = new GitHubApi({
version: '3.0.0',
protocol: 'https'
})
const bot = new SlackBot({
token: 'xoxb-000000000000-aaaaaaaaaaaaaaaaaaaaaaaa',
-----BEGIN PGP PUBLIC KEY BLOCK-----
mQENBFhqXdYBCADLd6j3IgA+ziom/ZLPkX1niDZ6EiDkA98rP3q+T7nSuQKpIooq
Kt0mTRpqxdroCp9O+IOizvJDpK6pb1kefDvTfren5xvVU3O/X4ihm9/W8VHCjgaF
zKzsIL3vH+Q61yTOxyfmq6nHbuoYPsyWcRoYOShCQTz/4XmUB9HHe/+Y46qEERcp
sbkJci0yDYCEtPk/Dri21NvNcRf8dJkYud36sRVesvWziXvY+eJCsP8+LgsP7wLA
5V4rhpV5eyWzFdxhX3q8qhKzOJlJeoudIAH0WmeDvWVHlWcOCp1WVoCdT4IVLduf
drEd1uO5vjv3y22H2KRaaibSFdYRO6T408IHABEBAAG0IUdhYnJpZWwgTW9udGVz
IDxnYWJyaWVsQGJsb3EuY29tPokBNwQTAQgAIQUCWGpd1gIbAwULCQgHAgYVCAkK
CwIEFgIDAQIeAQIXgAAKCRCYoLLoABE9pT5jB/0aoRG9AxqzanQydh+zB8QlWuXA
const waterfall = promises => init => promises.reduce((chain, promise) => chain.then(promise), Promise.resolve(init))
const mapFields = (obj, map) =>
Object.keys(map)
.map(key => ({ key, value: obj[map[key]] }))
.reduce((res, { key, value }) => Object.assign(res, { [key]: value }), {})