This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var express = require('express'); | |
var RedisStore = require('connect-redis')(express); | |
express.socketio = require('socket.io'); | |
var app = express.createServer(); | |
app.configure(function() { | |
app.use(express.cookieParser() ); | |
app.sessionStore = new express.session.MemoryStore(); //Not recommended for production use | |
app.use(express.session({ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env php | |
<?php | |
//Don't forget to setup credentials for the AWS API. | |
require_once('/usr/lib/aws-php-sdk-1.3.1/sdk.class.php'); | |
$ec2 = new AmazonEC2(); | |
$volumes = array( | |
'vol-xxxxxxxx' => '-- Your snapshot description here --', | |
'vol-xxxxxxxx' => '-- Your snapshot description here --', | |
'vol-xxxxxxxx' => '-- Your snapshot description here --' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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) ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var crypto = require("crypto"); | |
/* variableHash - Generate a variable-length hash of `data`. | |
Similar to the answer here: http://crypto.stackexchange.com/a/3559/4829 | |
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). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# 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?) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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"); | |
func(23); | |
which is equivalent to: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"strings" | |
) | |
// odds computes the square root by adding odd numbers together until n is | |
// reached. | |
// Cost: 4 commands per loop; O(n) loops |