Skip to content

Instantly share code, notes, and snippets.

// You can copy and paste this into your browser's developer console to navigate through the JSON response
function espn(path, key, callback) {
var xhr = new XMLHttpRequest();
xhr.open('GET', 'http://api.espn.com/v1' + path + '?apikey=' + key);
xhr.addEventListener('readystatechange', function() {
if (xhr.readyState === 4 && xhr.status === 200) {
callback(JSON.parse(xhr.responseText));
}
});
@1995eaton
1995eaton / http_get.c
Last active July 26, 2016 02:08
Simple HTTP GET in C
/* BUILD: gcc -lcrypto -lssl http_get.c -o http_get */
/* USAGE: ./http_get www.google.com */
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
// /r/dailyprogrammer challenge #169 (http://redd.it/29od55)
// Word list from https://dotnetperls-controls.googlecode.com/files/enable1.txt
var wordlist = require('fs').readFileSync('./dict', 'utf8').split(/\n+/)
.filter(function(e) { return e; });
console.log(challenge169(process.argv[2] || 'A oweaib who fprd not zfqzh challenges should mt ewlst to kze', wordlist));
function challenge169(string, wordlist) {
var shift = function(characters, start, end) {
for (var n = start, _ret = []; n < end; n++) {
#include <stdio.h>
#include <sys/stat.h>
int main(int argc, char *argv[]) {
if (argc == 1) {
return 0;
}
int tc = 0,
@1995eaton
1995eaton / xmlhttprequest.js
Last active February 16, 2018 04:13
node.js XMLHttpRequest
var XMLHttpRequest = function() {
var http = require('http'),
https = require('https');
var method, host, port, path, protocol,
request, xhr, callEventListeners,
statusCodes, syncFinished,
lastReadyState = 0,
listeners = ['readystatechange', 'abort', 'error', 'loadend', 'progress', 'load'],
@1995eaton
1995eaton / bitset.cpp
Last active August 29, 2015 14:03
Simple C++ bitset library
#include <iostream>
class Bitset {
private:
char *data;
size_t b_size;
public:
Bitset(size_t s) : b_size(s), data(new char[b_size + 1]) {
this->reset();
@1995eaton
1995eaton / array.cpp
Last active August 29, 2015 14:03
Array C++
#include <iostream>
#define BLOCK 2048
template <class T>
class Array {
private:
T *data;
size_t cap;
size_t max_cap;
@1995eaton
1995eaton / clock.html
Created July 28, 2014 04:12
Canvas analog clock
<!DOCTYPE html>
<html>
<head>
<title>Canvas Clock</title>
<style>
body, html {
background-color: #1b1d1e;
}
#clock {
position: absolute;
@1995eaton
1995eaton / background.js
Created July 30, 2014 21:22
A simple Chrome extension that opens random links
// A background script is needed in order to store
// persistent objects in memory. Content scripts
// run a seperate instance for each open tab in Chrome.
var nextLink = (function(linkArray) {
// Initialize a copy of the original links
var currentSet = linkArray.slice();
return function() {
@1995eaton
1995eaton / huffman.js
Created August 4, 2014 04:04
Huffman coding in JavaScript
log = console.log.bind(console);
var Heap = function(fn) {
this.fn = fn || function(e) {
return e;
};
this.items = [];
};
Heap.prototype = {