Skip to content

Instantly share code, notes, and snippets.

View marshallswain's full-sized avatar
😄

Marshall Thompson marshallswain

😄
View GitHub Profile
@marshallswain
marshallswain / gist:7129990
Created October 24, 2013 01:48
Socket.io response options
// send to current request socket client
socket.emit('message', "this is a test");
// sending to all clients, include sender
io.sockets.emit('message', "this is a test");
// sending to all clients except sender
socket.broadcast.emit('message', "this is a test");
// sending to all clients in 'game' room(channel) except sender
function md5cycle(x, k) {
var a = x[0], b = x[1], c = x[2], d = x[3];
a = ff(a, b, c, d, k[0], 7, -680876936);
d = ff(d, a, b, c, k[1], 12, -389564586);
c = ff(c, d, a, b, k[2], 17, 606105819);
b = ff(b, c, d, a, k[3], 22, -1044525330);
a = ff(a, b, c, d, k[4], 7, -176418897);
d = ff(d, a, b, c, k[5], 12, 1200080426);
c = ff(c, d, a, b, k[6], 17, -1473231341);
@marshallswain
marshallswain / 1_dpd-exposed.md
Last active January 1, 2016 03:49
A custom collection module that allows you to expose request properties to dashboard scripts by modifying the domain. In this example, I've added a headers property to the domain.

Installation

  1. Drop the dpd-exposed.js file into your node_modules directory. (You might have to create one if you installed Deployd using the dpd command line utility.)
  2. Open your Deployd dashboard and click the big green add button. You'll see the Exposed Collection type. Use it to create a collection like you would any other.

Usage

  1. Add some properties to your collection.
  2. Add some data to your collection. Remember that these scripts are run per instance on records from the database. It won't even run unless you add some data to the collection.
  3. In a dashboard script (ie. ON GET), use the headers variable directly.

console.log(headers);

@marshallswain
marshallswain / firebase.list.js
Created December 23, 2013 08:21
Firebase CanJS LIst Controller
var FirebaseListController = can.Control.extend({
defaults: {
// The main Firebase URL, including the trailing slash.
baseURL: 'https://bchm.firebaseIO.com/',
// The location of the list of data in Firebase.
location: "test_list",
// The HTML attribute that should be added to a template element in the list.
// It will need to be unique and will contain a single value, like an id, not a class.
// unused because I can't get can.Mustache to work with it right now. Keeps printing __!!__
// firebaseKeyName: "data-firebasekey",
@marshallswain
marshallswain / camelCase.js
Created December 26, 2013 02:47
camelCase a string. Originally found here: http://valschuman.blogspot.com/2012/08/javascript-camelcase-function.html?view=flipcard Thank you, Val Schuman;
Wrote a function to CamelCase a string in JavaScript. Because, AFAIK, CamelCasing applies only to programming, the function makes sure the string conforms to a legal variable name standard, removing all illegal characters, as well as making sure the string starts with a letter (not a number or an underscore.)
You can add the function to the String object prototype:
String.prototype.toCamelCase = function() {
// remove all characters that should not be in a variable name
// as well underscores an numbers from the beginning of the string
var s = this.replace(/([^a-zA-Z0-9_\- ])|^[_0-9]+/g, "").trim().toLowerCase();
// uppercase letters preceeded by a hyphen or a space
s = s.replace(/([ -]+)([a-zA-Z0-9])/g, function(a,b,c) {
@marshallswain
marshallswain / forever-start.js
Created December 29, 2013 00:55
Deployd custom start script and forever-monitor examples Install Deployd locally using npm install deployd --save. Then npm install forever-monitor --save.
var forever = require('forever-monitor');
var child = new (forever.Monitor)('server.js', {
max: 10,
silent: true,
options: []
});
child.on('exit', function () {
console.log('Your server has exited after 3 restarts');
@marshallswain
marshallswain / country-codes.json
Last active January 1, 2016 17:29
List of ISO 3166 Two-character Country Codes
[
{"code", "AF", "name", "AFGHANISTAN"},
{"code", "AX", "name", "ÅLAND ISLANDS"},
{"code", "AL", "name", "ALBANIA"},
{"code", "DZ", "name", "ALGERIA"},
{"code", "AS", "name", "AMERICAN SAMOA"},
{"code", "AD", "name", "ANDORRA"},
{"code", "AO", "name", "ANGOLA"},
{"code", "AI", "name", "ANGUILLA"},
{"code", "AQ", "name", "ANTARCTICA"},
@marshallswain
marshallswain / qtip.stache
Created January 28, 2016 18:25
qtip2 idea
https://www.npmjs.com/package/qtip2
<td qtip>content</td>
<div class="qtip">here is popover content</div>
<td qtip qtip-selector="qtip">content</td>
<td>
content
@marshallswain
marshallswain / app.js
Last active July 14, 2016 13:27
Choo todo demo with needed scripts
/* global window, document, choo, yo, extend */
// const extend = require('xtend');
var html = yo;
const app = choo();
const store = {
getAll: (storeName, cb) => {
try {
cb(JSON.parse(window.localStorage[storeName]));
} catch (e) {
@marshallswain
marshallswain / bitcentive.md
Last active November 11, 2016 18:59
Bitcentive Guide

Bitcentive

High Level Architecture

Server and Services

  • Feathers
  • feathers-mongoose
    • only used for the model validation