Skip to content

Instantly share code, notes, and snippets.

View dmerejkowsky's full-sized avatar
🍵
418 - I'm a teapot

Dimitri Merejkowsky dmerejkowsky

🍵
418 - I'm a teapot
View GitHub Profile
@dmerejkowsky
dmerejkowsky / Migrating Python.md
Created February 9, 2024 15:14
A quick GPT chat, but asking a trick question ...

Question:

How do I migrate from Python 2.7 to Python 2.8 ?

Answer:

Migrating from Python 2.7 to Python 3 is a crucial step, especially since Python 2 reached its official end-of-life at the start of 2020. Here's a guide to help you transition your code:

  1. Assess Your Codebase:
    • Focus on supporting Python 2.7 initially.
@dmerejkowsky
dmerejkowsky / podiff.py
Created May 16, 2021 15:23
git filter for .po translations
#!/bin/python
from pathlib import Path
import sys
input = Path(sys.argv[1])
for line in input.read_text().splitlines():
# Ignore date of the modification
if line.startswith('"PO-Revision-Date:'):
continue
"""
Code for https://dmerej.info/blog/post/my-blogging-flow-part-2-publishing/,
because some people asked.
Entry points are either `publish()`or `new_post()`.
"""
import contextlib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText

Keybase proof

I hereby claim:

  • I am dmerejkowsky on github.
  • I am dmerej (https://keybase.io/dmerej) on keybase.
  • I have a public key ASC6SndvnXWar2ESXiyD1ogOaoCd_0uQRnAxU214SZzCZQo

To claim this, I am signing this object:

@dmerejkowsky
dmerejkowsky / test.rs
Created September 27, 2018 19:13
actix unit test
fn body_contains(response: &HttpResponse, fragment: &str) -> bool {
// TODO: this looks really complicated. I must be missing something here :/
let body = response.body();
if let Binary(b) = body {
if let Bytes(bytes) = b {
let text = str::from_utf8(&bytes).unwrap();
return text.contains(fragment);
}
}
panic!("Expecting a binary response");
@dmerejkowsky
dmerejkowsky / us.patch
Last active September 13, 2018 19:22
Easy brackets (linux)
Apply me in /usr/share/X11/xkb/symbols
diff -up us.old us
--- us.old 2018-09-13 20:58:33.969768060 +0200
+++ us 2018-09-13 21:18:13.814198419 +0200
@@ -286,22 +286,22 @@ xkb_symbols "dvorak-intl" {
key <AE12> { [bracketright, braceright, guillemotright, rightdoublequotemark ] };
key <AD01> { [dead_acute, dead_diaeresis, apostrophe, quotedbl ] };
- key <AD02> { [ comma, less, ccedilla, Ccedilla ] };
@dmerejkowsky
dmerejkowsky / python-3-4
Last active April 18, 2018 16:20
Using pipenv with pyenv to debug a ci failure on python3.4
# on arch, install openssl-1.0 and then:
CFLAGS="-DOPENSSL_NO_SSL2 -I/usr/include/openssl-1.0" LDFLAGS=-L/usr/lib/openssl-1.0 pyenv install 3.4.6
# on debian, install all build deps and then:
sudo apt install libbz2-dev libssl1.0-dev libreadline-dev zlib1g-dev libsqlite3-dev
CFLAGS=-DOPENSSL_NO_SSL2 pyenv install 3.4.6
git clone tsrc tsrc-3.4
cd tsrc-3.4
pyenv local 3.4.6
pipenv install --python $(pyenv which python) --dev
@dmerejkowsky
dmerejkowsky / count.rs
Last active July 18, 2023 18:58
Compute letters frequencies in a string
use std::collections::BTreeMap;
fn main() {
let text = "abbcbbaaeef";
let mut scores = BTreeMap::new();
for c in text.chars() {
scores.entry(c).and_modify(|e| *e += 1).or_insert(1);
}
for (k, v) in scores {
println!("{}: {}", k, v);
@dmerejkowsky
dmerejkowsky / venv.zsh
Last active October 6, 2017 21:19
Virtualenv support in zsh
# Usage:
# * Create a venv based on the name of the current directory
# $ mkdir new-proj && cd new-proj
# $ venv-create
#
# * Activae an existing virtualenv
# $ cd project
# # done!
blue="\033[34;1m"
@dmerejkowsky
dmerejkowsky / latest.zsh
Last active August 25, 2017 18:57
Insert most recent file in current command line
# Display most recent file in the current directory
function latest() {
echo $(ls --quoting-style=shell -t | head -n1)
}
# Insert most recent file in the current line
latest-file-widget () {
LBUFFER="${LBUFFER} $(latest)"
local ret=$?
zle redisplay