Skip to content

Instantly share code, notes, and snippets.

We couldn’t find that file to show.
var system = require('system');
var fs = require("fs");
function scroller(eofSelector, cb, wait) {
var done = page.evaluate(function (s) {
return document.querySelector(s);
}, eofSelector);
if(done === null) {
page.evaluate(function() {
window.scroll(0, document.body.scrollHeight);
@porterjamesj
porterjamesj / shell.py
Last active September 14, 2016 21:43
Tiny shell written for a workshop at Recurse Center.
"""
Small description:
What it does:
1. first this
2. then this
"""
import sys
import os
@porterjamesj
porterjamesj / app.py
Last active August 29, 2015 14:20
flask request close insanity
import time
from flask import Flask, Response, current_app
class Stream(object):
def __init__(self, string):
self.bytes = 0
self.string = string
@porterjamesj
porterjamesj / hello_mesos.py
Last active March 6, 2018 20:43
the tiniest mesos scheduler
import logging
import uuid
import time
from mesos.interface import Scheduler
from mesos.native import MesosSchedulerDriver
from mesos.interface import mesos_pb2
logging.basicConfig(level=logging.INFO)
@porterjamesj
porterjamesj / echo.py
Last active August 29, 2015 14:08
tiny echo server with asyncio
import asyncio
@asyncio.coroutine
def server_callback(reader, writer):
while True:
data = yield from reader.readline()
yield from asyncio.sleep(1)
writer.write(data)
yield from writer.drain()
@porterjamesj
porterjamesj / async.jl
Created October 28, 2014 17:34
demonstration that Julia task-switching happens only when a task has to wait on IO
function do_computation_then_print(message::String)
sum = 1
for i = 1:(rand() * 10^7)
sum *= i
end
# print out the sum so the compiler doesn't elide the loop
print("$message: $sum\n")
end
@porterjamesj
porterjamesj / first_try.jl
Last active August 29, 2015 14:02
BinDeps :(
using BinDeps
@BinDeps.setup
gumbo = library_dependency("libgumbo")
provides(Sources,
URI("https://github.com/google/gumbo-parser/archive/master.zip"),
gumbo,
unpacked_dir="gumbo-parser-master")
@porterjamesj
porterjamesj / balanced.py
Created June 11, 2014 03:00
fun exercise from programming praxis
def balanced(s):
raise NotImplementedError("Implement me!")
def test():
for s in ["{}", "[]", "()", "a(b)c", "abc[d]", "a(b)c{d[e]}"]:
assert balanced(s)
for s in ["{]", "(]", "a(b]c", "abc[d}", "a(b)c{d[e}"]:
assert not balanced(s)
@porterjamesj
porterjamesj / gumbo_example.c
Created May 3, 2014 01:52
just a small example of using google's gumbo for html parsing
#include <stdio.h>
#include "gumbo.h"
int main() {
GumboOutput* output = gumbo_parse("<h1>Hello, World!</h1>");
// Gumbo inserts all the html, body, etc.
GumboNode *html = output->root;
GumboNode *body = (GumboNode *) html->v.element.children.data[1];
GumboNode *header = (GumboNode *) body->v.element.children.data[0];
GumboNode *text = (GumboNode *) header->v.element.children.data[0];