Skip to content

Instantly share code, notes, and snippets.

@najmam
najmam / rename-iso88591-utf8.py
Created September 6, 2023 16:12
Rename filenames from ISO-8859-1 to UTF-8, recursively
import os
import codecs
# Recursively rename files or folders from iso-8859-1 to utf-8
def rename_to_utf8(directory, what):
for root, dirs, files in os.walk(directory):
for filename in (dirs if what == "dirs" else files):
old_path = os.path.join(root, filename)
# Decode the old filename from iso-8859-1
@najmam
najmam / convert-vcard-to-csv.py
Last active August 20, 2023 18:15
Convert vCard to CSV (2021-06-31)
# -*- coding: utf-8 -*-
import vobject
import re
import sys
# TODO gérer les entrées qui contiennent plus d'un numéro de téléphone, ou au moins écrire un warning
vcf = "".join(open(sys.argv[1]).readlines()).strip()
vcfs = [e for e in vcf.split("END:VCARD") if e != ""]
vcfs = [e+"END:VCARD" for e in vcfs]
@najmam
najmam / list-css-classes-in-document.js
Created December 22, 2022 11:49
Lists all CSS classes referred to in a document. Run this in a web browser console.
(() => { // list all css classes referred to in the document
const classes = new Set();
function findClasses(el) {
if(el.hasAttribute('class')) {
const cls = el.getAttribute('class').split(' ');
for(let cl of cls) {
classes.add(cl);
}
}
for(let child of el.children) {
#!/bin/bash
set -e
set -o pipefail
start=$1
stop=$2
delay=$3
for rev in $(git log --oneline ${start}..${stop} |tac |cut -d' ' -f1); do
git cherry-pick -n ${rev}
@najmam
najmam / garfield
Created April 5, 2017 13:26
Script that opens today's Garfield strip in the browser
#!/bin/sh
year=$(date +%Y)
month=$(date +%m)
day=$(date +%d)
xdg-open https://d1ejxu6vysztl5.cloudfront.net/comics/garfield/${year}/${year}-${month}-${day}.gif
# if you're on Mac, use open instead of xdg-open
@najmam
najmam / batch_convert.py
Last active July 28, 2016 15:52
A script for extracting audio streams in bulk. Relies on ffmpeg
#!/usr/bin/env python3
import os, sys
# This script expects the following folder structure:
# / the folder you run this script from
# /in store the videos which you want to rip here
# /out the extracted audio will be written here
# as Ogg files, using the same name as the input
# /done and the videos that were in in/ will be moved here.
#
@najmam
najmam / PhysicsSystem_extract.java
Created October 18, 2014 19:04
Integrating gdx-ai's steering behaviours with Ashley and Box2D
// apply steering behaviors
ImmutableArray<Entity> entities = engine.getEntitiesFor(Family.getFor(SteerAgentComponent.class));
for(int i = 0; i < entities.size(); i++) {
Entity e = entities.get(i);
Body body = e.getComponent(PhysicalBodyComponent.class).body;
SteerAgentComponent steer = e.getComponent(SteerAgentComponent.class);
if(steer.steeringBehavior == null) {
continue;
}
@najmam
najmam / WorldRenderingSystem_extract.java
Last active August 29, 2015 14:07
LibGDX rendering routine using a TiledMap renderer, the Box2D debug renderer and sprites
@Override
public void update(float deltaTime) {
/* glClear etc... */
// mapCamera is an OrthogonalCamera
mapCamera.position.set(cameraMovable.position.x * mapComponent.pixelsPerMeter,
cameraMovable.position.y * mapComponent.pixelsPerMeter, 0);
mapCamera.zoom = 1.0f/cameraComponent.camera_zoom;
mapCamera.update();