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 May 8, 2024 06:55
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 / 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 / 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 .
@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 / domEl.ts
Last active May 8, 2023 20:28
Shortcut function to create a return a DOM element. Handles children, CSS via `style` attribute, and `text` and `html` attributes also
/**
* Shortcut function to create and return a DOM element
*/
function domEl(tag: string, attributes: { [key: string]: any } = {}, children: any[] = []) {
const el = document.createElement(tag);
for (const attr in attributes) {
if (attr === 'text') {
el.appendChild(document.createTextNode(attributes[attr]));
continue;
@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 / login.tsx
Created June 8, 2022 18:53
Next.js Login Page (POSTs back to itself and handles everything)
import { GetServerSidePropsContext } from 'next';
import React from 'react';
import AuthLayout from 'src/layouts/AuthLayout';
import AlertErrors from 'src/components/AlertErrors';
import { addRequestBody } from 'src/server/bodyParser';
import { userLogin, userSessionInsert } from 'src/server/queries';
import { redirectUserToApp, setUserAuthCookie } from 'src/server/auth';
import Link from 'next/link';
// Types
@vlucas
vlucas / ApiForm.tsx
Created May 10, 2022 20:50
ApiForm React Component for native <form> onSubmit support
import type { FormEvent } from 'react';
export type onFormSubmit = (e: FormEvent, data: { [key: string]: any}) => void
export type ApiFormProps = {
children: any,
onSubmit: onFormSubmit,
[key: string]: any, // Allows any other props to be passed through to element
}
/**
@vlucas
vlucas / gist:1802688
Created February 11, 2012 17:22
Mac OS X Architecture Flags
# x386 Architecture
export CFLAGS="-arch i386 $CFLAGS"
export CCFLAGS="-arch i386 $CCFLAGS"
export CXXFLAGS="-arch i386 $CXXFLAGS"
export LDFLAGS="-arch i386 $LDFLAGS"
# x64 Architecture
export CFLAGS="-arch x86_64 $CFLAGS"
export CCFLAGS="-arch x86_64 $CCFLAGS"
export CXXFLAGS="-arch x86_64 $CXXFLAGS"
@vlucas
vlucas / SheetQuery-InserRows.js
Created April 14, 2021 15:21
SheetQuery-InsertRows
sheetQuery()
.from('Transactions')
.insertRows([
{
Amount: -554.23,
Name: 'BigBox, inc.'
},
{
Amount: -29.74,
Name: 'Fast-n-greasy Food Spot'