Skip to content

Instantly share code, notes, and snippets.

View vlucas's full-sized avatar

Vance Lucas vlucas

View GitHub Profile
@vlucas
vlucas / encryption.js
Last active April 2, 2024 14:26
Stronger Encryption and Decryption in Node.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
vlucas / react_new.sh
Created May 5, 2016 21:47
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
vlucas / markdown-import.php
Last active May 28, 2023 00:23
Imports Markdown files in a local directory into a WordPress installation
<?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);
error_reporting(-1);
// Relative path to your wp-config.php file (to connect to the database)
require '../wp-config.php';
require './frontmatter.php'; // Parses YAML frontmatter - https://github.com/Modularr/YAML-FrontMatter
require './Parsedown.php'; // Markdown parser - https://github.com/erusev/parsedown
@vlucas
vlucas / deploy.sh
Last active February 6, 2024 22:57
Deploy a Static Site to Github Pages
#!/bin/bash
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 .
// 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 });
db.connect();
<?php
// snip ...
// Marketing site routes (www. or no subdomain)
$app->subdomain(['www', false], function($request) use($siteRoutesDir) {
Bullet\View\Template::config(array(
'path' => BULLET_APP_ROOT . '/templates/',
'path_layouts' => BULLET_APP_ROOT . '/templates/layout/site/',
'auto_layout' => 'inner'
));
@vlucas
vlucas / pre-push.sh
Created July 22, 2014 16:12
Prevent Pushes Directly to Master
#!/bin/bash
# @link https://gist.github.com/mattscilipoti/8424018
#
# 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...
@vlucas
vlucas / gh_label_setup.sh
Last active February 20, 2017 22:42
Setup New Github Project with System Labels
#!/bin/bash
echo -n "GitHub Repo (e.g. foo/bar): "
read REPO
echo -n "GitHub Access Token: "
read ACCESS_TOKEN
echo ""
@vlucas
vlucas / forms.js
Last active December 30, 2015 09:29
// "Constants"
exports.STYLE_HINT = 'hint';
exports.STYLE_LABEL = 'label';
exports.TYPE_DATE = 'date';
exports.TYPE_DATETIME = 'datetime';
exports.TYPE_EMAIL = 'email';
exports.TYPE_URL = 'url';
exports.TYPE_NUMBER = 'number';
exports.TYPE_PASSWORD = 'password';
@vlucas
vlucas / a-comments.md
Last active May 9, 2017 12:34
Titanium File Upload Differences on Android vs. iPhone

Purpose

The purpose of this gist is to point out that iPhone and Android HTTPClient handle HTTP requests differently when combining file uploads with other form data, for example uploading a photo along with a title or message.

iOS / iPhone

The iOS implementation, as usual, is correct and handles this situation perfectly and as expected.

Android