Skip to content

Instantly share code, notes, and snippets.

View hadware's full-sized avatar

hadware

View GitHub Profile
@hadware
hadware / evolution_legacy_tls.desktop
Last active December 8, 2021 14:57
Gnome Desktop config to enable TLS1.0 on evolution 3.65
[Desktop Entry]
Name=Evolution (Legacy TLS)
GenericName=Groupware Suite
X-GNOME-FullName=Evolution
Comment=Manage your email, contacts and schedule
Keywords=email;calendar;contact;addressbook;task;
Actions=new-window;compose;contacts;calendar;mail;memos;tasks;
Exec=env G_TLS_GNUTLS_PRIORITY=NORMAL:+VERS-TLS1.0 evolution %U
Icon=evolution
Terminal=false
@hadware
hadware / json_parser.py
Last active June 20, 2023 09:50
Parsing Examples with sly
from sly import Lexer, Parser
import pprint
class JSONLexer(Lexer):
tokens = {"FLOAT", "INTEGER", "STRING"}
literals = {'{', '}', '[', ']', ',', ':'}
ignore = " \t\n"
@hadware
hadware / OrderedDequeDict.py
Created November 5, 2018 15:25
An ordered dictionnary kind of like a Deque: adding or updating a key (re)-appends it to the end of the dictionary, and if the dictionary is full, the oldest elements are pop'ed (in a FIFO fashion)
class OrderedDequeDict(OrderedDict):
def __init__(self, size=100, *args, **kwargs):
super().__init__(*args, **kwargs)
self.size = size
def __setitem__(self, key, value):
if key in self:
del self[key]
elif len(self) == self.size:
@hadware
hadware / settlers.xs
Last active March 13, 2018 20:47
A settlers random map script for Age of Mythology
/* Map Name: settlers.xs
*/
//Include the library file.
include "MmM_FE_lib.xs";
// Main entry point for random map script
void main(void){
/* **************************** */
@hadware
hadware / cp_folders.sh
Created February 20, 2018 14:58
Copy only files with a specific extension and keep folder scrutures
find . -name '*.csv' -exec cp --parents \{\} /target \;
@hadware
hadware / xpath_scrape.py
Created January 19, 2018 00:35
Scraping a website's text in a class using LXML and XPath
from lxml import etree
from urllib import request
page = request.urlopen("http://link.fr").read()
root = etree.HTML(page)
items = root.xpath("//div[@class='custom-class']/text()")
@hadware
hadware / async_multifetch.py
Created January 9, 2017 22:36
A small scraper that uses ayncio to run lots of concurrent request on an API. However, it does use a sempaphore to limit the number of outgoing connection at one time.
import asyncio
import json
from os import path
import aiohttp
import async_timeout
imdb_ids = ['0114319', '0112302', '0114576', '0113189', '0112346', '0112896', '0112453',
'0113987', '0112760', '0112641', '0114388', '0113101', '0112281', '0113845']
api_url = "http://www.omdbapi.com/?i=tt%s&plot=full&r=json"
@hadware
hadware / wav_resample.py
Last active March 6, 2020 11:47
Resampling a wav ndarray with sox in python
import numpy as np
from subprocess import PIPE, run
from scipy.io.wavfile import read, write
## This is in case you have a numpy nd array of your sound, and the sampling rate
## isn't the same as another ndarray. This resamples the array by piping in and out of Sox
## This is a simple example with wav files encoded in float32, with only one channel (mono)
## These parameters can however be adjusted by tweaking -t and -c options in the sox command
with open("sample_48k.wav", "rb") as file_48k, open("sample_16k.wav", "rb") as file_16k:
@hadware
hadware / bytes_to_wav.py
Last active February 23, 2024 19:19
Convert wav in bytes for to numpy ndarray, then back to bytes
from scipy.io.wavfile import read, write
import io
## This may look a bit intricate/useless, considering the fact that scipy's read() and write() function already return a
## numpy ndarray, but the BytesIO "hack" may be useful in case you get the wav not through a file, but trough some websocket or
## HTTP Post request. This should obviously work with any other sound format, as long as you have the proper decoding function
with open("input_wav.wav", "rb") as wavfile:
input_wav = wavfile.read()