Skip to content

Instantly share code, notes, and snippets.

View projectweekend's full-sized avatar

Brian Hines projectweekend

View GitHub Profile
@projectweekend
projectweekend / mock_sqs_data.py
Last active December 26, 2015 18:59
This function mocks the response the call to get messages from an Amazon SQS Queue...which is handy for testing when you don't want to make real calls to your SQS queue. The MESSAGE_BODY_TEMPLATE is simply a dictionary where the keys represent the keys in the output JSON message and the value represents a function to cast the appropriate datatyp…
from boto.sqs.jsonmessage import JSONMessage
MESSAGE_BODY_TEMPLATE = {
'article_id': int,
'owner_id': int,
'auth_token': str
}
NUMBER_OF_MESSAGES = 10
@projectweekend
projectweekend / NodeJS-CRUDSocket.js
Last active December 28, 2015 11:49
Node.js CRUD Socket - A reusable pattern I'm testing out to for a socket that handles CRUD actions against a model.
module.exports = function (socket, handleError, config) {
// set some common items we will need from config
var route = config.route;
var model = config.model;
// define the socket behavior
socket.on(route, function (data) {
switch (data.action) {
@projectweekend
projectweekend / NodeJS-ERRORSocket.js
Last active December 28, 2015 11:49
Node.js ERROR Socket - A pattern I'm exploring for communicating all socket errors back to client over a single socket.
module.exports = function (socket, config) {
var route = config.route;
var errorHandler = function (errRoute, err) {
var data = {
socket: errRoute,
error: err
};
socket.emit(route, data);
@projectweekend
projectweekend / AngularJS-ErrorHelper.js
Last active December 28, 2015 14:29
AngularJS ERROR helper service - A pattern that I am testing out to easily inject some basic error handling into controller functions.
factory('ErrorHelper', function() {
return {
errorMessage: "",
dismissError: function () {
this.errorMessage = "";
},
logToConsole: function (data) {
console.log("ERROR:");
console.log(data);
}
@projectweekend
projectweekend / NodeJS-READSocket.js
Created November 18, 2013 00:48
Node.js Read-only Socket - A reusable pattern I'm testing out to for a socket that handles read-only actions against a model.
module.exports = function (socket, handleError, config) {
// set some common items we will need from config
var route = config.route;
var model = config.model;
socket.on(route, function (data) {
switch (data.action) {
@projectweekend
projectweekend / NodeJS-SIGNUPSocket.js
Created November 18, 2013 01:50
Node.js User Signup Socket - A pattern I'm testing out to for a socket that handles user signup actions using MongooseJS and Passport.
var hat = require('hat');
module.exports = function (socket, handleError, config) {
// set some common items we will need from config
var route = config.route;
var userModel = config.model;
socket.on(route, function (data) {
@projectweekend
projectweekend / Vagrantfile
Created December 19, 2013 01:14
This is all the Vagrant config you need to run a virtual memcache server...if you're into that sort of thing. Seriously though, it can come in handy. Just drop these three files into the same directory and: vagrant up. Your memcache server will be available at: 192.168.100.101:11211. Party on.
# -*- mode: ruby -*-
# vi: set ft=ruby :
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "precise32"
config.vm.provision :shell, :path => "bootstrap.sh"
config.vm.box_url = "http://files.vagrantup.com/precise32.box"
@projectweekend
projectweekend / raspberry-pi-node-installation
Last active January 2, 2016 04:49
Steps/commands for installing Node on the Raspberry Pi
# Get the Node ARM package
wget http://nodejs.org/dist/v0.10.9/node-v0.10.9-linux-arm-pi.tar.gz
# Extract it
tar xvzf node-v0.10.9-linux-arm-pi.tar.gz
# Copy files to a permanent spot
sudo cp -r node-v0.10.9-linux-arm-pi/* /opt/node
# Add it to your PATH
@projectweekend
projectweekend / suckIt.js
Last active January 2, 2016 07:59
Since Facebook feels the need to capture stuff I do not choose to post, I'm going to have some fun with it! I don't have the time to type stuff into textareas all day, but this JavaScript snippet does. Go to your Facebook news feed, open up your browser's dev tools, paste this into console, and press enter.
var mySpecialMessage = "Suck It!";
var sendMySpecialMessage = function () {
var textareasOnPage = document.getElementsByTagName("textarea");
for (var i = 0; i < textareasOnPage.length; ++i) {
var item = textareasOnPage[i];
@projectweekend
projectweekend / RepeatOneSocket.js
Created January 15, 2014 22:18
Node.js - A reusable pattern to perform a FindOne query on a model a and emit across a Socket.IO channel on a fixed interval.
module.exports = function ( socket, handleError, config ) {
var route = config.route;
var model = config.model;
var query = config.query;
var sort = config.sort;
var interval = config.interval;
setInterval( function () {