Skip to content

Instantly share code, notes, and snippets.

import sys
import tempfile
import heapq
from array import array
def int_array_from_file(int_file, buffer_size=4000):
int_array = array("i")
py311.json
==========
Performance version: 1.0.9
Report on Linux-5.15.0-84-generic-x86_64-with-glibc2.31
Number of logical CPUs: 8
Start date: 2023-10-03 15:46:40.037527
End date: 2023-10-03 16:30:51.189955
@ksamuel
ksamuel / pythonstartup.py
Last active July 23, 2023 13:47
Python startup script
import atexit
# First, a lot of imports. I don't use all of them all the time,
# but I like to have them available.
import csv
import datetime as dt
import hashlib
import json
import math
"""
usage: download_bookmarks.py [-h] [--concurrency [CONCURRENCY]] [--directory DIRECTORY] bookmarks
positional arguments:
bookmarks The path to the sqlite db file containing
the bookmarks. It's the places.sqlite file
in your default profile dir.
optional arguments:
-h, --help show this help message and exit
[tool.poetry]
name = "fdsq"
version = "0.1.0"
description = "fdsq"
authors = ["fdsqfsq"]
license = "MIT"
[tool.poetry.dependencies]
python = "^3.10"
@ksamuel
ksamuel / switcheroo.sh
Created February 20, 2022 16:35
A script to automatically stash uncommited work when one switches branch in git
#!/usr/bin/env bash
set -o errtrace # err traps works in functions
set -E -o errexit # exit on error
#set -o pipefail # don't hide errors in pipes => can't use this one, it fails on grep -q
set -o nounset # exit on undeclared variable
set -o xtrace # trace everything
IFS=$'\n' # Field separator is a new line
@ksamuel
ksamuel / download_bookmarks.py
Created December 20, 2019 12:16
A quick and dirty python script to download all firefox bookmarks as stand alone static pages
"""
usage: download_bookmarks.py [-h] [--concurrency [CONCURRENCY]] [--directory DIRECTORY] bookmarks
positional arguments:
bookmarks The path to the sqlite db file containing
the bookmarks. It's the places.sqlite file
in your default profile dir.
optional arguments:
-h, --help show this help message and exit
@ksamuel
ksamuel / song.txt
Created September 30, 2019 06:36
Song for Python exercice
There's a lady who's sure all that glitters is gold
And she's buying a stairway to heaven.
When she gets there she knows, if the stores are all closed
With a word she can get what she came for.
Ooh, ooh, and she's buying a stairway to heaven.
There's a sign on the wall but she wants to be sure
'Cause you know sometimes words have two meanings.
In a tree by the brook, there's a songbird who sings,
Sometimes all of our thoughts are misgiven.
@ksamuel
ksamuel / test_formatter.py
Created October 6, 2018 09:43
Sculpter une fonction: les tests
from formatter import afficher, formater, produire
def test_afficher():
assert afficher([1, 2, 3]) == "- 1\n- 2\n- 3"
assert afficher([1, 2, 3], prefix="*") == "* 1\n* 2\n* 3"
assert afficher([1, 2, 3], template="{element} {prefix}") == "1 -\n2 -\n3 -"