Skip to content

Instantly share code, notes, and snippets.

View sloev's full-sized avatar
https://www.buymeacoffee.com/sloev

sloev / Johannes Valbjørn sloev

https://www.buymeacoffee.com/sloev
View GitHub Profile
@sloev
sloev / json_stream_encoding_stdlib.py
Last active January 10, 2020 15:11
python json stream encoding of generator and array / list using stdlib
# You can use the builtin json lib to iteratively encode a json object
# but encoding a json array iteratively requires the iterable to be list-like
# No worries we just subclass list and pretend to be a list while being able to ingest
# whatever you want
import json
import sys
class IteratorAsList(list):
@sloev
sloev / screenshot.py
Created February 24, 2020 17:05
osx python 3 headless chrome screenshot
#!/usr/bin/python
import subprocess
import json
URL = "https://www.google.com"
get_browser_bundle_id = "cat ~/Library/Preferences/com.apple.LaunchServices/com.apple.launchservices.secure.plist | plutil -convert json -r -o - -- -"

pip install -r requirements.txt

@sloev
sloev / README.md
Last active July 21, 2020 22:23
Download newest landsat recordings

used to download newest satelist images strips off landsat satelites

install

use python3.5+
pip install numpy pillow requests

usage

@sloev
sloev / encrypt_base2048_encode_json.js
Created September 2, 2020 20:32
encrypt and base2048 encode json bidirectional
const { encode, decode } = require('base2048');
const jsonCipher = require('json-cipher')
createCrypto = (secret, algorithm = 'aes-256-cbc') => {
const { cipher, decipher, hmac } = jsonCipher(secret, algorithm)
return {
stringify: object => encode(cipher(object)),
parse: string => decipher(decode(string)),
cipher,
decipher,
import requests
requests_get = requests.get
import OpenSSL
def get(
*args, retries=5, **kwargs,
):
@sloev
sloev / ipfs gossip libp2p nodejs example server with http api.md
Last active September 17, 2020 05:53
ipfs gossip libp2p nodejs example server with http api

npm install npm start

@sloev
sloev / app.py
Last active December 30, 2020 02:04
etag tracking user journey
import msgpack
from typing import Optional
from fastapi import FastAPI, Response
from starlette.requests import Request
from fastapi.responses import HTMLResponse
import crypto
import json
import secrets
app = FastAPI()
@sloev
sloev / async_mysql.py
Last active May 3, 2021 19:07
asyncio sqlalchemy mysql
from sqlalchemy.pool import QueuePool
from sqlalchemy import create_engine
from contextlib import closing, contextmanager, ExitStack
from sqlalchemy.sql import text
import asyncio
import logging
import time
class AsyncMysqlDatabase: