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 / many_to_many.py
Created July 9, 2015 18:51
Many to Many description
class Genre(models.Model):
name = models.CharField(max_length=15)
class Movie(models.Model):
title = models.CharField(max_length=40)
genres = models.ManyToManyField(Genre)
@taddeimania
taddeimania / client.py
Created July 15, 2015 15:44
Python API Client
import requests
API_HOST = "http://localhost:8000/api3/"
AUTH_TOKEN = "ebea682e0ff80c453fb179b042c22d11d8e6179f"
def get_movie_list():
return [movie['title'] for movie in requests.get(API_HOST + "movie/").json()]
@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 / 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.
@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"))