Skip to content

Instantly share code, notes, and snippets.

View txomon's full-sized avatar

Javier Domingo Cansino txomon

  • Germany/Koln, UK/London, Spain/Bilbao
View GitHub Profile
@txomon
txomon / JSONL.jsonl.groovy
Last active April 8, 2025 20:58
Jetbrains IDEs (Pycharm, Intellij, etc.) data export to JSONL (json lines)
/*
* Available context bindings:
* COLUMNS List<DataColumn>
* ROWS Iterable<DataRow>
* OUT { append() }
* FORMATTER { format(row, col); formatValue(Object, col); getTypeName(Object, col); isStringLiteral(Object, col); }
* TRANSPOSED Boolean
* plus ALL_COLUMNS, TABLE, DIALECT
*
* where:
@txomon
txomon / client_disconnect_handler.py
Created February 1, 2025 18:16
Detect client-side disconnection of socket to raise an exception on the server to interrupt traffic
import ctypes
import enum
import logging
import os
import socket
import struct
import sys
try:
import tenacity.retry
@txomon
txomon / debugging_exception.py
Last active January 1, 2024 19:38
Snippet to ease debugging exceptions
import sys, traceback
def exception_hook(e, value, tb):
for line in traceback.TracebackException(
type(value), value, tb, capture_locals=True
).format(chain=True):
print(line, end="")
sys.excepthook = exception_hook
@txomon
txomon / test.py
Created August 4, 2018 04:54
Python 3.7 ContextVar example in asyncio
from contextvars import ContextVar
import asyncio
import random
cv = ContextVar('cv')
async def waiting_func(name):
print(f'{name} Before sleep: {cv.get() == name}')
@txomon
txomon / ratelimit.py
Created August 12, 2018 21:24
Rate limit python asyncio
import asyncio
import collections
async def ratelimit(*, max_request, in_interval):
slots = collections.deque()
while True:
slots.append(time() + in_interval)
yield
while len(slots) >= max_request:
left = slots[0] - time()
@txomon
txomon / C-kernel-codestyle-eclipse.xml
Created January 13, 2014 10:01
This is a configuration file for eclipse to make C code follow as much as possible Linux Codystyle
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<profiles version="1">
<profile kind="CodeFormatterProfile" name="Linux Kernel" version="1">
<setting id="org.eclipse.cdt.core.formatter.insert_space_before_opening_paren_in_method_declaration" value="do not insert"/>
<setting id="org.eclipse.cdt.core.formatter.insert_space_after_opening_paren_in_for" value="do not insert"/>
<setting id="org.eclipse.cdt.core.formatter.insert_new_line_in_empty_block" value="insert"/>
<setting id="org.eclipse.cdt.core.formatter.lineSplit" value="80"/>
<setting id="org.eclipse.cdt.core.formatter.alignment_for_member_access" value="0"/>
<setting id="org.eclipse.cdt.core.formatter.insert_space_before_comma_in_base_types" value="do not insert"/>
<setting id="org.eclipse.cdt.core.formatter.keep_else_statement_on_same_line" value="false"/>
@txomon
txomon / error.log
Created October 29, 2015 14:41
Openwrt AA compilation
root@3c0f8c6a25c9:/srv/attitude_adjustment# make menuconfig V=s
make[1]: Entering directory `/srv/attitude_adjustment/scripts/config'
zconf.tab.o: In function `zconflex':
zconf.tab.c:(.text+0x21c1): undefined reference to `kconf_id_lookup'
zconf.tab.c:(.text+0x2313): undefined reference to `kconf_id_lookup'
collect2: ld returned 1 exit status
make[1]: *** [conf] Error 1
make[1]: Leaving directory `/srv/attitude_adjustment/scripts/config'
make: *** [scripts/config/mconf] Error 2
@txomon
txomon / playbook.yaml
Created October 30, 2019 19:11
Example declarative metamodule for ansible
- name: Make sure only three files exist in /myfolder
declarative:
items:
- a
- b
- c
state:
command: find /myfolder/ | tail -n +2 | basename
extra_item:
file:
# -*- coding: utf-8 -*-
from __future__ import absolute_import, division, print_function, unicode_literals
import string
from weakref import WeakKeyDictionary
class SafeDict(dict):
def __missing__(self, key):
return '{' + key + '}'
async def message_handler(message: DubtrackMessage):
print(f'Received {message.text}')
# await message.channel.say('Bot speaking here')
def run_bot():
# Setup
bot = Bot()
dubtrack_backend = DubtrackBotBackend()
dubtrack_backend.configure()