Skip to content

Instantly share code, notes, and snippets.

bminer / ebs-backup.php
Created Mar 8, 2012
Simple PHP script to backup EC2 EBS volumes. Nice to include as a daily Cron job.
View ebs-backup.php
#! /usr/bin/env php
//Don't forget to setup credentials for the AWS API.
$ec2 = new AmazonEC2();
$volumes = array(
'vol-xxxxxxxx' => '-- Your snapshot description here --',
'vol-xxxxxxxx' => '-- Your snapshot description here --',
'vol-xxxxxxxx' => '-- Your snapshot description here --'
bminer / exportDatabaseToCSV.php
Created Jun 20, 2012
Quick code to export an entire database schema to RFC4180-compliant CSV files and wrap them in a Gzip-compressed tarball.
View exportDatabaseToCSV.php
/* exportDatabaseToCSV
Author: Blake C. Miner
$db - must be a PDO connection
$database - string, the name of the schema to be backed up
$filename - string, the name of the *.tar file to be generated
function exportDatabaseToCSV($db, $database, $filename) {
//Delete files
if(file_exists($filename) )
bminer / variableHash.js
Created Jan 23, 2013
Generate a variable-length hash of `data` in Node.js
View variableHash.js
var crypto = require("crypto");
/* variableHash - Generate a variable-length hash of `data`.
Similar to the answer here:
If you want a b-bit hash of the message m, then use the first b bits of AES-CTR(SHA256(m)).
Rather than using the suggested algorithm in the stackexchange answer above, I developed
my own.
I decided to derive AES256 initialization vector and key from the output of SHA256(data).
bminer / changeTypeAttr.js
Created Aug 31, 2012
Cross-browser solution for changing the 'type' attribute of an `<input/>` tag.
View changeTypeAttr.js
/* x is the <input/> element
type is the type you want to change it to.
jQuery is required and assumed to be the "$" variable */
function changeType(x, type) {
if(x.prop('type') == type)
return x; //That was easy.
try {
return x.prop('type', type); //Stupid IE security will not allow this
} catch(e) {
//Try re-creating the element (yep... this sucks)
bminer / reactHandlerUtils.js
Last active Oct 11, 2018
Utility to make React `onChange` event handlers more enjoyable to write
View reactHandlerUtils.js
/* Returns a function `(value, merge) => {...}` that calls
`component.setState(...)` to update the component's state with the new value
for `key`.
A simple example:
const func = updateKey(component, "counter");
which is equivalent to:
View isqrt.go
package main
import (
// odds computes the square root by adding odd numbers together until n is
// reached.
// Cost: 4 commands per loop; O(n) loops
bminer /
Created Sep 13, 2011
Accessing/Manipulating Session Data in Socket.IO (Express + Sessions + Socket.IO)
var express = require('express');
var RedisStore = require('connect-redis')(express);
express.socketio = require('');
var app = express.createServer();
app.configure(function() {
app.use(express.cookieParser() );
app.sessionStore = new express.session.MemoryStore(); //Not recommended for production use
bminer /
Created May 21, 2018
Python Script for Raspberry Pi + HC-SR04 sensor to measure water level in a sump pit
# Measure distance to water level in sump pit using
# HC-SR04 ultrasonic ranging module
# Sensor info:
# 2cm - 4m. range with ~3mm. accuracy, 15 degree measuring angle
# 5VDC, 15mA working current
# Suggestion in spec to connect ground before 5VDC line when hot plugging
# Measure surface area no less than 0.5 m^2 (really?)