Skip to content

Instantly share code, notes, and snippets.

Toon t00n

Block or report user

Report or block t00n

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@t00n
t00n / lru_cache_by_minute.py
Last active Aug 8, 2018
LRU cache that invalidates every minute
View lru_cache_by_minute.py
from functools import lru_cache, wraps
from datetime import datetime
def lru_cache_by_minute(size):
""" Decorator that caches the result of `f` during the current minute """
def real_decorator(f):
# create a cached function that wraps f but adds a minute argument
# the size is the number of entries in the cache
@t00n
t00n / yolo.py
Created Mar 5, 2018
Small module to add the curry() decorator from pymonad on every function of every subsequent import
View yolo.py
import builtins
from inspect import getmembers, isfunction
from pymonad import curry
old_imp = builtins.__import__
def currify(mod):
for name, val in getmembers(mod):
@t00n
t00n / trange.py
Created Dec 24, 2017
Small function to iterative over a time range
View trange.py
from datetime import datetime
from time import sleep
def trange(start=None, end=None, interval=1):
now = datetime.now().timestamp()
if start is None:
start = now
else:
start = start.timestamp()
@t00n
t00n / gist:57a4c351ec1beac9a42f9446513ed420
Created Nov 17, 2017
Modify JS function prototype to call functions with an object of arguments (similar to f(**dict) in Python)
View gist:57a4c351ec1beac9a42f9446513ed420
function function_params(func) {
if (typeof(func) == "function") {
let source_code = func.toString()
let regex_paren = new RegExp("\\((.*)\\)")
let args_str = regex_paren.exec(source_code)
return args_str[1].split(",").map((x) => x.trim())
}
}
Function.prototype.applyObj = function (obj) {
View My WoW macros
--- sends a message on several channels at once ---
--- channels can be either a name or a number ---
/script m,cs="what you want to send",{"1","world","LookingForGroup"};
/script for _,c in ipairs(cs) do i,n=GetChannelName(c);SendChatMessage(m,"CHANNEL",nil,i);end
--- toggles join/leave a channel ---
/script c="channel_name";i,n=GetChannelName(c);if i==0 then JoinChannelByName(c);ChatFrame_AddChannel(ChatFrame1,c);else LeaveChannelByName(c);end
--- swaps weapons with first 2 slots of last bag, works with 2H,1H+shield, not tested with 2 weapons ---
You can’t perform that action at this time.