Skip to content

Instantly share code, notes, and snippets.

View justinvh's full-sized avatar
😀

Justin Bruce Van Horne justinvh

😀
  • SpaceX
  • New York, New York
  • 01:12 (UTC -05:00)
  • LinkedIn in/justinvh
View GitHub Profile
@justinvh
justinvh / rotate.py
Created April 8, 2014 04:31
fft rotate for binarized text
import sys
import numpy as np
from PIL import Image
binarized_text = sys.argv[1] if len(sys.argv) == 2 else 'text.png'
# Binarized (1-bit image)
data = np.array(Image.open(binarized_text))
Image.fromarray(np.uint8(data * 255)).show()
@justinvh
justinvh / revtree.py
Created March 7, 2014 02:11
A questionable revtree for dulwich
def revtree(self, sha=None):
# We need to first traverse the tree and construct a state that
# we can render to the end-user. This tree will be stored as a
# JSON object on the commit message
tree = {}
seen = set()
sha = sha or self.repo.head()
for walker in self.repo.get_walker(include=[sha]):
# Walk the commit and convert it into something usable
@justinvh
justinvh / urls.js
Last active August 29, 2015 13:57
Automatic JavaScript Django URL Resolver
var {{ namespace }} = {};
{{ namespace }}.urls = {{ urls }};
{{ namespace }}.resolve = function (name, kwargs) {
var path = {{ namespace }}.urls[name];
if (!path) {
throw('URL not found for view: ' + name);
}
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/uio.h>
#include <unistd.h>
#define ascii_chars 128
struct Counter {
char k;
#include <vector>
#include <iostream>
int main()
{
std::vector<std::pair<int, char>> tally(128);
for (int i = 0; i < 128; i++) {
tally[i].second = i;
}
@justinvh
justinvh / bf.py
Created January 11, 2014 03:31
stupidly simple C output bf
import sys
preamble = '#include <stdio.h>\nmain(){char a[5000]={0};char *p=a;%s;return 0;}'
cmds = {'>': '++p;', '<': '--p;', '+': '++*p;', '-': '--*p;',
'.': 'putchar(*p);', ',': '*p=getchar();', '[': 'while(*p){', ']': '}'}
print(preamble%(''.join(cmds.get(i, '') for i in sys.stdin.read())))
@justinvh
justinvh / bf-llvm.cc
Created January 11, 2014 03:15
toy bf-llvm program
#include <vector>
#include <cstdint>
#include <iostream>
#include <llvm/IR/LLVMContext.h>
#include <llvm/IR/IRBuilder.h>
#include <llvm/IR/Module.h>
#include <llvm/ExecutionEngine/GenericValue.h>
#include <llvm/ExecutionEngine/Interpreter.h>
#include <llvm/ExecutionEngine/JIT.h>
@justinvh
justinvh / django.formset.js
Last active June 4, 2018 21:30
Easier formset factories with JavaScript
/**
* Copyright 2013 Justin Bruce Van Horne <[email protected]>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@justinvh
justinvh / suffix.cpp
Last active June 7, 2020 06:46
C++11 _format suffix literal for .format() like string arguments.
#include <string>
#include <vector>
#include <sstream>
#include <exception>
namespace std {
std::string to_string(const char* value)
{
return std::string(value);
}
template <class OutputIter, class = void>
class Foo;
template <class OutputIter>
class Foo<OutputIter, is_output_iterator<OutputIter>> {
/* some class with an output iterator */
};