This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Genre(models.Model): | |
name = models.CharField(max_length=15) | |
class Movie(models.Model): | |
title = models.CharField(max_length=40) | |
genres = models.ManyToManyField(Genre) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()] | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# __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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
include<stdio.h> | |
int main() | |
{ | |
unsigned char buffer[10000]; | |
char home[2]; | |
FILE *ptr; | |
ptr = fopen("1.nst","rb"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import asyncio | |
class AsyncIterator: | |
def __init__(self, data): | |
self.data = data | |
async def __aiter__(self): | |
return self |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import md5 | |
m = md5() | |
m = md5(b"http://joel.io") | |
m.hexdigest() | |
# >> 'c9bd9363c90e6a3a7edd3f5114bfffd2' | |
m.hexdigest()[:10] | |
# >> 'c9bd9363c9' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Number(int): | |
def __add__(self, fn): | |
return fn(self) | |
Number(5) + (lambda x: print("hello world")) |