Skip to content

Instantly share code, notes, and snippets.

View jamessouth's full-sized avatar
😉
World's Best Developer

james south jamessouth

😉
World's Best Developer
View GitHub Profile
@jamessouth
jamessouth / coin2.go
Created February 14, 2022 04:05
2nd coin problem solutions - OCaml and Go
// How many different ways can we make change of $1.00, given half-dollars,
// quarters, dimes, nickels, and pennies?
// -- from SICP 1.2.2
package main
import "fmt"
func coin2() int {
cnt := 0
@jamessouth
jamessouth / coin.go
Last active January 28, 2022 02:17
Coin problem solutions - OCaml and Go
// Problem: Find all integer values of X (1 <= X <= 100) that satisfy the
// following statement: It is impossible to make $1 using exactly X U.S. coins.
// Consider only coins with these denominations: 1¢, 5¢, 10¢, 25¢, 50¢, and $1.
package main
import "fmt"
type results struct {
coins int
@jamessouth
jamessouth / ddbprint.js
Created March 18, 2021 04:31
Node script to display JSON from the AWS CLI (DynamoDB) in a more readable table
const readable = process.stdin;
const chunks = [];
readable.on('readable', () => {
let chunk;
while (null !== (chunk = readable.read())) {
chunks.push(chunk);
}
});
@jamessouth
jamessouth / hashFilenames.js
Created May 2, 2020 04:49
Node script that hashes the files in a dist directory in the proper order, i.e. hashes the files that a file references before hashing the file itself
const crypto = require('crypto');
const fs = require('fs');
const path = require('path');
const walk = require('walkdir');
let tree = [];
//hash and rename a file
async function hashFile(filepath) {
const file = fs.createReadStream(filepath);
@jamessouth
jamessouth / dep-check.js
Last active May 1, 2020 20:12
Node script to search npmjs.com for packages that share one or more given packages as dependencies, i.e. what packages have x, y, and z as dependencies?
const https = require('https');
const { Transform } = require('stream');
//each package listed as depending on another is in its own <section>
const breakIntoSections = () => new Transform({
transform(ch, _, cb) {
const rows = ((this.partialRow || '') + ch.toString()).split(/<\/section>/);
this.partialRow = rows.pop();
for (const row of rows) {
this.push(`${row}\n`);
@jamessouth
jamessouth / iso2countries.js
Last active July 17, 2018 20:28
JavaScript array of 218 countries and territories with their iso2codes, in alpha order by country/territory name
const countries = [
{ code: "AF", country: "Afghanistan" },
{ code: "AL", country: "Albania" },
{ code: "DZ", country: "Algeria" },
{ code: "AS", country: "American Samoa" },
{ code: "AD", country: "Andorra" },
{ code: "AO", country: "Angola" },
{ code: "AG", country: "Antigua and Barbuda" },
{ code: "AR", country: "Argentina" },
{ code: "AM", country: "Armenia" },