Skip to content

Instantly share code, notes, and snippets.

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

Vance Lucas vlucas

It's either a binary trap, or it's not.
View GitHub Profile
View SheetQuery-InserRows.js
sheetQuery()
.from('Transactions')
.insertRows([
{
Amount: -554.23,
Name: 'BigBox, inc.'
},
{
Amount: -29.74,
Name: 'Fast-n-greasy Food Spot'
View SheetQuery-DeleteRows.js
// Delete specific matching rows
sheetQuery()
.from('Transactions')
.where(row => row.Category === 'DELETEME')
.deleteRows();
@vlucas
vlucas / sheetquery-updaterows.js
Last active Apr 9, 2021
SheetQuery-UpdateRows
View sheetquery-updaterows.js
// Update rows with criteria
sheetQuery()
.from('Transactions')
.where(row => row.Business.toLowerCase().includes('starbucks'))
.updateRows(row => {
row.Category = 'Coffee Shops'
});
@vlucas
vlucas / SheetQuery-getRows.js
Last active Apr 9, 2021
SheetQuery-getRows
View SheetQuery-getRows.js
const query = sheetQuery()
.from('Transactions')
.where(row => row.Category === 'Shops');
const data = query.getRows(); // Array of objects, i.e. [ { Name: "Somestore", Amount: 45.29, Category: "Shops" } ]
@vlucas
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 = _.rest(arguments);
let translation = translations[key];
if (translation && replacements.length) {
translation = format.apply(null, [translation].concat(replacements));
}
@vlucas
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
vlucas / encryption.js
Last active Jul 28, 2021
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
vlucas / react_new.sh
Created May 5, 2016
Shell function to setup a new React.js project
View react_new.sh
# 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 Apr 21, 2021
Imports Markdown files in a local directory into a WordPress installation
View markdown-import.php
<?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