Skip to content

Instantly share code, notes, and snippets.

View ixe013's full-sized avatar

Guillaume ixe013

View GitHub Profile
@ixe013
ixe013 / sort-json.py
Created April 11, 2024 04:06
Python code to deep sort a JSON file
import argparse
import collections
import json
import sys
def sort_json(json_obj):
if isinstance(json_obj, dict):
sorted_dict = collections.OrderedDict()
for key in sorted(json_obj.keys()):
sorted_dict[key] = sort_json(json_obj[key])

Keybase proof

I hereby claim:

  • I am ixe013 on github.
  • I am ixe013 (https://keybase.io/ixe013) on keybase.
  • I have a public key ASDVKpY197mr9of1D44fuPwJhESiuireGAjklHQ9UC_sbAo

To claim this, I am signing this object:

@ixe013
ixe013 / postalcode.go
Last active November 23, 2019 01:14
Go code used to play around FPE / FF1 asking this question https://crypto.stackexchange.com/q/75926/1949
package main
import (
"encoding/hex"
"fmt"
"strings"
"github.com/capitalone/fpe/ff1"
//"alphabets"
)
@ixe013
ixe013 / polyglot-listener.bat
Last active April 23, 2024 10:00
A polyglot batch file/JScript.net application that listens on a port. Try it with `polyglot-listener.bat 1234` to listen on port 1234
@if (@X)==(@Y) @end /* JScript comment
@echo off
REM Polyglot code adapted from https://stackoverflow.com/a/24396149/591064
setlocal enableDelayedExpansion
REM Too few arguments?
if "x%1" == "x" goto usage_help
REM Find the latest JScript.Net compiler
for /f "tokens=* delims=" %%v in ('dir /b /s /a:-d /o:-n "%SystemRoot%\Microsoft.NET\Framework\*jsc.exe"') do (
@ixe013
ixe013 / emp-to-locoid.py
Created October 2, 2019 19:58
Converts a AAR EMP address to a locomotive id
import re
emp = 'cn.l.ble.901:itc'
#Test regex here:
#https://pythex.org/?regex=%5E(%5Ba-z%5D%7B2%2C4%7D)%5C.l%5C.(%5Ba-z%5D%2B%3F)%5C.(.*)%3A(.*)&test_string=cn.l.ble.901%3Atmc
pattern = re.compile(r'^([a-z]{2,4})\.l\.([a-z]+?)\.(.*):(.*)')
match = pattern.search(emp)
scac, origin, number, topic = match.groups()
#print(scac, origin, number, topic)
print(f'emp={emp}')
print(f'locoid={origin}{number}')
@ixe013
ixe013 / prompt_finder.py
Last active October 2, 2019 17:33
Looks for a sequence of text (a prompt) inside a set of lines arbitrary cut, with or without newlines
import itertools
tests_passed = {
'simple end of line':
[ b'One\nSSH>',
b'no!',
],
'simple begining of line':
[ b'SSH>',
],
@ixe013
ixe013 / abortable-threadpoolexectuor.py
Created September 17, 2019 20:10
Aborting a thread pool executor using events. Some threads will never run (that's what we want to demonstrate)
import concurrent.futures
import logging
import threading
import time
import random
def return_after_5_secs(num, stop):
threading.current_thread().name = f"banane{num}"
logging.debug(f"from inside {num}")
@ixe013
ixe013 / aoicmd.py
Created February 20, 2019 04:26
Python Cmd cmdloop replacement to make it asyncio aware
#See https://stackoverflow.com/q/54425723/591064 for usage
async def adapter_cmdloop(self, intro=None):
"""Repeatedly issue a prompt, accept input, parse an initial prefix
off the received input, and dispatch to action methods, passing them
the remainder of the line as argument.
"""
self.preloop()
#This is the same code as the Python 3.7.2 Cmd class, with the
@ixe013
ixe013 / showJWT.py
Last active September 14, 2023 18:23
Python script to decode a JWT. Works with JWT that are compressed (DEFLATE algorihtm) and incomplete padding
from __future__ import print_function
import base64
import json
import os.path
import pprint
import sys
import time
import zlib
hKRib2R5hqhkZXRhY2hlZMOpaGFzaF90eXBlCqNrZXnEIwEg1SqWNfe5q/aH9Q+OH7j8CYREoroq3hgI5JR0PVAv7GwKp3BheWxvYWTFAul7ImJvZHkiOnsia2V5Ijp7ImVsZGVzdF9raWQiOiIwMTIwZDUyYTk2MzVmN2I5YWJmNjg3ZjUwZjhlMWZiOGZjMDk4NDQ0YTJiYTJhZGUxODA4ZTQ5NDc0M2Q1MDJmZWM2YzBhIiwiaG9zdCI6ImtleWJhc2UuaW8iLCJraWQiOiIwMTIwZDUyYTk2MzVmN2I5YWJmNjg3ZjUwZjhlMWZiOGZjMDk4NDQ0YTJiYTJhZGUxODA4ZTQ5NDc0M2Q1MDJmZWM2YzBhIiwidWlkIjoiOGRhODVkNTNhZGU3NDc3MDAzYjc5M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