Skip to content

Instantly share code, notes, and snippets.

View Kwpolska's full-sized avatar

Chris Warrick Kwpolska

View GitHub Profile
@Kwpolska
Kwpolska / babel_locale_tester.py
Created August 6, 2018 19:00
Babel locale tester
#!/usr/bin/env python3
from __future__ import print_function
import sys
import datetime
try:
import babel.dates
except ImportError:
print("Failed to import Babel. Did you run `pip install Babel`?")
sys.exit(1)
@Kwpolska
Kwpolska / # macvim - 2018-04-16_21-57-32.txt
Created April 16, 2018 21:10
macvim on macOS 10.13.4 - Homebrew build logs
Homebrew build logs for macvim on macOS 10.13.4
Build date: 2018-04-16 21:57:32
import socket
s1 = socket.socket()
s2 = socket.socket()
s1.bind(('0.0.0.0', 1234))
s2.bind(('0.0.0.0', 1234))
# Traceback (most recent call last):
# File "socket_in_use.py", line 4, in <module>
# s1.bind(('0.0.0.0', 1234))
# OSError: [Errno 48] Address already in use
@Kwpolska
Kwpolska / 01_WRITEUP.md
Created September 21, 2017 10:07
Gynvael’s Mission 15 (en): a writeup by Chris Warrick

Gynvael’s Mission 15 (en): A writeup by Chris Warrick

(Spoilers ahead!)

the chart

I started solving the mission by opening the chart with GIMP and measuring the first few lines. I found out that the first red bars are:

 60 63 112 104 112 10 10
@Kwpolska
Kwpolska / sep_unique.py
Created August 30, 2017 13:09
Split dict of lists into dict of values
def sep_unique(d):
newdict = {}
for key, val in d.items():
if len(val) > 1:
for n, i in enumerate(val, 1):
newdict[key if n == 1 else f"{key}{i}"] = i
else:
newdict[key] = val[0]
return newdict
@Kwpolska
Kwpolska / line-continuation.py
Last active July 15, 2017 08:37
PEP8-compatible line continuation
if 1 == 1:
pass
elif 1 == 1 or \
1 == 2: # backslash continuation is very ugly
pass
elif (1 == 1 or # parentheses work better
1 == 2):
pass
elif (1 == 1 or # and they look best with 8 spaces
1 == 2):
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include <sys/resource.h>
#define MSIZE 10000
int main() {
int* a[MSIZE];
struct rusage usage;
from typing import Dict, Union, NewType
Foo = NewType("Foo", str)
Bar = NewType("Bar", int)
def get_data() -> Dict[str, Union[Foo, Bar]]:
return {"foo": Foo("one"), "bar": Bar(2)}
def process(foo_value: Foo, bar_value: Bar) -> None:
pass
@Kwpolska
Kwpolska / ext4-unusable.py
Created June 6, 2017 12:06
ext4 is currently unusable with most non-English languages
# https://eclecticlight.co/2017/04/06/apfs-is-currently-unusable-with-most-non-english-languages/
# ↑ is bullshit
In [1]: e = 'é'
In [2]: len(e)
Out[2]: 1
In [3]: import unicodedata
def ask_int(question):
"""Ask a question and return an integer."""
while True:
try:
return int(input(question))
except ValueError:
print("Not a number, please try again.")