Skip to content

Instantly share code, notes, and snippets.

@jlnwlf
jlnwlf / bitrate_lower.py
Last active July 16, 2018 12:41
Lower FLAC, MP3 -> MP3 to a target bitrate, and replace the files in dir(s) (requires ffmpeg, multiprocess, Python3, *nix only for now)
import argparse
import hashlib
import logging
import subprocess
from multiprocessing import Pool, log_to_stderr
from os import path, remove, replace, walk
from mutagen.mp3 import MP3
parser = argparse.ArgumentParser(description="Floor bitrate of mp3 (and flac) to mp3 to gain storage space, recursively on DIR")
@jlnwlf
jlnwlf / fixiterm.sh
Last active September 15, 2016 13:39
Bash script to hack iTerm 2/3 to use hotkey window on every space without loosing focus on Mac OS 10.9/10/...
fixiterm () {
/usr/libexec/PlistBuddy -c 'Add :LSUIElement bool true' /Applications/iTerm.app/Contents/Info.plist
}
unfixiterm () {
/usr/libexec/PlistBuddy -c 'Delete :LSUIElement' /Applications/iTerm.app/Contents/Info.plist
}
@jlnwlf
jlnwlf / custom_git_config.sh
Last active June 8, 2016 08:31
git basic custom aliases and configuration
git config --global alias.actualize '!CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD) && git checkout master && git pull && git checkout $CURRENT_BRANCH && git rebase master'
git config --global alias.st status
git config --global alias.graph "log --graph --pretty='%C(auto)%cn %d- %h %s (%ar)'"
git config --global alias.release '!BRANCH_TO_MERGE="$(git rev-parse --abbrev-ref HEAD)" ; git actualize && git checkout master && git merge --ff-only "$BRANCH_TO_MERGE" && git branch -d "$BRANCH_TO_MERGE"'
git config --global color.ui true
@jlnwlf
jlnwlf / a.py
Created December 22, 2014 08:47
Mock base class (old style classes)
class A:
def method(self):
print "I do stuff..."
def uniquemethod(self):
print "I'm only in A"
@jlnwlf
jlnwlf / Python Virtualenv.sublime-build
Created March 31, 2014 10:06
Using a special virtualenv or, if the specific virtualenv is not found, using system's default python
{
"shell_cmd": "( workon ${file_base_name} 2>&- && ( echo \"[Using ${file_base_name} virtualenv...]\n\" ; python ${file} ; deactivate ) ) || python ${file}",
"selector": "source.python"
}
@jlnwlf
jlnwlf / pre-commit
Created March 20, 2014 09:04
git pre-commit hook for Python Unittest + autopep8 check
#!/bin/bash
autopep=$(autopep8 -dr .)
if [[ -z $autopep ]]
then
echo "> PEP8 passed !"
else
echo "> PEP8 DID NOT pass !"
echo "$autopep" | colordiff
@jlnwlf
jlnwlf / _pythonguidelines.md
Last active April 21, 2020 03:26
Useful Python snippets

General tips and guidelines for Python development

Code management

  • Always prefer huge modules (i.e. few big source files) instead of Java's "one class, one file" policy. Or you can use Python packages instead (directory with __init__.py file) to organize multiple files.
  • This tutorial about directory structure for Python projects.
  • When creating "abstract" classes with some default methods, raise NotImplementedError in the base class. You can do so also with data attributes with @property in the base class like this.

Coding standards from Python PEP 8 Coding standards

@jlnwlf
jlnwlf / Preferences.sublime-settings
Last active December 30, 2015 08:19
My SublimeText user preferences for best user experience on Windows with 1920x1080 screen resolution.
{
"ensure_newline_at_eof_on_save": true,
"color_scheme": "Packages/Color Scheme - Default/Amy.tmTheme",
"font_face": "Inconsolata",
"font_size": 14.0,
"gutter": true,
"hot_exit": false,
"remember_open_files": false,
"trim_trailing_white_space_on_save": true,
"word_wrap": false,
@jlnwlf
jlnwlf / regex.regex
Last active December 29, 2015 17:39
Useful Regex I could use someday...
Matching href without " or ' (with escaping support):
(?<=href\=('|"))((?!\1).)+
Matching youtube video URLs without " or ' (with escaping support)
(?<=href\=('|"))(((http(s)?:)?//)?(youtube.com))?/watch\?((?!\1).)+
Matching any >1 consecutive empty lines:
(?<=\s\n)(\s*\n)
Matching per line slash (/) separated values without slashes