Skip to content

Instantly share code, notes, and snippets.

@jsenin
jsenin / hg253v2-image-builder.py
Created May 6, 2020 19:35
hg253v2 image builder
import sys
import binascii
# wget https://raw.githubusercontent.com/SySS-Research/syss-crc/master/syss_crc.py
from syss_crc import CRC
def do_crc(data):
crc = CRC()
crc.set_config_by_name('CRC-32/JAMCRC')
return crc.compute(data)
@jsenin
jsenin / ssh_autologin.py
Last active April 17, 2020 10:37
ssh auto login with python pexpect
from mamba import describe, context, it, before
from doublex import Spy, when, ANY_ARG
from expects import expect, raise_error
from doublex_expects import have_been_called_with, have_been_called
class SSHAutologin:
def __init__(self, expector):
self._expector = expector
@jsenin
jsenin / ssh_autologin.py
Created April 8, 2020 10:04
Auto login ssh with pexpect and python
import pexpect, struct, fcntl, termios, signal, sys
def sigwinch_passthrough (sig, data):
s = struct.pack("HHHH", 0, 0, 0, 0)
a = struct.unpack('hhhh', fcntl.ioctl(sys.stdout.fileno(),
termios.TIOCGWINSZ , s))
if not p.closed:
p.setwinsize(a[0],a[1])
# Note this 'p' is global and used in sigwinch_passthrough.
@jsenin
jsenin / tornado_get_route_rule_name.py
Created February 14, 2020 12:39
Show the name of matching url rule that has invoqued the current executing request handler at tornado app
from tornado.web import Application
from tornado.ioloop import IOLoop
from tornado import web
class Collaborator:
def do_magic(self):
return "Hi all!"
class ByeHandler(web.RequestHandler):
@jsenin
jsenin / colorized_app.py
Created February 13, 2020 07:26
colorized python app log
import logging
import coloredlogs
def init_logger(dunder_name, testing_mode):
log_format = (
'%(asctime)s - '
'%(name)s - '
'%(funcName)s - '
'[%(levelname)s] - '
'%(processName)s (%(process)d)'
@jsenin
jsenin / tornado_lost_logger.py
Created February 11, 2020 07:54
Tornado lost logger otuput when logger apply dictConfig without explicit disable_existing_loggers to False
from tornado.web import Application
from tornado.ioloop import IOLoop
from tornado import web
# Tornado lost logger otuput when logger apply dictConfig without explicit disable_existing_loggers to False
# infcommon https://github.com/aleasoluciones/infcommon
class Collaborator:
def do_magic(self):
return "Hi all!"
@jsenin
jsenin / tmux.conf
Created October 15, 2019 20:55
tmux config
## it solves the vim key issues when press keypad /
## it solves color terminal
## lets select using mouse and copy and paste for remote and local
## at started terminal, all terminal including the reduced window points are copied
set -g default-terminal "xterm-256color"
set -g terminal-overrides "xterm*:XT:smcup@:rmcup@:kUP5=\eOA:kDN5=\eOB:kLFT5=\eOD:kRIT5=\eOC"
# scrollback size
set -g history-limit 10000
@jsenin
jsenin / keyvaluetransparentcacherepository.py
Created July 15, 2019 07:40
Key Value cache, hooks find_ methods to store in a keyvalue repoistory (like redis)
class KeyValueTransparentCacheRepository(object):
def __init__(self, loader, keyvalue_client, key, ttl=constants.DEFAULT_CACHE_TTL):
self.loader = loader
self.keyvalue_client = keyvalue_client
self.key = key
self.ttl = ttl
def cache_wrapper(self, f):
def cache_logic(*args, **kwargs):
@jsenin
jsenin / release_production.sh
Created May 20, 2019 09:59
Tag production version and add commit description to CHANGELOG.md
#!/bin/bash
# this scripts do:
# - Marks current commit as production_<YYYYmmdd>
# - add commit descriptions between current and previous one having this pattern 'production_xxxxxx'
# It's needed to have previous tag for the first time, to obtain the difereneces between commits
# git tag production_XXXXXX <hash>
@jsenin
jsenin / jinja2file.py
Created May 14, 2019 11:05
Render a jinja2 template command line
# requires to install jinja2
# pip install jinja2
import os
import sys
from jinja2 import Environment, FileSystemLoader
def jinja2file(source, dest):
template_dir = os.path.dirname(os.path.abspath(source))
j2_env = Environment(loader=FileSystemLoader(template_dir),