Skip to content

Instantly share code, notes, and snippets.

View radicalsauce's full-sized avatar

radicalsauce

  • San Francisco, CA
View GitHub Profile
@radicalsauce
radicalsauce / purple-air-notif.js
Last active August 29, 2020 19:19
Notifies me via Twilio when my local AQI slips into "unhealthy" ranges
/*
How to use:
- Set up Twilio:
You will need a Twilio account and a Twilio phone number. All in all this should run you
about $1. Details here: https://www.twilio.com/docs/sms/quickstart/node
You'll want to save your new Twilio # into your phone contacts and set to favorite so it can wake you up
if you're using DND.
- Find the sensor you want to monitor:
@radicalsauce
radicalsauce / adv_js_prompts.js
Last active April 3, 2019 17:04
JS Interview Questions
// PROMPT ONE:
var getUserComments = function(callback) {
// pretend this performs some async operation like an Ajax call
var commentCount = 50;
callback({ comments: commentCount });
};
var User = {
fullName: 'Joe Shmoe',
@radicalsauce
radicalsauce / list.js
Created October 7, 2015 00:43
JS Linked List
var makeLinkedList = function(){
var list = {};
list.head = null;
list.tail = null;
list.addToTail = function(value){
var newNode = makeNode(value);
if (!list.head) {
list.head = newNode;
}
// early experiments with node had mysterious double requests
// turned out these were for the stoopid favicon
// here's how to short-circuit those requests
// and stop seeing 404 errors in your client console
var http = require('http');
http.createServer(function (q, r) {
// control for favicon
@radicalsauce
radicalsauce / concat.js
Last active October 7, 2015 01:07
Javascript Concat()
// A recreation of the native JS string method
// Accepts as many string arguments as you can feed it, returns concatenated string
// K.R. Hale
var concat = function() {
var result = "";
for(var i = 0; i < arguments.length; i++) {
result += arguments[i];
}
return result;
@radicalsauce
radicalsauce / mergesort.js
Last active October 7, 2015 01:06
Javascript MergeSort
// A simple JS mergesort, per Wikipedia's pseudocode
// http://en.wikipedia.org/wiki/Mergesort
// by K.R. Hale
var mergeSort = function(array) {
//base case
if (array.length <= 1) return array;
//recursive case
var middle = Math.floor(array.length / 2);
@radicalsauce
radicalsauce / Guess the Number - Python
Last active August 29, 2015 14:02
Guess The Number Game (Written for Coursera's An Introduction to Interactive Programming in Python class)
# "Guess the number" mini-project
# By Kelly Hale, 3/12/14
# input will come from buttons and an input field in simplegui
# all output for the game will be printed in the console
import simplegui
import random
import math