Skip to content

Instantly share code, notes, and snippets.

Andreas Dewes adewes

Block or report user

Report or block adewes

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
@adewes
adewes / README.md
Last active Apr 17, 2018
Borg Backup - Shell script to create regular backups (can e.g. be called hourly by cron).
View README.md

Borg Backup Script

This is a little helper script to regulary back up your data using the Borg backup tool. I wrote this as I was frustrated with Deja-Dup, which does not allow me to exclude directories by pattern, hence I ended up with backups that were very large and took a really long time to create because they contained many directories with non-essential files (e.g. node modules or Python virtual environments). Borg backup is a simple tool that offers everything that Deja-Dup does and is easier to customize.

  • Put the script in your home folder and make it executable.
  • Call it regularly using e.g. cron (put e.g. "0 * * * * [your username] /home/[your username]/make_backup.sh" in your /etc/crontab - this will call the script every hour). Please note that the script will perform its own checking to see
@adewes
adewes / contracts.py
Created Jul 12, 2017
Contracts in Python
View contracts.py
import functools
import inspect
class Validated(type):
"""
Base meta-class for our validation classes.
"""
def __getitem__(self, type):
@adewes
adewes / Makefile
Created Nov 12, 2015
The build watcher: Automatically rebuild Pelican content as files change.
View Makefile
# Changes gather, and now my watch begins.
# It shall not end until my death.
# I shall live and die at my post.
# I am the process in the darkness.
# I am the watcher on the files.
# I am the shield that guards the realms of the build dir.
watch:
@which inotifywait || (echo "Please install inotifywait";exit 2)
@while true ; do \
@adewes
adewes / find_circular_dependencies.py
Last active Sep 16, 2015
Finding circular dependencies in your SQLAlchemy data scheme
View find_circular_dependencies.py
from collections import defaultdict
dependencies = defaultdict(set)
#use your metadata object here
for t in metadata.sorted_tables:
for fkey in t.foreign_key_constraints:
dependencies[t.name].add(fkey.referred_table.name)
@adewes
adewes / README.md
Last active Apr 23, 2019
Ebay Ads - Bot. Because who wants to write messages by hand...
View README.md

To use this bot:

  • Download ads_bot.py and requirements.txt.
  • Type pip install -r requirements.txt to install the requirements.
  • Fill out the required information in the Python file.
  • Ideally, create a (free) Slack account and set up a web hook to receive notifications from the bot.
  • Run the script :)
  • Relax and be ready to answer incoming calls :D
@adewes
adewes / eight_queens.sql
Last active May 3, 2016
Eight Queens Problem Solved using Common Table Expressions
View eight_queens.sql
WITH RECURSIVE
positions(i) as (
VALUES(0)
UNION SELECT ALL
i+1 FROM positions WHERE i < 63
),
solutions(board, n_queens) AS (
SELECT '----------------------------------------------------------------', cast(0 AS bigint)
FROM positions
UNION
View gist:2674ae8e89e4d561235a
### Keybase proof
I hereby claim:
* I am adewes on github.
* I am dewes (https://keybase.io/dewes) on keybase.
* I have a public key whose fingerprint is 3BCA 20E5 94D4 910B 070E 25D6 8E2F D9A8 CBA7 BA57
To claim this, I am signing this object:
@adewes
adewes / export.py
Created Apr 9, 2014
Python: Dictionary Value Exporter
View export.py
def export(d,key):
"""
Exports a set of values from a nested dict.
Example usage:
d = {
'name' : 'test',
'remote_servers' :
@adewes
adewes / hacker_school_effect.ipynb
Created Mar 11, 2014
The Hacker School Effect
View hacker_school_effect.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@adewes
adewes / eight_queens.py
Last active Aug 29, 2015
Acht Königinnen
View eight_queens.py
board_size = 8
def get_free_states(queens):
"""
Get free board states for a set of queens
"""
free_states = [[True]*board_size for i in range(0,board_size)]
for queen in queens:
for i in range(0,board_size):
for signs in [(1,1),(-1,-1),(1,-1),(-1,1),(1,0),(-1,0),(0,1),(0,-1)]:
You can’t perform that action at this time.