Skip to content

Instantly share code, notes, and snippets.

@t00n
t00n / lru_cache_by_minute.py
Last active August 8, 2018 11:48
LRU cache that invalidates every minute
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 March 5, 2018 20:05
Small module to add the curry() decorator from pymonad on every function of every subsequent import
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 December 24, 2017 20:11
Small function to iterative over a time range
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 November 17, 2017 19:50
Modify JS function prototype to call functions with an object of arguments (similar to f(**dict) in Python)
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) {
@t00n
t00n / My WoW macros
Last active September 28, 2017 11:41
--- 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 ---