Skip to content

Instantly share code, notes, and snippets.

@mitchallen
mitchallen / gclean.sh
Created November 10, 2023 19:35
How to clean a repo
git fetch origin
git reset --hard origin/main
git clean -fxd
@mitchallen
mitchallen / artifact-registry-cloud-run-demo.sh
Created July 27, 2023 10:35 — forked from pydevops/artifact-registry-cloud-run-demo.sh
Google Cloud Platform demo of Artifact Registry deployment and Cloud Run app
#!/usr/bin/env bash
export PROJECT_ID=$(gcloud config get-value project)
export PROJECT_USER=$(gcloud config get-value core/account) # set current user
export PROJECT_NUMBER=$(gcloud projects describe $PROJECT_ID --format="value(projectNumber)")
export IDNS=${PROJECT_ID}.svc.id.goog # workflow identity domain
export GCP_REGION="us-east1" # CHANGEME (OPT)
export GCP_ZONE="us-east1-c" # CHANGEME (OPT)
export NETWORK_NAME="default"
@mitchallen
mitchallen / test.js
Created April 24, 2023 18:49
k6 starter
import http from 'k6/http';
import { sleep } from 'k6';
export default function() {
const response = http.get('https://example.com/');
console.log(response.timings.duration);
sleep(5);
}
@mitchallen
mitchallen / hello.js
Last active April 24, 2023 01:33
a very simple hello world program in JavaScript
#!/usr/bin/env node
console.log("Hello world!")
@mitchallen
mitchallen / brownian.js
Last active April 23, 2023 11:07
Example code generating a brownian motion SVG
/**
* Author: Mitch Allen (https://mitchallen.com)
* https://scriptable.com/
*/
var fs = require('fs');
function generate(limit) {
let width = 1024
@mitchallen
mitchallen / demo-main.test.js
Created April 3, 2023 02:04
An example of testing a main component
"use strict";
var assert = require('assert');
const demoMain = require('..');
describe('demo-main', function () {
context('smoke test', function () {
it('should add first two numbers and subtract the third', function (done) {
const a = 100, b = 200, c = 50;
@mitchallen
mitchallen / demo-main.js
Created April 3, 2023 02:00
An example of importing a module in the same scope
"use strict";
var tools = require('@YOUR-SCOPE/demo-tools');
module.exports = demoMain;
function demoMain(a,b,c) {
// return a + b - c
return tools.subtract(tools.add(a,b),c);
}
@mitchallen
mitchallen / demo-tools.test.js
Created April 3, 2023 01:57
Example mocha test for verifying a simple tool module
'use strict';
var assert = require('assert');
const demoTools = require('..');
describe('demo-tools', function () {
context('smoke test', function () {
it('add should add two numbers together', function (done) {
assert.strictEqual(demoTools.add(100,200),300);
@mitchallen
mitchallen / mocha-lerna-script.json
Last active April 3, 2023 02:05
Lerna test script for package.jspn
"scripts": {
"test": "mocha __tests__/*.test.js"
}
@mitchallen
mitchallen / demo-tools.js
Created April 3, 2023 01:52
Simple javascript tools demo
"use strict";
module.exports = {
add: (a,b) => a + b,
subtract: (a,b) => a - b
};