Skip to content

Instantly share code, notes, and snippets.

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

Joel Taddei taddeimania

☄️
Hi!
View GitHub Profile
# aside from the dict being vulnerable to overwrite what benefit does the @property give
# over the dict on the instance in this particular use case?
class MyClass(object):
@property
def my_attribute(self):
return {
'key': 'value'
}
>>> print "{}"
{}
>>> print {}
{}
# C'MON!
>>> print ['{}']
['{}']
>>> print [{}]
[{}]
>>> print type('{}')
@taddeimania
taddeimania / query_question.sql
Last active August 29, 2015 14:15
Why for the other fast?
select mt.id from massive_table mt
where not exists
(select id from big_table bt where bt.massive_table_id=mt.id);
select mt.id from massive_table mt
left join big_table bt on bt.massive_table_id = mt.id
where bt.massive_table_id is null;
-- The left join query appears to return results 100x faster.
@taddeimania
taddeimania / magic.hy
Last active August 29, 2015 14:16
Accessing magic methods in Hy
(defclass Person []
[[name "joel"]])
(setv me (Person))
(print me.__class__)
(print "primitive".__class__)
;;from hy.core.language import name
@taddeimania
taddeimania / response_parse.hy
Last active August 29, 2015 14:17
Hy throwing error parsing response.
;; response_parse.py
;; import requests
;; response = requests.get("https://asciinema.org/api/asciicasts/17675").content
;; print response.index("click")
;; >>> 9949
;; hy_response_parse.hy
(import requests)
@taddeimania
taddeimania / scraper.hy
Last active August 29, 2015 14:17
Not really a scraper, just a complicated replacer
(import requests)
(defn replacer []
(setv content
(. (requests.get "https://asciinema.org/api/asciicasts/17675" ) text))
(setv replaced-content (.replace content "/assets" "https://asciinema.org/assets"))
replaced-content)
(replacer)
@taddeimania
taddeimania / bikeRaceOOP.js
Last active August 29, 2015 14:22
Bike Race OOP JS
var Bike = (function () {
var _bike;
_bike = function(opts) {
this.name = opts.name;
this.topSpeed = opts.topSpeed;
this.location = 0;
this.speed = 0;
};
import random
class Bike:
speed = 0
moving = False
location = 0
top_speed = 14
name = ""
def __init__(self, name="Unknown Racer", top_speed=14):
@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()]