Skip to content

Instantly share code, notes, and snippets.

Daniel Hilst dhilst

Block or report user

Report or block dhilst

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
View gist:2e6f02f4a0eff26581f1a6919330ae35
>>> from dis import dis
>>> dis('"foo" in {"bar", "tar"}')
1 0 LOAD_CONST 0 ('foo')
2 LOAD_CONST 1 (frozenset({'bar', 'tar'}))
4 COMPARE_OP 6 (in)
>>> dis('"foo" == "bar" or "foo" == "tar"')
1 0 LOAD_CONST 0 ('foo')
2 LOAD_CONST 1 ('bar')
4 COMPARE_OP 2 (==)
dhilst /
Created Jun 17, 2019
Functional fun with python types
from typing import *
from typing_extensions import Protocol
# Type Generics
A = TypeVar('A')
B = TypeVar('B')
C = TypeVar('C')
A_co = TypeVar('A_co', covariant=True)
class Box:
dhilst / index.html
Created Apr 13, 2019
online photo filtering
View index.html
<!DOCTYPE html>
<meta charset="utf-8">
<meta name="author" content="">
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src=""></script>
dhilst /
Last active Apr 7, 2019
Delegate methods in python
def delegate(to, *methods):
Class decorator to delegate methods to another objects.
>>> @delegate('v', 'upper')
... @delegate('v', 'lower')
... @delegate('v', 'wrong_method')
... @delegate('not_an_attribute', 'wrong_attribute')
... class Foo:
... def __init__(self, v):
... self.v = v
dhilst /
Created Apr 7, 2019
Create open objects with easy, access dicts as objects and arrays with a simple notation
from import MutableMapping
class O(MutableMapping):
O class make possible to create deep nested objects without struggle.
Just instantiate it!
>>> o = O()
It's represented by its contructor. This means that coping and pasting
dhilst / gist:f5d5d78463f34d243d7f343337f8880b
Last active Apr 7, 2019
Show queries at rails test console
View gist:f5d5d78463f34d243d7f343337f8880b
ActiveRecord::Base.logger =
dhilst /
Last active Apr 7, 2019
declarative class expressinons
# Using class expressions for declarative programming in python
import inspect
def route(path, func, *methods):
An example on how to create function usable for
declarative programming in python. These functions
will sit on the class body and setup some state for
latter use.
dhilst / gist:43e13b93f68811988324fa4f483cce75
Last active Jan 25, 2019
Redmine Uninstall agile plugin
View gist:43e13b93f68811988324fa4f483cce75
# Move all issues to 'Task' tracker
RAILS_ENV=production rails r "Issue.where(tracker: Tracker.find_by(name: 'User story'))&.update(tracker: Tracker.find_by(
name: 'Task'))"
bundle exec rake redmine:plugins:migrate NAME=redmine_agile VERSION=0 RAILS_ENV=production
rm -rf plugins/redmine_agile/
# Update Fedora
is_number() { perl -se 'exit($n !~ /^\d+(\.\d+)?$/)' -- -n="$1"; }
current_version=$(curl -s | perl -lane 'print $1 if /href="(\d+)\/"/' | sort -rn | head -1)
is_number $current_version || { echo 'Cant get Fedora version'; exit 1; }
dnf install dnf-plugin-system-upgrade -y && dnf upgrade --refresh -y && dnf system-upgrade download --refresh --releasever=$current_version -y && dnf system-upgrade reboot -y
View gist:73b701c753f13301bc3610aaefba18a8
# If you come from bash you might have to change your $PATH.
# export PATH=$HOME/bin:/usr/local/bin:$PATH
# Path to your oh-my-zsh installation.
export ZSH="/Users/daniel/.oh-my-zsh"
# Set name of the theme to load --- if set to "random", it will
# load a random theme each time oh-my-zsh is loaded, in which case,
# to know which specific one was loaded, run: echo $RANDOM_THEME
# See
You can’t perform that action at this time.