Skip to content

Instantly share code, notes, and snippets.

View elnygren's full-sized avatar

el3ng elnygren

  • Helsinki, Finland
View GitHub Profile
@elnygren
elnygren / expression_problem.clj
Last active January 23, 2025 16:00
Solving the Expression Problem with Clojure
; The Expression Problem and my sources:
; http://stackoverflow.com/questions/3596366/what-is-the-expression-problem
; http://blog.ontoillogical.com/blog/2014/10/18/solving-the-expression-problem-in-clojure/
; http://eli.thegreenplace.net/2016/the-expression-problem-and-its-solutions/
; http://www.ibm.com/developerworks/library/j-clojure-protocols/
; To begin demonstrating the problem, we first need some
; "legacy code" with datastructures and functionality:
@elnygren
elnygren / gitlab_mv.py
Created August 11, 2016 06:30
Move git projects the hard way
from subprocess import call
OLD_URLS = [
'[email protected]:someone/some-project.git'
]
NEW_URLS = [
'[email protected]:someone/some-project.git'
]
@elnygren
elnygren / ssl_status_pyopenssl.py
Created August 19, 2016 12:38
SSL certificate status with pyOpenSSL
from OpenSSL import SSL
import sys, os, select, socket
def parse_name(name):
return {
'common_name': name.commonName
}
def verify_cb(conn, cert, errnum, depth, ok):
@elnygren
elnygren / emblica_shared_source_license.py
Created September 5, 2016 12:24
EMBLICA SHARED SOURCE LICENSE
EMBLICA SHARED SOURCE LICENSE
version 1.0, 5 September 2016
Copyright (c) 2016 Emblica. <http://emblica.fi>
Everyone is permitted to copy and distribute verbatim
copies of this license document, but changing it is
not allowed.
TERMS AND CONDITIONS
@elnygren
elnygren / logging.py
Created September 26, 2016 10:09
Sane Python logging
# Setting up python logging is a pain in the but
# ...until you found this gist.
import logging
from logging.config import dictConfig as LOGGING_CONFIG
LOG_LEVEL = logging.INFO
LOGGING_CONFIG({
'version': 1,
'formatters': {
@elnygren
elnygren / django_jwt_cookie.py
Last active September 24, 2023 08:13
Teach Django to use JWT tokens inside the session cookie - plays well with django-rest-framework-jwt.
@elnygren
elnygren / to_file.py
Created October 27, 2016 19:40
Populate Django request.FILES from base64 encoded file in request.POST
import base64
import io
import sys
from django.core.files.uploadedfile import InMemoryUploadedFile
from django.core.exceptions import SuspiciousOperation
# WARNING: quick and dirty, should be used for reference only.
def to_file(file_from_POST):
@elnygren
elnygren / docker_run_commands.sh
Last active August 16, 2017 00:09
Docker run commands
#
# ElasticSearch
#
docker run -d \
-v "$PWD/esdata":/usr/share/elasticsearch/data \
-p 127.0.0.1:9200:9200 \
-p 127.0.0.1:9300:9300 \
--name essi \
--restart always \
@elnygren
elnygren / poor_man_airdrop.sh
Last active January 2, 2017 15:14
Poor man's airdrop (send a file to a friend)
#
# RECEIVE DATA:
#
nc -lp <PORT> > data_from_someone
# gzipped, monitor with pv
nc -lp 6666 | gzip -d | pv > data_from_someone
@elnygren
elnygren / ansible-tasks.yml
Created November 16, 2016 19:30
Certbot autorenew + Nginx (with Django specific conf)
- hosts: server
become: yes
become_method: sudo
user: root
vars:
- APP_NAME: app
- CERTBOT_EMAIL: [email protected]
- DOMAIN_NAME: www.emblica.fi
- OTHER_DOMAINS: ['emblica.fi'] # fed to certbot