Skip to content

Instantly share code, notes, and snippets.

View chico's full-sized avatar

Chico Charlesworth chico

View GitHub Profile
@chico
chico / jack_herrington.js
Created June 6, 2022 16:42
Jack Herrington
Jack Herrington
The Blue Collar Coder 👋
github.com/jherr
youtube.com/JackHerrington
@chico
chico / wordle_color_algorithm.js
Created March 2, 2022 20:48
Wordle color algorithm
const chalk = require('chalk');
const COLOR_CORRECT_SPOT = 'green';
const COLOR_WRONG_SPOT = 'yellow';
const COLOR_NOT_ANY_SPOT = 'gray';
// From https://codereview.stackexchange.com/a/274334
function guessColor(word, guess, index) {
// correct (matched) index letter
if (guess[index] === word[index]) {
@chico
chico / joke.go
Created February 24, 2022 09:24
Joke go program to fetch & print a random Joke
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"time"
)
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
"net/http"
"time"
)
package main
// A simple program that call a Joke API and prints out the joke
import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
"net/http"
@chico
chico / choice.mjs
Created February 19, 2022 14:03
Choices in zx
#!/usr/bin/env zx
const choice = await question("How do you script? ", {
choices: ["zx 💪", "bash 😵"],
});
console.log(`Now scripting in ${choice}`);
@chico
chico / joke.mjs
Created February 19, 2022 14:00
Joke in zx
#!/usr/bin/env zx
const url = "https://sv443.net/jokeapi/v2/joke/Programming?type=single";
const res = await fetch(url);
console.log((await res.json()).joke);
@chico
chico / hello.mjs
Last active February 19, 2022 13:57
Hello zx
#!/usr/bin/env zx
console.log(`Hello ${argv.name} 👋`);
@chico
chico / hello.test.ts
Created February 14, 2022 09:04
Hello oclif test
import { expect, test } from "@oclif/test";
describe("hello", () => {
test
.stdout()
.command(["hello", "world", "--from=clidevs"])
.it("runs hello cmd", (ctx) => {
expect(ctx.stdout).to.contain("hello world from clidevs!");
});
});
@chico
chico / stub_enquirer_prompts.js
Created February 12, 2022 22:01
5 - Testing with sinon & mock-stdin
import inquirer from 'inquirer'
import sinon from 'sinon'
const stubPrompts = (results) => {
const stub = sinon.stub(inquirer, 'prompt')
for (const [index, result] of results.entries()) {
stub.onCall(index).resolves({ result })
}
return stub
}