Skip to content

Instantly share code, notes, and snippets.

🔛

James J Porter porterjamesj

🔛
Block or report user

Report or block porterjamesj

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
We couldn’t find that file to show.
View soundcloud-dl.js
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 Sep 14, 2016
Tiny shell written for a workshop at Recurse Center.
View shell.py
"""
Small description:
What it does:
1. first this
2. then this
"""
import sys
import os
@porterjamesj
porterjamesj / app.py
Last active Aug 29, 2015
flask request close insanity
View app.py
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 Mar 6, 2018
the tiniest mesos scheduler
View hello_mesos.py
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 Aug 29, 2015
tiny echo server with asyncio
View echo.py
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 Oct 28, 2014
demonstration that Julia task-switching happens only when a task has to wait on IO
View async.jl
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
View first_try.jl
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 Jun 11, 2014
fun exercise from programming praxis
View balanced.py
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
just a small example of using google's gumbo for html parsing
View gumbo_example.c
#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];
You can’t perform that action at this time.