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 - -- -"
@sloev
sloev / args_to_csv.py
Created April 21, 2020 12:06
how to encode values to csv string in python 3 (args to csv string)
import csv
from io import StringIO
class ArgsToCsv:
def __init__(self, seperator=","):
self.seperator = seperator
self.buffer = StringIO()
self.writer = csv.writer(self.buffer)
@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:

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

import requests
requests_get = requests.get
import OpenSSL
def get(
*args, retries=5, **kwargs,
):
@sloev
sloev / fetch.py
Last active November 19, 2021 05:50
common crawl python cdx_toolkit
try:
import requests
import cdx_toolkit
import tqdm
import OpenSSL
from lxml import html
except:
print("you need to do some installs first:\npip install requests cdx_toolkit tqdm pyOpenSSL lxml")
exit(1)
@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,