Skip to content

Instantly share code, notes, and snippets.

View cblair's full-sized avatar

Colby Blair cblair

View GitHub Profile
// WIP
// Objective: Create a Node.js script that encrypts text files within a specified directory using asynchronous programming. This script should encrypt the content of each text file using a basic Caesar Cipher for simplicity, then save the encrypted content to a new file in a different directory. The process should handle multiple files concurrently, support both encryption and decryption modes, and log the completion of each file operation.
// Requirements:
// Mode Selection: The script should accept a mode argument (encrypt or decrypt) as the first command-line argument to determine the operation mode.
// Directory Arguments: Accept two additional command-line arguments for the input directory (containing text files to process) and the output directory (where encrypted or decrypted files will be saved).
const { assert } = require("node:console");
const { argv } = require("node:process");
const { readdir, readFile } = require('node:fs/promises');
const express = require('express');
const app = express();
const port = 4000;
// Payments
// In the real world, we would use a real database like Postgres or MongoDB. Just in memory for the sake of this example.
const payments = {};
/** POST /payment - Create a payment.
@cblair
cblair / bump-version.js
Created February 22, 2019 19:07
bump package.json and package-lock.json versions
#!/usr/bin/env node
const fs = require('fs');
const bumpVersion = process.argv.length >= 3 ? process.argv[2] : undefined;
['./package.json', './package-lock.json'].forEach(fname => {
let packageJson = fs.readFileSync(fname, 'utf8');
const [full, semver] = packageJson.match('"version":[ ]*"([0-9]+\.[0-9]+\.[0-9]+)"');
let [major, minor, patch] = semver.split('.').map(version => parseInt(version));
v6.9.2
3.10.9
[email protected] /Users/colbyblair/code/communityco/svc-qa
├─┬ @communityco/[email protected]
│ └─┬ [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ └─┬ [email protected]
│ ├── [email protected]
@cblair
cblair / flatten.js
Created October 26, 2016 23:40
JS Array flatten
'use strict';
/** Function to flatten sub-arrays within an array into one big array.
* @param {Array} origArray - The array to flatten.
*
* @returns {Array} The flattened array.
*/
function flatten(origArray) {
var flattenedArray = [];
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/prototype/1/prototype.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/scriptaculous/1/scriptaculous.js"></script>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
@cblair
cblair / gen_string.py
Last active August 29, 2015 14:06
Performance experiments with python string generation
#!/usr/bin/env python2.7
import random
import numpy
def gen_random_string(range_start, range_end, str_len):
#~.145 s
return "".join(
[
"x%04x" %\