Skip to content

Instantly share code, notes, and snippets.

View aweary's full-sized avatar
🌐
doing things and stuff

Brandon Dail aweary

🌐
doing things and stuff
View GitHub Profile
@aweary
aweary / gist:cf982bee1f9fd4576992
Created October 1, 2014 02:48
Create extend() on all objects
Object.defineProperty(Object.prototype, 'extend', {
writable: true,
enumerable: false,
configurable: true,
value: function(o){
var names = Object.getOwnPropertyNames(o);
for(var i = 0; i < names.length; i++){
if(names[i] in this) continue;
var desc = Object.getOwnPropertyDescriptor(o, names[i]);
@aweary
aweary / nodejs-in-action-3_11
Last active August 29, 2015 14:07
Node.JS in Action, example 3.11
var events = require('events');
var net = require('net');
var channel = new events.EventEmitter();
channel.clients = {};
channel.subscriptions = {};
//Add a listener for the join event that stores a user’s client object,
//allowing the application to send data back to the user.
@aweary
aweary / gist:2721832fc27e97c98fdd
Created October 5, 2014 03:10
3.11 - logging added
var events = require('events');
var net = require('net');
var channel = new events.EventEmitter();
channel.clients = {};
channel.subscriptions = {};
//Add a listener for the join event that stores a user’s client object,
//allowing the application to send data back to the user.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
<script id="jsbin-javascript">
//move to commands.js
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.14/angular.min.js"></script>
<meta charset="utf-8">
<title>JS Bin</title>
<style id="jsbin-css">
.warning {
color: tomato;
}
@aweary
aweary / SassMeister-input.scss
Created December 12, 2014 20:03
Generated by SassMeister.com.
// ----
// Sass (v3.4.7)
// Compass (v1.0.1)
// ----
$sans: sans-serif;
$serif: georgia, times;
@aweary
aweary / tobinary.js
Created January 28, 2015 23:58
Add a toBinary() method to all numbers
Number.prototype.toBinary = function(){
return parseInt(this.toString(2));
};
// > (55).toBinary()
// > 110111
@aweary
aweary / scramble.js
Created February 17, 2015 17:20
Random character formation from an input string
var scrambleWord = function(word){
var result = "";
var i = word.length;
while(i--){
result += word.charAt(Math.floor(Math.random() * word.length));
}
return result
}
@aweary
aweary / binary.js
Created June 12, 2015 01:11
binary.js
// Find the index of an element in an array using binary sorting
function binarySort(collection, target, callback, minimum, maximum) {
// Get the starting and ending points
var min = minimum || 0;
var max = maximum || collection.length;
// Get the median value and the value at that index
var median = Math.floor((min + max) / 2);
@aweary
aweary / union.js
Created June 23, 2015 05:38
weighted quick union
function WeightedQuickUnion(initCount) {
var size = this.size = [];
var parent = this.parent = [];
var count = initCount;
/* Initialize the union-find structure */
for(var i = 0; i < count; i++) {
parent[i] = i;
size[i] = 1;