Skip to content

Instantly share code, notes, and snippets.

View jsmolina's full-sized avatar

Jordi Sesmero jsmolina

  • Barcelona
View GitHub Profile
@jsmolina
jsmolina / app.py
Created November 12, 2021 12:04
simple w3c tracecontext plugin for traceapi
from plugin import TraceParentLogger
def create_app():
config = get_api_settings()
app = FastAPI...
....
app.add_middleware(RawContextMiddleware, plugins=(TraceParentLogger(),)
@jsmolina
jsmolina / Dockerfile
Last active September 27, 2022 16:06
simple http server for testing kong api gw
FROM python:3.9.5-slim-buster
ENV PYTHONUNBUFFERED 1
RUN adduser \
--disabled-password \
--gecos "" \
--home /app \
app
@jsmolina
jsmolina / zx_spectrum_color.py
Created January 8, 2021 08:32
python3 script to determine which number corresponds to the specific zx spectrum color + paper + flash + bright
# python3 script to determine
# 1 flash, 1 bit bright,3 bits paper,3 bits ink
if __name__ == '__main__':
colors = {
"INK_BLACK": 0x00,
"INK_BLUE": 0x01,
"INK_RED": 0x02,
"INK_MAGENTA": 0x03,
"INK_GREEN": 0x04,
"INK_CYAN": 0x05,
"""
Converts in batch 7zip files to zip
"""
import zipfile
import glob
from io import BytesIO
import argparse
# Uncomment to use macos hack brew version of of libarchive
# import os
@jsmolina
jsmolina / wait_for_vpn.sh
Created November 14, 2018 16:02
Blocks until host is reachable by SSH. Useful for opening a VPN asynchronously and waiting for connection to be ready.
#!/usr/bin/env bash
until nc -nz $1 22 -w 5 &>/dev/null; do :; done
@jsmolina
jsmolina / unmerge_parquet.py
Created November 14, 2018 15:10
Allows splitting merged parquet files with an accidental hadoop fs -getmerge
"""
Obtained from
https://stackoverflow.com/questions/41564291/parquet-build-with-hdfs-getmerge-recovery
"""
import sys
import locale
import os
import re
import io
@jsmolina
jsmolina / celerybeat_howto_launch
Created May 9, 2018 16:58
Celery cron (beat) service learned things
Executing a new task periodically in celery like in java quartz, is as simple as:
0) Define your tasks in a dictionary (function check_users in background_tasks module will execute every half an hour):
beat_schedule = {
'check_users': {
task: 'backoffice.blueprints.users.background_tasks.check_users'
schedule: 1800.0
}
}
@jsmolina
jsmolina / gutter_example.py
Created May 9, 2018 10:30
Example of feature enable/disable in gutter
from distutils.version import StrictVersion
class User(object):
def __init__(self, version='2.0.0'):
self.app_version = version
class UserArgument(User):
COMPATIBLE_TYPE=User
def __init__(self, input):
self.applies = 1
@jsmolina
jsmolina / pathautojs.js
Last active January 3, 2016 10:59
This js script simulates Drupal pathauto module that generates an automatic url based on a node title. It is useful for web crawling, testing, ...
String.stopWords = 'a,an,as,at,before,but,by,for,from,is,in,into,like,of,off,on,onto,per,since,than,the,this,that,to,up,via,with';
String.escapeRegExp = function(str) {
return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
};
String.prototype.replaceAll = function (find, replace) {
return this.replace(new RegExp(String.escapeRegExp(find), 'g'), replace);
};
@jsmolina
jsmolina / README.txt
Created June 21, 2012 12:14
BrowserId bug number: 1605790
Welcome to BrowserId.
This module provides a 'Login' button inside login form and a configurable block.
It also defines a Permission called 'log in using browserid', which needs to be enabled for anonymous role in order to show the Login buttons.