Skip to content

Instantly share code, notes, and snippets.

Tomas Fagerbekk tomfa

Block or report user

Report or block tomfa

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
@tomfa
tomfa / py38-libsass.sh
Last active Nov 6, 2019
pip install libsass fails for Python 3.8
View py38-libsass.sh
mkdir test && cd test
echo "3.7.0" > .python-version
# Verify python 3.7 – do "pyenv install" if necessary
python --version
$(pyenv which python) -m venv .venv
source .venv/bin/activate
@tomfa
tomfa / demo.py
Last active Sep 3, 2019
Python inheritance
View demo.py
class A:
a_attribute = 'A attribute'
common_attribute = 'common_attribute A'
overriden_attribute = 'overridden_attribute of A'
def common_method(self):
print(' - calling A.common_method')
return f'A.common_method. common_attribute={self.common_attribute}'
def a_method(self):
@tomfa
tomfa / signals.py
Last active Sep 3, 2019
Django Elasticsearch with Celery
View signals.py
from celery import shared_task
from django.db import models, transaction
from django.utils import timezone
from django_elasticsearch_dsl.apps import DEDConfig
from django_elasticsearch_dsl.registries import registry
from django_elasticsearch_dsl.signals import BaseSignalProcessor
from .. import utils
View gist:f85abcc9faa01bcacb99940cc3d8171e
### Keybase proof
I hereby claim:
* I am tomfa on github.
* I am tomfa (https://keybase.io/tomfa) on keybase.
* I have a public key ASA6Jb7E1FqdDnq75emuMWFeYHPl0fV-Axb0fPcc2FoIIQo
To claim this, I am signing this object:
View index.html
<html>
<head>
<style>
h1 { color: #FF00FF; }
.this-is-a-classname {
padding: 10px;
border: 3px solid black;
background-color: #f5deb3;
}
</style>
@tomfa
tomfa / fields.py
Last active Jan 22, 2019
Django compressed json field / compressed binary field
View fields.py
from django.utils.text import compress_string
from django.core.serializers.json import DjangoJSONEncoder
class CompressedBinaryField(models.BinaryField):
compress = compress_string
@staticmethod
def uncompress(s):
zbuf = io.BytesIO(s)
@tomfa
tomfa / fields.py
Created Jan 22, 2019
Django CompressedJSONField
View fields.py
from django.utils.text import compress_string
from django.core.serializers.json import DjangoJSONEncoder
class CompressedBinaryField(models.BinaryField):
compress = compress_string
@staticmethod
def uncompress(s):
zbuf = io.BytesIO(s)
View benchmark.sh
# Simple curl benchmarking
#
# Example: 10 (sequential) calls towards google.com
# sh benchmark.sh 10 http://google.com
#
# Output:
# Running 10 iterations for curl https://google.com
# .....
# Averaged 63.8024 ms in 10 iterations
@tomfa
tomfa / script.pseudo
Last active Sep 9, 2018
Pseudocode for check file thingy
View script.pseudo
function does_file_exist(filename):
...
function get_modified_at(filename):
...
function print_file_is_deleted(filename):
...
function print_file_is_created(filename):
@tomfa
tomfa / diff.py
Last active Sep 5, 2018
Python nested dict diff
View diff.py
"""
Hacky shell tool for finding dict deep diffs
a = {
'b': {
'c': 2,
'd': 3
},
'e': 2
}
You can’t perform that action at this time.