Skip to content

Instantly share code, notes, and snippets.

View Kwpolska's full-sized avatar

Chris Warrick Kwpolska

View GitHub Profile
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
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.")
@Kwpolska
Kwpolska / fork.py
Created August 7, 2015 16:00
os.fork demo
import os
import time
print("forking...")
pid = os.fork()
print("done!")
if pid == 0:
print("hello, I am the child")
else:
print("hello, I am the parent")
@Kwpolska
Kwpolska / TextToSpeech.scpt
Created February 18, 2017 13:54
Text to Speech service
-- USAGE: create an Automator service that receives selected text and put this in "Run AppleScript"
on run {input, parameters}
choose from list {"Alex", "Daniel", "Ewa", "Samantha", "Serena", "Thomas", "Zosia", "Bad News", "Good News", "Pipe Organ"} with prompt "Choose voice:" without multiple selections allowed and empty selection allowed
set voice to the result as string
say input using voice
return input
end run
#!/usr/bin/env python3
from __future__ import print_function
def f(n, level=0):
indent = level * ' '
print(indent, 'start', n)
if n == 10202:
print(indent, 'return constant from', n)
return 4
@Kwpolska
Kwpolska / diff.diff
Last active December 8, 2016 19:02
for loop vs while loop (C, gcc 6.2.1)
--- for.s 2016-12-08 20:00:37.121281039 +0100
+++ while.s 2016-12-08 20:00:38.705280904 +0100
@@ -1,4 +1,4 @@
- .file "for.c"
+ .file "while.c"
.intel_syntax noprefix
.text
.globl main
from functools import wraps
def dec(f):
@wraps(f)
def wrapper(i):
print("wrapper")
return f(i)
return wrapper
@Kwpolska
Kwpolska / Makefile
Created September 24, 2016 11:19
Makefile example for Gynvael’s OSDev
floppy.bin: kernel.c stage1.asm stage2.asm
gcc kernel.c -std=c99 -nostdlib -o kernel64
strip kernel64
nasm stage1.asm
nasm stage2.asm
dd if=/dev/zero bs=1 count=$((512-$(stat --printf="%s" stage1))) >> stage1
cat stage1 stage2 kernel64 > floppy.bin
bash -c 'fsize=$$(stat --printf="%s" floppy.bin); if [[ $$(($$fsize%512)) != 0 ]]; then dd if=/dev/zero bs=1 count=$$((512-($$fsize%512))) >> floppy.bin; fi'
@Kwpolska
Kwpolska / widget-meta2.php
Created September 14, 2016 18:07
WordPress Meta2 widget: a meta widget with less useless cruft.
<?php
/*
Plugin Name: Meta2 Widget
Description: Meta2 Widget.
*/
class WP_Widget_Meta2 extends WP_Widget {
/**
* Sets up a new Meta widget instance.
*
[user]
name = Chris Warrick
email = kwpolska@gmail.com
username = Kwpolska
[color]
ui = 1
diff = auto
status = auto
branch = auto
[github]