Skip to content

Instantly share code, notes, and snippets.

View xzela's full-sized avatar
🌭
:(){ :|:& };:

Zeph LaFassett! xzela

🌭
:(){ :|:& };:
View GitHub Profile
@xzela
xzela / checkout-main.js
Created February 16, 2022 01:10
Script to checkout main based on `.meta` package
#!/usr/bin/env node
const util = require('util');
const exec = util.promisify(require('child_process').exec);
const fs = require('fs/promises');
(async () => {
try {
const metaPath = `${process.cwd()}/.meta`;
const buffer = await fs.readFile(metaPath, {encoding: 'utf8'});
@xzela
xzela / json5.js
Last active February 16, 2022 01:09
JSON5 Validator tool
#!/usr/bin/env node
const argv = require('yargs/yargs')(process.argv.slice(2))
.usage('Usage: $0 -p [str] ')
.example('$0 -p ./prod-changes/test.json5')
.alias('p', 'pattern')
.default('p', './prod-changes/config-data/**/*.json5')
.describe('p', 'Pattern (or path) of the json file(s) to validate')
.alias('x', 'exit-on-error')
.default('x', false)
@xzela
xzela / example.js
Created April 20, 2020 21:20
spread operator
const bag = {
food: 'pizza',
drink: 'pepsi',
money: 20.01,
receipt: true,
};
const { food, drink, ...whatsLeftInTheBag } = bag;
console.log(food); // 'pizza'
console.log(drink); // 'pepsi',
@xzela
xzela / basic_example.js
Last active September 23, 2019 20:07
Examples of when to use `return`, `callback`, and or `Promise`
// ***
// Best case for `return`
// ***
function isNumber(n) {
return (/^\d+$/).test(n);
}
// best solution:
// - creates on closure: function itself
@xzela
xzela / Router.md
Last active July 12, 2018 20:54
Routers

Routes in a Service

In an effort to standardize the router creation process, here's a general outline on how you should define your routes

Best Practices:

URL Anatomy:

           GET  /api /v2 /frogs /80085
Verb:_______| | | | |
@xzela
xzela / http-client.js
Created April 6, 2018 00:23
Generic axios api client
import config from './config'; // get a config somehow
import axios from 'axios';
// https://github.com/axios/axios#config-defaults
export axios.create({
baseURL: `${config.api.protocol}://${config.api.host}:${config.api.port}`,
auth: config.api.auth
});
@xzela
xzela / fields_.js
Created February 22, 2018 23:43
parsing-fields
/**
* Attempts to transmute a querystring order by value into a valid order by array
*
* Usually, the querystring value will look similar to:
* /sites/?orderBy=name,-id
*
* Which should be converted to:
* [
* {field: 'name', order: 'asc'},
* {field: 'id', order: 'desc'}
@xzela
xzela / non-unified-cache-files.js
Created July 25, 2017 23:38
proposed idea on how to structure classes/code that extends other classes/modules
// Each block is in a new file
// favorites-cache.js -- START
const ReditsClient = require('redis-client').Client;
// caching methods specific to Favorites (currently uses redis)
class FavoritesCache extends RedisClient {
constructor(conifg) {
super(config)
}
@xzela
xzela / validator-example.js
Created April 12, 2017 20:21
a hopeful dream for kink-validator
let sId = 12345; // shootId
let pId = 83726; // performerId
let error; // error placeholder
// Example #1
// default behavor
// error is returned if validation fails, `value` is actual validated value
let {error, value} = new Validator(sId).schema(require('constraints/shootId')).validate();
// check for error
if (is.error(error)) {
@xzela
xzela / home_directory_solution.md
Last active February 10, 2017 22:48
Prepending your commits with a branch name