Skip to content

Instantly share code, notes, and snippets.

@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 / numba.pip.log
Created March 20, 2013 17:58
complete pip log of failed numba install
------------------------------------------------------------
/Users/james/.virtualenvs/numbatest/bin/pip run on Wed Mar 20 12:56:47 2013
Downloading/unpacking numba
Getting page http://pypi.python.org/simple/numba
URLs to search for versions for numba:
* http://pypi.python.org/simple/numba/
Getting page http://numba.github.com
Getting page http://numba.pydata.org
Getting page https://numba.github.com
#!/usr/bin/python
# -*- coding: utf-8 -*-
from flask import Flask
from flaskext.sqlalchemy import SQLAlchemy
from werkzeug.security import generate_password_hash
from werkzeug.security import check_password_hash
from sqlalchemy.orm.exc import NoResultFound
app = Flask(__name__)
@porterjamesj
porterjamesj / trolling.el
Created July 30, 2013 18:04
Emacs Trolling — Make the buffer position a random number
(setcar mode-line-position '(:eval (number-to-string (random))))
julia> a = function(x)
x[1] = 0
end
# function
julia> x = [3,3]
2-element Int64 Array:
3
3
@porterjamesj
porterjamesj / julianagram.jl
Last active December 21, 2015 02:29
longest anagram finder in julia
function doit(f::IOStream)
wordmap = Dict{Array{Char},Array{Char}}()
best = (0,"","")
for line in eachline(f)
if length(line) > best[1]
word = collect(line)
cannonical = sort(word)
if haskey(wordmap,cannonical)
best = (length(word),word,wordmap[cannonical])
@porterjamesj
porterjamesj / venv-macros.el
Created September 17, 2013 01:57
two macros that both produce the correct result
;; needed for both
(defun venv--gen-fun (command)
`(defun ,(intern (format "pcomplete/eshell-mode/%s" command)) ()
(pcomplete-here* (venv-get-candidates))))
;; with the common lisp loop macro
(defmacro venv--make-pcompletions (commands)
`(progn ,@(loop for item in commands
collect (venv--gen-fun item))))
@porterjamesj
porterjamesj / FauxO.py
Last active December 23, 2015 05:49
fooling around with some FauxO tooling
from functools import wraps
from copy import deepcopy
def fauxothis(fn):
@wraps(fn)
def wrapper(self):
new = deepcopy(self)
fn(new)
return new
@porterjamesj
porterjamesj / heapsort.c
Created September 22, 2013 07:25
quick heapsort implementation
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
/* Heap struct (just an array and its length). */
typedef struct {
int *slots;
int len;
} heap_base_t, *heap_t;
@porterjamesj
porterjamesj / silly.s
Last active December 24, 2015 22:49
silly mips program that works as expected in spim
main:
addi $sp $sp -4 # allocate space for one thing on the stack
addi $t0 $zero 30
sw $t0 4($sp)
addi $t1 $sp 4 # put the address we want in t1
lw $t1 0($t1) # <- this works, 30 ends up in $t1
# exit syscall
li $v0 10 # system call code for exit = 10
syscall # call operating sys