Skip to content

Instantly share code, notes, and snippets.

@chazcheadle
chazcheadle / nvm_test.sh
Created September 8, 2016 20:29
nvm_test.sh
#!/bin/bash
if command -v nvm 1&>2 >/dev/null; then
if [ -f "$HOME/.nvmrc" ]; then
nvm use
echo -n "Using Node: `nvm current`"
else
echo -n "nvm installed but .nvmrc not found."
fi
else
echo -n "nvm not installed"
@chazcheadle
chazcheadle / getUserRepositories.go
Created September 15, 2016 03:58
Golang go-github example to list a user's public repositories
package main
import (
"fmt"
"github.com/google/go-github/github"
)
func main() {
@chazcheadle
chazcheadle / jenkins.vcl
Created October 3, 2016 19:24
Jenkins redirect in Varnish 4
# Jenkins
# This will allow you to run Jenkins as <HOST>/jenkins.
# Varnish 4 declaration
vcl 4.0;
# Backend is using the default Jenkins port.
backend jenkins {
.host = "127.0.0.1";
.port = "8080";
@chazcheadle
chazcheadle / Dockerfile_node-v4.4.4
Created October 5, 2016 04:24
Build a Node 4.4.4 factory for Docker
# Create a factory container that can run a specific version of NodeJS/npm/grunt/bower/gulp
FROM centos:7
# Install any required system programs. In this case, 'wget' is is required for fetching the binaries.
RUN yum install -y wget
# Download specific version of NodeJS and install it on the system..
RUN cd /opt; mkdir node-4.4.4; wget http://nodejs.org/dist/v4.4.4/node-v4.4.4-linux-x64.tar.gz; \
tar zxvf node-v4.4.4-linux-x64.tar.gz --strip-components=1 -C ./node-4.4.4; rm -f node-v4.4.4-linux-x64.tar.gz; \
ln -s /opt/node-4.4.4/bin/node /usr/local/bin/node; \
@chazcheadle
chazcheadle / workdir.sh
Created October 5, 2016 14:23
Bash: Get final path element in working directory
#!/bin/bash
# ex> '/home/on/the/range' will return 'range'
WORKDIR=${PWD##*/}
echo $WORKDIR
@chazcheadle
chazcheadle / config.go
Created June 7, 2017 04:32
Golang Viper config read into struct
package main
import (
"fmt"
"github.com/spf13/viper"
)
// Create private data struct to hold config options.
type config struct {
@chazcheadle
chazcheadle / power-use-aggregrator.py
Last active August 31, 2017 04:42
Electric Power Meter Service written in Python with Adafruit.io logging
#!/usr/bin/env python3
## Download your adafruit.io json data and load it.
## UTC_HOURS_OFFSET - Set to match your local offset.
import pandas as pd
import matplotlib.pyplot as plt
df = pd.read_json(ADAFRUITIO_JSON_DATAFILE)
# Change index to be usable by TimeGrouper().
@chazcheadle
chazcheadle / esp8266-mqtt-bme280-MCP9808.ino
Created March 16, 2018 05:42
Adafruit Feather Huzzah, MQTT, BME280/MCP9808, Wifimanager
#include <FS.h> //this needs to be first, or it all crashes and burns...
#include <Wire.h>
#include <ESP8266WiFi.h> //https://github.com/esp8266/Arduino
#include <DNSServer.h>
#include <ESP8266WebServer.h>
#include <WiFiManager.h> //https://github.com/tzapu/WiFiManager
#include <ArduinoJson.h> //https://github.com/bblanchon/ArduinoJson
// MQTT Library
#include <PubSubClient.h>
FROM ubuntu:xenial
RUN apt-get update
RUN apt-get install -y software-properties-common vim
RUN apt-get update
RUN apt-get install -y build-essential
RUN apt-get install -y git
RUN apt-get update -y
@chazcheadle
chazcheadle / Multiple Queries
Last active November 5, 2019 06:58
Python Database Snippets
import concurrent.futures
import time
import psycopg2
import getpass
password = getpass.getpass(prompt='Password')
start = time.perf_counter()
def do_something(letter):