Skip to content

Instantly share code, notes, and snippets.

View mattneary's full-sized avatar

Matt Neary mattneary

View GitHub Profile
@mattneary
mattneary / index.js
Created October 4, 2012 00:52
Y Combinator
Y = function(f) {
var f_xx = function(x) {
return f(function(v) { return x(x)(v); });
};
return f_xx(f_xx);
};
var factorial = Y(function(self) {
return function(n) {
return n == 0 ? 1 : n*self(n - 1);
};
@mattneary
mattneary / index.js
Created October 29, 2012 23:35
Picture Voting
var http = require('http');
process.on("uncaughtException", function(){vote();});
var count = 0;
var vote = function() {
var fetched = false;
var poster = [];
var data = {
"recaptcha_challenge_field": "03AHJ_Vuu9MDRN0efmOk0w1eyknSbmFJMf2kM3fMCyoR4aX319zjel6Q4YKFIBs9wqXa0zqy8kx8E6DG1dTGRiGAhF3Pe67Zdlnp8mGkTYEPFQTYg9pBYswsnC693eG4oVv9L_4aSUFjbMmaThaETlDMq-S-TlK0Pca7jCsLLivus6ZDFijVxGTSg",
@mattneary
mattneary / index.js
Created November 24, 2012 03:48
Node.js Telnet Chat
// To Access Once Running: `telnet localhost 8124`
var net = require('net');
var users = [];
var red = '\033[31m'; // command line colors
var reset = '\033[0m';
var server = net.createServer(function(c) {
// handle new connection
c.on('end', function() {
console.log("end");
@mattneary
mattneary / index.js
Created December 6, 2012 03:31
Fetch Jeopardy Titles
var http = require('http'),
fs = require('fs');
var fetchShow = function(code) {
http.get({
host: "www.j-archive.com",
port: 80,
path: "/showgame.php?game_id="+code
}, function(response) {
var buffer = [];
@mattneary
mattneary / index.js
Created December 7, 2012 01:56
Node.js App Router
var app = require('route');
app.get({
path: /\/api\//,
cb: function(req, res) {
res.end(JSON.stringify({success: true}));
}
}, {
path: /\/home\//,
cb: function(req, res) {
@mattneary
mattneary / index.html
Created December 11, 2012 00:33
Simple JS Chat displaying Prototypes
<!-- Socket.io Library Include -->
<script src="https://raw.github.com/LearnBoost/socket.io-client/master/dist/socket.io.min.js"></script>
<!-- Page Structure -->
<ol id="messages"></ol>
<input type="text" id="message">
<input type="button" id="send" value="Send">
<!-- Styling -->
<style>
.msg_to, .msg_from {
list-style: none;
@mattneary
mattneary / index.js
Created December 18, 2012 00:08 — forked from anonymous/index.js
var Queue = function(parts) {
var index = 0;
this.read = function() {
var part = parts[index];
index++;
return part;
};
this.next = function() {
var thiz = this;
@mattneary
mattneary / index.js
Created January 8, 2013 02:02
Wavelength-To-RGB
var color = function(wavelength) {
var bounds = [380, 440, 490, 510, 580, 645, 780];
var pairs = ["BR", "BG", "GB", "GR", "RG", "R"]
var colorGen = function(combo, borders, wl) {
var RGB = {R:0,G:0,B:0};
RGB[combo[0]] = 255;
RGB[combo[1]] = 255 * (borders[1] - wl)/(borders[1] - borders[0]);
return RGB;
};
var residuals = bounds.map(function(bound){return bound-wavelength}).map(Math.abs);
@mattneary
mattneary / main.c
Created January 10, 2013 22:29
Robot-C
#pragma config(Sensor, S1, IR, sensorI2CCustom)
//#pragma config(Motor, mtr_S1_C1_1, motorD, tmotorNormal, openLoop)
//#pragma config(Motor, mtr_S1_C1_2, motorE, tmotorNormal, openLoop, reversed)
/*
TO-DO
- find real value of timeEnd
- find motor strengths
- find left and right motors
*/
@mattneary
mattneary / prime.hs
Last active December 11, 2015 06:39
Haskell Array-based isPrime
module Main where
grid range = [[i,j] | i <- range, j <- range] -- construct grid of number pairs
multiplicationTable grid = map (\l -> foldl (*) 1 l) grid -- multiply said pairs
isPrime number = not $ any (==number) $ (multiplicationTable . grid) [2 .. number] -- check for presence in table
main = print $ map (\p -> (fst p, (isPrime . fst) p)) [(i, b) | i <- [1 .. 100], b <- [True]] -- map all numbers to primeness