Skip to content

Instantly share code, notes, and snippets.

View objarni's full-sized avatar

Olof Bjarnason objarni

View GitHub Profile
@objarni
objarni / tcr.sh
Last active October 11, 2021 11:24
test-commit-revert
#!/bin/env sh
clear && python main.py && git commit -a -m 'tcr' || git reset --hard
# combine with:
# ls main.py | entr ./tcr.sh
@objarni
objarni / spy.py
Created November 2, 2020 17:30
Simple class attribute spy for Python
class Spy:
# replace getattr of class and collect all calls
# and the return the underlying class' getattr
def __init__(self, cls):
self.spy_on = cls.__name__
self.cls_getattr = cls.__getattribute__
self.cls_getitem = cls.__getitem__
self.attributes_read = set()
@objarni
objarni / AMOS.tmTheme
Created June 29, 2020 06:37
Sublime Text 3 Color Scheme Theme inspired by AMOS Professional
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<!-- Generated by: TmTheme-Editor -->
<!-- ============================================ -->
<!-- app: http://tmtheme-editor.herokuapp.com -->
<!-- code: https://github.com/aziz/tmTheme-Editor -->
<plist version="1.0">
<dict>
<key>author</key>
<string>Olof Bjarnason</string>
#!/usr/bin/env python3
#
# Python script to wish Merry Christmas using turtle.
# Author - Anurag Rana
#
from random import randint
###
# Added for approval testing purposes
@objarni
objarni / remember.py
Last active May 10, 2019 10:54
A quick and dirty way to persist small amounts of data to disk in Python3
import pickle
def remember(filepath, change):
"""Update and persist simple data to filepath using pickle module.
The change callback updates the data read from disk;
if the file does not exist None is passed and you are
responsible for building the initial data.
Example use, to keep track of how many times a script has been run:
import qp
async def backup_procedure():
async def zip_folder(folder, archive_file):
# ???
backup_fn = # ...
backup_folder = # ...
await zip_folder(backup_folder, backup_fn)
qp.publish(qif.BACKUP_DONE)
@objarni
objarni / simple.py
Last active November 24, 2018 04:48
trio learning
# License - MIT / do whatever
## rev3 - add result gathering
async def child(name, journal):
print(f"{name}: My name is: " + name)
staytime = random.randint(1, 3)
print(f"{name}: I will stay for {staytime} seconds.")
print(f"{name}: I will jot down my name in the journal")
journal.append(name)
#!/usr/bin/env python
import os
import re
from collections import defaultdict
import subprocess
author_line_count = defaultdict(lambda: 0)
email_re = re.compile(r'<.*?>')
@objarni
objarni / authorship_py2.py
Last active April 25, 2017 14:42
authorship.py
#!/usr/bin/env python
import os
import re
from collections import defaultdict
import subprocess
author_line_count = defaultdict(lambda: 0)
email_re = re.compile(r'<.*?>')
#include <stdio.h>
#include <assert.h>
#include <vector>
#include <functional>
// Scenario: a button is connected to an input pin,
// and it toggles an output pin, connect to an output
// pin on and off. So when button is pressed, lamp
// goes on. Then the button is released, and the lamp
// stays on. Not until we press button again, does