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
Created June 15, 2023 11:33
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 / 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 / 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 + '}'
@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 / 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}')
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()
WARNING:abot.bot:No message handler for <DubtrackUserUpdate <DubtrackEntity None#560b135c7ae1ea0300869b20 379/1680 0(S) ##0> skip#0 played#1680 queue#0 dubs#379>
WARNING:abot.bot:No message handler for <DubtrackDub#updub <DubtrackEntity txomon#560b135c7ae1ea0300869b20 379/1680 0(S) ##0> +1-0>
INFO:dubtrack.layer3:User updated 5628edc08d7d6a5600335d3d, skip 0, played 23898, queue 30, dubs 25899
INFO:dubtrack.layer3:Chat txomon: so I have been able to more or less finish the bindings
INFO:dubtrack:Now playing youtube#8-wIg90lagk: Batman Begins Soundtrack - Corynorhinus
INFO:dubtrack.layer3:Chat txomon: and I need to generate some actions more to be able to map all the possible ones
INFO:dubtrack.layer3:Chat txomon: so if you see I do strange stuff, it's true xD
INFO:dubtrack.layer3:Chat txomon: I am just testing
INFO:dubtrack.layer3:Chat eva_MoS: Short version:beware, he´s watching all of us
INFO:dubtrack.layer3:Chat eva_MoS: ;-P
INFO:dubtrack.layer3:User updated 562e462b888e6f1900ff20bc, skip 0, played 28988, queue 42, dubs 30136
INFO:dubtrack.layer3:Song updub by eva_MoS#562e462b888e6f1900ff20bc, total 1U/0D
DEBUG:root:Sending ping
DEBUG:root:Sending message 2
DEBUG:root:Received pong
DEBUG:root:Received message: 4{"action":15,"channel":"room:561b1e59c90a9c0e00df610b","message":{"name":"user-join","type":"json","data":"{\"roomUser\":{\"_id\":\"5628db0a3883a45600b7e68f\",\"updated\":1518739898666,\"skippedCount\":0,\"playedCount\":1677,\"songsInQueue\":0,\"active\":false,\"dubs\":364,\"order\":999999999,\"roomid\":\"561b1e59c90a9c0e00df610b\",\"userid\":\"560b135c7ae1ea0300869b20\",\"_user\":\"560b135c7ae1ea0300869b20\",\"__v\":0,\"ot_token\":null,\"authorized\":true,\"queuePaused\":null,\"waitLine\":0,\"roleid\":{\"_id\":\"52d1ce33c38a06510c000001\",\"type\":\"mod\",\"label\":\"Moderator\",\"rights\":[\"skip\",\"queue-order\",\"kick\",\"ban\",\"mute\",\"set-dj\",\"lock-queue\",\"delete-chat\",\"chat-mention\"],\"__v\":0}},\"user\":{\"_force_updated\":1516971162191,\"userInfo\":{\"_id\":\"560b135c7ae1ea0300869b21\",\"userid\":\"560b135c7ae1ea0300869b20\",\"__v\":0},\"_id\":\"560b135c7ae1ea0300869b20\",\"username\"