Skip to content

Instantly share code, notes, and snippets.

View bradorego's full-sized avatar

Brad Orego bradorego

View GitHub Profile
@bradorego
bradorego / nyc-zip.js
Last active May 19, 2018 04:40
NYC Zip Codes (JavaScript)
/// from https://www.health.ny.gov/statistics/cancer/registry/appendix/neighborhoods.htm
// fancypants class version
class ZipCode {
constructor(label, code) {
this.label = label;
this.code = code;
}
}
let zipCodes = {
var uploadVideo = function (file, title, description) {
var d = $q.defer();
youtube.videos.insert({
part: 'snippet,status',
resource: {
snippet: {
title: title,
description: description
},
status: {
@bradorego
bradorego / classname.js
Last active April 12, 2016 20:27
Add, Remove, Toggle classname for an element in Vanilla Javascript
Element.prototype.hasClass = function (name) {
var classes = this.className.split(" "),
hasClass = false;
for (var i = 0; i < classes.length; i++) {
if (classes[i] === name) {
return true;
}
}
return false;
};
# Written by Brad Orego, Dijkstra's implementation adapted from http://rosettacode.org/wiki/Dijkstra%27s_algorithm#Ruby
# Ruby implementation of Dijkstra's algorithm intended to be run in Sonic Pi
# Define a graph with random arc weights, traverse the graph, playing a note for each node, then at the end, play the shortest path
# Repeat for 30 seconds, then stop after that run finishes
Vertex = Struct.new(:name, :neighbours, :dist, :prev)
def init_graph(graph)
@vertices = Hash.new{|h,k| h[k]=Vertex.new(k,[],Float::INFINITY)}
@edges = {}
graph.each do |(v1, v2, dist)|
@vertices[v1].neighbours << v2
# Coded by Sam Aaron, modified by Brad Orego
use_debug false
load_sample :bd_fat
8.times do
sample :bd_fat, amp: (line 0.5, 5, steps: 8).tick
sleep 0.5
end
live_loop :drums do
# A small snippet in Sonic Pi that lets you randomly select functions
# from an array, then remove them, and stops the loop when you run
# out of functions.
#
# The purpose being you can define the sections of your song/composition
# as functions, and then let rPI randomly select the order in which those
# sections happen.
#
# This is part of an exploration for a dance piece I will be choreographing
# for Kanopy Dance Company's April 2016 show.
@bradorego
bradorego / gist:8012976
Created December 17, 2013 21:35
setting cookies in vertx
if (pg_android) {
var exdate = new Date();
exdate.setDate(exdate.getDate() + 365);
/// I tried it on the request, too, but it got weird...
// req.headers().set("Cookie", headers.getAll('Cookie').toString() + ";pg_android=1; path=/; expires=" + exdate.toUTCString());
req.response.putHeader("Cookie", "pg_android=1; path=/; expires=" + exdate.toUTCString());
}
function sendAJAX(url, method, callback, data, headers) {
var xhReq = new XMLHttpRequest();
if (method !== "POST" && method !== "GET" && method !== "PUT" && method !== "DELETE") {
return false;
}
xhReq.open(method, url);
if (typeof(headers) != "undefined") {
for (var i = 0; i < headers.headers.length; i++) {
xhReq.setRequestHeader(headers.headers[i].type, headers.headers[i].value);
}
var vertx = require('vertx'),
console = require('vertx/console'),
client = vertx.createHttpClient().host('google.com'),
rm = new vertx.RouteMatcher();
rm.get('/', function(req) {
console.log("rm1");
req.bodyHandler(function (body) {
console.log("rm2");
req.response.end("Hello, World");
});
@bradorego
bradorego / gist:6553412
Created September 13, 2013 17:15
JS for calendar
if (windowPathname.indexOf("/upcoming") > -1) {
var $calRadios = document.getElementsByTagName('input'),
$lastActive = document.getElementsByClassName('active')[0],
$calList = document.getElementById('planIdeaList'),
$couldDoIndicator = document.getElementById('indicator'),
$couldDo = document.getElementById('couldDo')
$couldDoWrap = document.getElementById('couldDoWrap');
addActionButtonListeners(document.getElementsByClassName('actionButton'));
if ($couldDoWrap) {
$couldDoWrap.addEventListener(touchEvent, function (e) {