Skip to content

Instantly share code, notes, and snippets.

View bakerface's full-sized avatar

Chris Baker bakerface

  • Test and Controls International
  • Taylorsville, Kentucky
View GitHub Profile
# git feature foo-bar (creates a branch called feature-foo-bar)
# ...
# git publish
git config --global alias.feature "!f() { git checkout -b feature-\$1 develop; }; f"
git config --global alias.publish-feature "!f() { LOCAL=\$(git rev-parse --abbrev-ref HEAD); FEATURE=\$(echo \$LOCAL | sed -E 's/^.{8}//'); git checkout develop && git merge \$LOCAL && git branch -d \$LOCAL && git push origin develop; }; f"
# git release 1.0.0 (creates a branch called release-v1.0.0)
# ...
# git publish
git config --global alias.release "!f() { git checkout -b release-v\$1 develop && ./bump-version \$1 && git commit -a -m \"Updated version to \\\`\$1\\\`.\"; }; f"
#!/bin/sh
ping -c 1 8.8.8.8 &> /dev/null && ping -c 1 www.google.com &> /dev/null && echo 'We are able to resolve host names to IP addresses!' || echo 'We are connected to the internet, but we are incapable of resolving host names to IP addresses!'
@bakerface
bakerface / csv-example.js
Last active August 29, 2015 14:22
Node.js CSV Example
var fs = require('fs');
var parse = require('csv-parse');
var input = fs.readFileSync('myfile.csv').toString('ascii');
// remove the 3rd line from the file
var lines = input.split('\n');
lines.splice(2, 1);
input = lines.join('\n');
parse(input, { comment: '#' }, function(err, lines) {
@bakerface
bakerface / snappy-dns-fix.sh
Last active August 29, 2015 14:27
Snappy DNS Fix
# remount the partition as read-write so we can modify the filesystem
mount -o remount,rw /
# add the default nameservers so that they are appended to resolv.conf
echo "nameserver 8.8.8.8" >> /etc/resolvconf/resolv.conf.d/base
echo "nameserver 8.8.4.4" >> /etc/resolvconf/resolv.conf.d/base
# ask the user to reboot so the changes take place and filesystem is read-only again
echo "Please reboot for the changes to take."
@bakerface
bakerface / callbacks.js
Created August 26, 2015 00:41
Node.js callbacks with `when`
var when = require('when');
var when_node = require('when/node');
// a function that sends `data`
// waits `cycles` milliseconds to simulate network delay
// calls the `callback` after `data` is sent
function send_with_callback(data, cycles, callback) {
console.log(new Date().toISOString(), 'sending data', data);
setTimeout(callback, cycles);
}
@bakerface
bakerface / random.js
Last active June 16, 2016 13:41
Create random alphanumeric UUID
function randomString(len) {
var s = '';
while (s.length < len) {
s += Math.random().toString(36).substr(2);
}
return s.substr(0, len);
}
@bakerface
bakerface / update-dns.js
Created July 1, 2016 17:19
GoDaddy DNS Update Script
#!/usr/bin/env node
const request = require('superagent');
const { domain, key, secret } = require('./godaddy.json');
function callback(resolve, reject) {
return (error, value) => {
if (error) return reject(error);
return resolve(value);
};
@bakerface
bakerface / redis-backup.sh
Last active February 9, 2024 00:37
Backup Heroku Redis Database
#!/usr/bin/env bash
REDIS_URL=$(heroku config:get REDIS_URL $@)
REDIS_USERNAME_AND_PASSWORD=$(echo $REDIS_URL | cut -d@ -f1)
REDIS_HOSTNAME_AND_PORT=$(echo $REDIS_URL | cut -d@ -f2)
REDIS_HOSTNAME=$(echo $REDIS_HOSTNAME_AND_PORT | cut -d: -f1)
REDIS_PORT=$(echo $REDIS_HOSTNAME_AND_PORT | cut -d: -f2)
REDIS_PASSWORD=$(echo $REDIS_USERNAME_AND_PASSWORD | cut -d: -f3)
# redis-dump -h $REDIS_HOSTNAME -p $REDIS_PORT -a $REDIS_PASSWORD > redis.dump
@bakerface
bakerface / babel-starter.sh
Last active April 12, 2017 17:24
Baseline package template for Node.js and Babel
#!/usr/bin/env bash
YEAR=$(date +"%Y")
NPM_VERSION=$(npm -v)
NODE_VERSION=$(node -v)
NODE_VERSION=${NODE_VERSION:1}
if [ "$GITHUB_USER" == "" ]; then
@bakerface
bakerface / redux.c
Last active March 23, 2018 12:47
A simple redux example in C
#include <stdio.h>
#include <unistd.h>
typedef enum {
INIT,
DEBUG,
INC,
INC_ASYNC,
DEC,
DEC_ASYNC