Skip to content

Instantly share code, notes, and snippets.

View jbiason's full-sized avatar
💭
Rewrite it in Rust!

Julio Biason jbiason

💭
Rewrite it in Rust!
View GitHub Profile
@jbiason
jbiason / select_in.py
Created September 13, 2020 13:51
How to make "select in" with SQLite in Python
import sqlite3
import itertools
names = ['one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight',
'nine', 'ten', 'eleven', 'twelve', 'thirteen', 'fourteen', 'fifteen',
'sixteen', 'seventeen', 'eighteen', 'nineteen', 'twenty']
groups = itertools.cycle([1, 2, 3])
ids = itertools.count(1)
data = zip(ids, names, groups)
{"reqId":"JI1FPhUSoqVsxFQx1nbx","level":3,"time":"2020-01-14T14:15:39+00:00","remoteAddr":"","user":"--","app":"PHP","method":"","url":"--","message":"Error while sending QUERY packet. PID=24296 at \/snap\/nextcloud\/18204\/htdocs\/3rdparty\/doctrine\/dbal\/lib\/Doctrine\/DBAL\/Driver\/PDOStatement.php#141","userAgent":"--","version":"16.0.7.1"}
{"reqId":"um6sul7SgptfXnVXCr7b","level":4,"time":"2020-01-14T15:51:37+00:00","remoteAddr":"127.0.0.1","user":"jbiason","app":"webdav","method":"PROPFIND","url":"\/remote.php\/dav\/files\/jbiason\/External","message":{"Exception":"Doctrine\\DBAL\\Exception\\LockWaitTimeoutException","Message":"An exception occurred while executing 'UPDATE `oc_filecache` SET `mtime` = ?, `etag` = ?, `storage_mtime` = ?, `checksum`=? WHERE (`mtime` <> ? OR `etag` <> ? OR `storage_mtime` <> ? OR `checksum` <> ? OR `mtime` IS NULL OR `etag` IS NULL OR `storage_mtime` IS NULL OR `checksum` IS NULL) AND `fileid` = ? ' with params [1579007046, \"5e1de356b3af0\", 1579007046, \"\", 1579007046,
class Base:
version = "unknown"
code = "unknown"
@classmethod
def identifier(cls):
return cls.code + '/' + cls.version
def do(self):
print("I'm a stupid method in the base class")
abstract class BaseClass {
public static String getVersion() {
return "Unknown";
}
public static String getGroup() {
return "Unknown";
}
public static String getIdentifier() {
abstract class Metric {
def parse(line:String):List[String]
}
class MetricData extends Metric {
def parse(line:String):List[String] = {
println("MetricData")
List()
}
}
@jbiason
jbiason / mp4gif.sh
Created January 2, 2018 17:01
FFmpeg to convert MP4s to GIFs (like nature wants it)
#!/bin/bash
ffmpeg -y -i $1 -vf fps=10,scale=320:-1:flags=lanczos,palettegen palette.png
ffmpeg -i $1 -i palette.png -filter_complex "fps=10,scale=-1:-1:flags=lanczos[x];[x][1:v]paletteuse" -- $1.gif
SAFE_ENCODE_URL_CHARACTERS = ['/', '*']
import urlparse
import urllib
def encode(url):
if not url.startswith(('//', 'http', 'ftp')):
url = '//' + url
frags = list(urlparse.urlparse(url))
@jbiason
jbiason / fujam.py
Last active August 17, 2017 13:57
from __future__ import print_function
import random
import argparse
CONSONANTS = ['f', 'j', 'c', 'l', 'n']
PASSPHRASE = '{}u{}am para as {}o{}i{}as'
@jbiason
jbiason / requests_mock.py
Created April 27, 2017 18:45
Mocking requests.
# This is the "mockator":
def _mock_requests_method(responses, url, *dummy1, **dummy2):
"""Check the URL and return the expected response."""
if url not in responses:
raise AssertionError('URL doesnt exist: {}', url)
(status, text) = responses[url]
response = Response()
response.status_code = status
response.raw = StringIO.StringIO(text)
return response
reorder = lambda eq: '+'.join(sorted(eq.split('+'), key=int))
# (’3+2+1+1’), ’1+1+2+3’
# (’1+2+3’), ’1+2+3’
# (’2+2’), ’2+2’
# (’1+3+2+3+2+1+3+2+3+1+2’), ’1+1+1+2+2+2+2+3+3+3+3’