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
@dhilst
dhilst / index.html
Created Apr 13, 2019
online photo filtering
View index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<meta name="author" content="">
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.0/jquery.min.js"></script>
@dhilst
dhilst / delegate.py
Last active Apr 7, 2019
Delegate methods in python
View delegate.py
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
dhilst / openobject.py
Created Apr 7, 2019
Create open objects with easy, access dicts as objects and arrays with a simple notation
View openobject.py
from collections.abc 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
dhilst / gist:f5d5d78463f34d243d7f343337f8880b
Last active Apr 7, 2019
Show queries at rails test console
View gist:f5d5d78463f34d243d7f343337f8880b
ActiveRecord::Base.logger = Logger.new(STDOUT)
@dhilst
dhilst / routeclass.py
Last active Apr 7, 2019
declarative class expressinons
View routeclass.py
# 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
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/
View fedora-update.sh
#!/bin/bash
# Update Fedora
is_number() { perl -se 'exit($n !~ /^\d+(\.\d+)?$/)' -- -n="$1"; }
current_version=$(curl -s https://sjc.edge.kernel.org/fedora-buffet/fedora/linux/releases/ | 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 https://github.com/robbyrussell/oh-my-zsh/wiki/Themes
View gist:43a1aa12737d279b2f416f0802e2c494
set modeline
set ls=2
set autoindent smartindent clipboard+=unnamed
set formatoptions-=t formatoptions+=croql
set nohls
set synmaxcol=200
set et
set backspace=indent,eol,start
set mouse+=a
set fo+=crot
@dhilst
dhilst / deletecache.js
Created Oct 28, 2018
Delete all service workers cache on liner
View deletecache.js
window.caches.keys().then(ks => ks.forEach(k => window.caches.delete(k).then(console.log).catch(console.error)))
You can’t perform that action at this time.