Skip to content

Instantly share code, notes, and snippets.

View davidbarral's full-sized avatar

David Barral davidbarral

View GitHub Profile
@davidbarral
davidbarral / client.3.up.tunnelblick.sh
Created October 12, 2011 18:30
Tunnelblick "Set nameserver (alternate 1)" up script modified to support multiple search domains
#!/bin/bash -e
#
# 2011-04-18 Changed from client.up.tunnelblick.sh to client.3.up.tunnelblick.sh and to use leasewatch3
trap "" TSTP
trap "" HUP
trap "" INT
export PATH="/bin:/sbin:/usr/sbin:/usr/bin"
# Process optional arguments (if any) for the script
@davidbarral
davidbarral / bitbucket.zsh
Last active December 23, 2015 19:39
Function + Aliases to quick open severla Bitbuket pages related to the current Git project.
# USAGE:
#
# Inside a bitbucket repo (remote must be origin) call:
#
# bb -> Go to overview page
# bbs <branch> -> Go to branch source. Defaults to master
# bbc <commit> -> Go to commit diff. Defaults to HEAD
# bbp -> Go to pull requests page
# bbnp -> New pull reques form
#
@davidbarral
davidbarral / npmenv.completions.fish
Last active November 22, 2017 10:36
Poor man npmenv solution for fish (Use multiple .npmrc profiles)
# Completions for npmenv.fish
function __fish_npmenv_needs_command
set cmd (commandline -opc)
if [ (count $cmd) -eq 1 -a $cmd[1] = 'npmenv' ]
return 0
end
return 1
end
@davidbarral
davidbarral / App.js
Created November 12, 2017 15:56
Toy redux and react-redux
import React, { Component } from "react";
import PropTypes from "prop-types";
import ReactDOM from 'react-dom';
// Toy redux ----------------------------------------------------------
const createStore = (reducer, initialState) => {
let state = initialState;
let subscribers = [];
@davidbarral
davidbarral / callbackify.js
Last active September 2, 2020 01:31
Callbackify: adhoc callbackify
const callbackify = fn => (...args) => {
const callback = args[args.length - 1];
const fnArgs = args.slice(0, -1);
fn(...fnArgs)
.then(value => {
callback(undefined, value);
})
.catch(error => {
callback(error);
});
@davidbarral
davidbarral / token-verification.js
Created January 20, 2018 15:44
Promisify: initial code
const jwt = require("jsonwebtoken");
const verifyToken = token => new Promise((resolve, reject) => {
jwt.verify(token, CERTIFICATE, { algorithms: ["RS256"] }, (error, payload) => {
if (error) {
reject(error);
} else {
resolve(payload);
}
});
@davidbarral
davidbarral / async-code.js
Last active January 20, 2018 15:47
Promisify: using promisified code
const usefulFunction = async () => {
try {
const payload = await verifyToken(token);
return payload;
} catch(e) {
console.error("Bad token", e);
}
};
@davidbarral
davidbarral / token-verification.js
Created January 20, 2018 15:50
Promisify: adhoc promisify
const jwt = require("jsonwebtoken");
const promisify = fn => (...args) => new Promise((resolve, reject) => {
fn(...args, (error, value) => {
if (error) {
reject(error);
} else {
resolve(value);
}
});
@davidbarral
davidbarral / token-verification.js
Created January 20, 2018 15:57
Promisify: node promisify
const { promisify } = require("util");
const jwt = require("jsonwebtoken");
const jwtVerify = promisify(jwt.verify);
const verifyToken = token => jwtVerify(token, CERTIFICATE, { algorithms: ["RS256"] });