Skip to content

Instantly share code, notes, and snippets.

Avatar

Clay Miller smockle

View GitHub Profile
@smockle
smockle / exclude.js
Created Sep 17, 2019
Output a regular expression which matches branch names _except_ the given name
View exclude.js
#!/usr/bin/env node
//@ts-check
const branchName = process.argv[2];
if (!branchName) {
throw new TypeError(`Expected a branch name but did not receive one.`)
}
const validCharactersRegExp = /[a-zA-Z0-9\-\_]/;
const validCharacters = [
[ "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z" ],
@smockle
smockle / index.js
Last active Jun 20, 2019
Bluebird.prototype.map with native Promises
View index.js
#!/usr/bin/env node
//@ts-check
const MAX_CONCURRENCY = 3;
function sayHiAsync() {
console.log("marco");
return new Promise((resolve) => {
console.log("polo");
setTimeout(() => {
View geoip-lite.js
#!/usr/bin/env node
// @ts-check
const geoip = require('geoip-lite');
function memoryUsageInMegabytes() {
const memoryUsageInBytes = process.memoryUsage();
const memoryUsageInMegabytes = {};
for (const key in memoryUsageInBytes) {
memoryUsageInMegabytes[key] = `${(memoryUsageInBytes[key] / 1000000).toFixed(2)}MB`;
}
@smockle
smockle / arp.js
Created Feb 5, 2019
Merge the results of `arp -a` with known device information for improved output
View arp.js
#!/usr/bin/env node
// @ts-check
const fs = require("fs");
const { spawn } = require("child_process");
const ipAddressRegExp = /\((?<ipAddress>\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\)/;
const macAddressRegExp = /(?<macAddress>[a-fA-F\d]{1,2}:[a-fA-F\d]{1,2}:[a-fA-F\d]{1,2}:[a-fA-F\d]{1,2}:[a-fA-F\d]{1,2}:[a-fA-F\d]{1,2})/;
function normalizeMACAddress(macAddress) {
return macAddress
View kelvin.md
# Set timezone
sudo timedatectl set-timezone "America/Los_Angeles"

# DNS servers
sudo vi /etc/dhcpcd.conf
# static domain_name_servers=1.1.1.1 1.0.0.1

# Install kelvin
$ mkdir -p ~/Downloads && cd $_
View homebridge.md

Homebridge

On the host

# Download latest Raspbian Stretch Lite from https://www.raspberrypi.org/downloads/raspbian/

# Insert a Micro SD card (at least 8 GB) into the host

# Install Etcher, a utility that flashes SD cards
@smockle
smockle / fizzbuzz.js
Created Sep 15, 2015
FizzBuzz, in JavaScript
View fizzbuzz.js
let array = [];
for (let i = 1; i <= 100; i++) {
let x = '';
if (i % 3 === 0) { x += 'Fizz'; }
if (i % 5 === 0) { x += 'Buzz'; }
if (x.length === 0) { x = i; }
array.push(x)
}
console.log(array.join('\n'));
@smockle
smockle / gif.sh
Last active Jul 25, 2020
Convert .mov to .gif in OS X with ffmpeg & imagemagick
View gif.sh
ffmpeg -i in.mov -vf scale=800:-1 -r 10 -f image2pipe -vcodec ppm - | convert -delay 5 -layers Optimize -loop 0 - out.gif
@smockle
smockle / osx.sh
Created Aug 24, 2015
Reset Finder, the Dock, the Open With menu and the clipboard in OS X.
View osx.sh
#!/usr/bin/env bash
killall Finder
killall Dock
/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister -kill -r -domain local -domain system -domain user
launchctl stop com.apple.pboard
launchctl start com.apple.pboard
View class.js
class Container {
constructor(x) {
this.__value = x;
}
static of(x) {
return new Container(x);
}
map(f) {