Skip to content

Instantly share code, notes, and snippets.

View kwo's full-sized avatar
💭
🎩🔥

Karl kwo

💭
🎩🔥
View GitHub Profile
@kwo
kwo / grn
Created June 13, 2024 08:46
go run wrapper to run a go program which is either in the current directory or in the cmd/<modulename> subdirectory
#!/bin/bash
# check if main.go file exists
if [ -f "main.go" ]; then
echo "go run ."
go run .
exit $?
fi
# check if go.mod file exists
#! /usr/bin/env node
const { exec } = require('child_process');
const fs = require('fs');
const doOutput = (z) => {
console.log(z.gitdir, z.status);
};
const doGitPull = (next) => (z) => {
exec('git pull', { cwd: z.gitdir }, (err, stdout, stderr) => {
@kwo
kwo / gist:6b41882abd2e12ad9c3d
Last active August 29, 2015 14:01
NodeJS properties test
#! /usr/bin/env node
// Method 1, using get and set literals instead of the function keyword
var time1 = {
seconds: 0,
get milliseconds() {return this.seconds * 1000;},
set milliseconds(x) {this.seconds = x / 1000;}
};
time1.milliseconds = 1750;
console.log(time1.seconds, time1.milliseconds); // outputs 1.75 1750;