Skip to content

Instantly share code, notes, and snippets.

It's either a binary trap, or it's not.

Vance Lucas vlucas

It's either a binary trap, or it's not.
Block or report user

Report or block vlucas

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
vlucas / routes.js
Created Feb 13, 2018
Simple JS router (client+node.js)
View routes.js
'use strict';
let pathToRegexp = require('path-to-regexp');
let defaultRoute;
let routes = [];
* GET route
* @param {String} pattern - Express.js style route pattern or bare URL string
View i18n.js
// ES5 way
t: function () {
let key = _.first(arguments);
let replacements =;
let translation = translations[key];
if (translation && replacements.length) {
translation = format.apply(null, [translation].concat(replacements));
vlucas / index.js
Last active May 16, 2017
JS Questions
View index.js
// stuff
function slug (title) {
// do something
slug('Some Post');
class Post {
slug () {
vlucas / encryption.js
Last active Nov 9, 2019
Stronger Encryption and Decryption in Node.js
View encryption.js
'use strict';
const crypto = require('crypto');
const ENCRYPTION_KEY = process.env.ENCRYPTION_KEY; // Must be 256 bits (32 characters)
const IV_LENGTH = 16; // For AES, this is always 16
function encrypt(text) {
let iv = crypto.randomBytes(IV_LENGTH);
let cipher = crypto.createCipheriv('aes-256-cbc', Buffer.from(ENCRYPTION_KEY), iv);
vlucas /
Created May 5, 2016
Shell function to setup a new React.js project
# Setup new React.js project
react_new() {
echo ">> Setting up NPM...";
npm init -y;
echo ">> Running NPM install...";
npm install --save react react-dom;
npm install --save-dev browserify babelify babel-preset-es2015 babel-preset-react fsmonitor;
echo ">> Setting up initial files...";
vlucas / markdown-import.php
Last active Sep 7, 2019
Imports Markdown files in a local directory into a WordPress installation
View markdown-import.php
// Turn on all error reporting so we can see if anything goes wrong
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
// Relative path to your wp-config.php file (to connect to the database)
require '../wp-config.php';
require './frontmatter.php'; // Parses YAML frontmatter -
require './Parsedown.php'; // Markdown parser -
vlucas /
Last active Aug 29, 2015
Deploy a Static Site to Github Pages
GIT_REPO_URL=$(git config --get remote.origin.url)
mkdir .deploy
cp -R ./* .deploy
cd .deploy
git init .
git remote add github $GIT_REPO_URL
git checkout -b gh-pages
git add .
View gist:09acb40ccbdd945d26ce
// PG directly
var pg = require('pg');
var client = new pg.Client(process.env.DATABASE_URL).connect();
// Node-DBI wrapper
var DBWrapper = require('node-dbi').DBWrapper;
var db = new DBWrapper('pg', {dsn: process.env.DATBASE_URL });
View index.php
// snip ...
// Marketing site routes (www. or no subdomain)
$app->subdomain(['www', false], function($request) use($siteRoutesDir) {
'path' => BULLET_APP_ROOT . '/templates/',
'path_layouts' => BULLET_APP_ROOT . '/templates/layout/site/',
'auto_layout' => 'inner'
vlucas /
Created Jul 22, 2014
Prevent Pushes Directly to Master
# @link
# Called by "git push" after it has checked the remote status,
# but before anything has been pushed.
# If this script exits with a non-zero status nothing will be pushed.
# Steps to install, from the root directory of your repo...
You can’t perform that action at this time.