Skip to content

Instantly share code, notes, and snippets.

View sbstp's full-sized avatar

Simon Bernier St-Pierre sbstp

View GitHub Profile
let m = Matcher::new(sequence([
capture("series", many1(regex(r"^\w+$"))),
or([
capture("season_episode", regex(r"^s\d\d?e\d\d?$")),
capture("season_episode", regex(r"^\d\d?x\d\d?$")),
sequence([
capture("season", regex(r"^s\d\d?$")),
capture("episode", regex(r"^e\d\d?$")),
]),
sequence([
@sbstp
sbstp / format.py
Last active February 28, 2018 19:29
import inspect
from collections import ChainMap
def f(fmt):
frame = inspect.currentframe()
try:
vars = ChainMap(frame.f_back.f_locals, frame.f_back.f_globals)
# from pprint import pprint
# pprint(vars)
import re
RE_SPLIT = re.compile(r"""
\(([^\)]+)\)[\.\s]?| # (parens)
\[([^\]]+)\][\.\s]?| # [square]
([^\.\s]+) # Sep.ara.ted
""", re.VERBOSE)
RE_YEAR = re.compile(r'(\d{4})|\((\d{4})\)')
TOKEN_FILTER = ('1080p', '720p')
fn main() {
let matches = App::new("aconv")
.setting(AppSettings::TrailingVarArg)
.arg(
Arg::with_name("codec")
.short("c")
.required(true)
.takes_value(true),
)
.arg(
@sbstp
sbstp / minecraftd
Last active April 1, 2020 13:55
Wrapper script for the official minecraft server (or spigot) to shut it down gracefully via SIGTERM. Useful to put behind systemd and friends.
#!/usr/bin/env python3
from signal import signal, SIG_IGN, SIGTERM, SIGINT
import subprocess
import sys
USAGE = '''Usage: minecraftd [server jar path] [java options]*'''
JAVA_BIN = '/usr/bin/java'
JAVA_OPTS = ['-XX:+UseParNewGC', '-XX:+UseConcMarkSweepGC',
'-XX:+AggressiveOpts']
#!/bin/bash
FILE="$1"
TEMP=`mktemp`
help() {
echo "This programs allows you to edit an encrypted file and"
echo "re-encrypt it as soon as you're done editing."
}
@sbstp
sbstp / install.sh
Last active May 22, 2016 17:27
Rust stable installer for Linux, includes the source code for tools like racer.
#!/bin/bash
#
# Installs the specified rust-stable version with the source code.
#
# The binaries are installed using the rust installer.
# They are located in /usr/local/bin.
#
# The source is installed in /usr/local/src/rust.
set -eu
class Rational(object):
def __init__(self, num, den):
self.num = num
self.den = den
def __add__(self, other):
if isinstance(other, int):
num = self.num + other * self.den
den = self.den
; create iterator from list
(define (iter lst)
(define state lst)
(lambda ()
(if (null? state)
'()
(let ((v (car state)))
(set! state (cdr state))
v))))
@sbstp
sbstp / c.scm
Created October 29, 2015 20:23
(define fact
(lambda (n)
(if (<= n 1)
1
(* n (fact (- n 1)))
)
)
)
(define perms