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 / 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 / chaos.py
Last active January 7, 2022 22:49
Proposal for Maybe type in python (True OR False)
import ast
import random
class MaybeType(type):
def __repr__(cls):
return str(bool(random.randint(0, 1)))
def __nonzero__(cls):
return ast.literal_eval(repr(cls))
# 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):