Skip to content

Instantly share code, notes, and snippets.

View taddeimania's full-sized avatar
☄️
Hi!

Joel Taddei taddeimania

☄️
Hi!
View GitHub Profile
@taddeimania
taddeimania / views.py
Created July 21, 2015 14:55
Graph to HttpResponse - django
from django.http import HttpResponse
import matplotlib.pyplot as plt
import io
def graph_view(request):
plt.scatter([1, 2, 3, 4], [6, 10, 12, 1])
image_file = io.BytesIO()
plt.savefig(image_file, format="png")
@taddeimania
taddeimania / views.py
Last active August 29, 2015 14:25
Bokeh Graph to context object in Template
from bokeh.embed import components
from bokeh.plotting import figure
from django.shortcuts import render_to_response
def graph_view(request):
x_data, y_data = ([1, 2, 3, 4], [10, 1, 5, 3])
plot = figure()
plot.line(x_data, y_data)
script, div = components(plot)
return render_to_response("base.html", {"bokeh_script": script, "bokeh_graph": div})
@taddeimania
taddeimania / main.c
Last active October 6, 2015 19:06
Reading Home / Away team from Tecmo Super Bowl savestate in C
include<stdio.h>
int main()
{
unsigned char buffer[10000];
char home[2];
FILE *ptr;
ptr = fopen("1.nst","rb");
@taddeimania
taddeimania / async.py
Last active October 7, 2015 16:10
New Async syntax in python 3.5 example
import asyncio
class AsyncIterator:
def __init__(self, data):
self.data = data
async def __aiter__(self):
return self
@taddeimania
taddeimania / hashing.py
Created October 27, 2015 17:53
MD5 hashing
import md5
m = md5()
m = md5(b"http://joel.io")
m.hexdigest()
# >> 'c9bd9363c90e6a3a7edd3f5114bfffd2'
m.hexdigest()[:10]
# >> 'c9bd9363c9'
@taddeimania
taddeimania / euclideanDistance.js
Created October 28, 2015 20:25
Calculate the distance between two feature vectors.
function euclideanDistance(v1, v2) {
return v1.map(
(e, i) => [v1[i], v2[i]]
).map(
(a) => a.reduce(
(prev, cur) => prev - cur
)
).map(
(e) => e ** 2
).reduce(
@taddeimania
taddeimania / wat.py
Created November 14, 2015 00:52
Object + Function = Hello World!
class Number(int):
def __add__(self, fn):
return fn(self)
Number(5) + (lambda x: print("hello world"))
@taddeimania
taddeimania / butts.bs
Last active November 24, 2015 03:48
heh
10 PRINT "fart"
20 GOTO 10
@taddeimania
taddeimania / grassbackground.js
Last active December 14, 2015 16:19
More efficient way to handle map generation
BaseBackground = ig.Class.extend({
init: function () {
this.map = new MapTiles();
},
draw: function () {
if (this.map.tilesLoaded()){
this.drawMap();
}
},
drawMap: function () {
@taddeimania
taddeimania / mat_mul_fun.py
Last active December 22, 2015 02:25
__matmul__ abuse for the greater good
# __matmul__ abuse for the greater good
"""One thing that caught my eye when learning more about the new Matrix / Matrix
multiplication operator was that it itself was not batteries included.
Having the wind taken out of my sails, it dawned on me I was looking
at the missing implentation the wrong way. What we have on our hands is an
operator with an ambiguously open ended realm of opportunities.