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:308b4b26599b13c20a8ff46603b0fc27
_xcat_complete() {
COMPREPLY=()
if [[ "${COMP_LINE}" =~ ^(ls|rm|ch|mk)def ]] || [[ "$COMP_LINE" =~ ^nodeset ]]; then
if [[ "${COMP_LINE}" =~ "-t network" ]]; then
local networks=$(lsdef -t network | cut -f1 -d' ' | paste -sd ' ')
COMPREPLY=( $(compgen -W "$networks" -- ${COMP_WORDS[-1]}) )
return 0
elif [[ "${COMP_LINE}" =~ "-t osimage" ]] || [[ "$COMP_LINE" =~ "osimage=" ]]; then
COMPREPLY=( $(compgen -W "$(lsdef -t osimage | cut -f1 -d' ' | paste -sd ' ')" -- ${COMP_WORDS[-1]#*=}) )
return 0
View gist:d7f4b0f9624c746bc238c33fad511949
class HasIter:
def __iter__(self):
return iter(range(10))
def foo(value):
try:
for i in value:
print(i)
except TypeError:
View gist:22eaf6089cc35fb8d43b4a49b680a5a4
#!/usr/bin/env python3
import sys
import re
def jobs_line(string):
return re.match(
r"^\[(?P<id>\d+)\]\s+(?P<default>\+|-)?\s+(?P<state>.*?)\s+(?P<rest>.*)", string
).groupdict()
View .emacs.el
(package-initialize)
(setq package-archives '(("gnu" . "https://elpa.gnu.org/packages/")
("melpa" . "https://melpa.org/packages/")))
(custom-set-faces
;; custom-set-faces was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
View gist:af9d5c15df94e0b36a8787c42ffab0ca
In [1]: for q2 in range (1, len(board)-q1):
...: if board[q1] == board[q1+q2] or board[q1+q2] == board[q1]+q2
...: or board[q1+q2] == board[q1]-q2:
...: return False
...: return True
...:
...: def n_queens_solutions(n):
...: board = []
...: return n_queens_helper(0, board, n)
...:
View foo.py
activity_level = [None, 1.2, 1.375, 1.55, 1.725, 1.9]
...
if gender == 'male':
bmr = (66 + (6.3*int(weight)) + (12.9*int(height)) - (6.8*int(age)))
calorie = bmr * ativity_levels[activity_level]
...
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)
6 RETURN_VALUE
>>> dis('"foo" == "bar" or "foo" == "tar"')
1 0 LOAD_CONST 0 ('foo')
2 LOAD_CONST 1 ('bar')
4 COMPARE_OP 2 (==)
@dhilst
dhilst / func_fun.py
Created Jun 17, 2019
Functional fun with python types
View func_fun.py
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
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 / 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.
You can’t perform that action at this time.