Skip to content

Instantly share code, notes, and snippets.

import time
i = 0
while True:
i += 1
with open('/tmp/thing', 'a') as f:
f.write('hello {}\n'.format(i))
time.sleep(0.5);
{
"apps": [{
"script": "helloworld.py",
"instances": 1,
"interpreter": "/usr/bin/python",
"exec_mode": "fork"
}]
}
>>> @contextlib.contextmanager
... def bun():
... print('top bun')
... yield
... print('bottom bun')
...
>>> with bun():
... raise ValueError('no meat!')
...
top bun
import contextlib
contextlib.contextmanager
def bun():
print('top bun')
yield
print('bottom bun')
with bun():
print('meat')
[ 5%] Built target raylib
[ 6%] Built target text_writing_anim
[ 7%] Built target text_ttf_loading
[ 8%] Built target text_raylib_fonts
[ 9%] Built target text_format_text
[ 10%] Built target text_bmfont_unordered
[ 11%] Built target shaders_postprocessing
[ 12%] Built target shaders_model_shader
[ 14%] Built target physics_shatter
[ 15%] Built target physics_restitution
filename: /lib/modules/4.2.2-1-ARCH/extramodules/nvidia.ko.gz
alias: char-major-195-*
version: 355.11
supported: external
license: NVIDIA
srcversion: 6A24921A6FFCC20E586AE3A
alias: pci:v000010DEd00000E00sv*sd*bc04sc80i00*
alias: pci:v000010DEd*sv*sd*bc03sc02i00*
alias: pci:v000010DEd*sv*sd*bc03sc00i00*
depends: drm
[223075.473]
X.Org X Server 1.17.2
Release Date: 2015-06-16
[223075.474] X Protocol Version 11, Revision 0
[223075.475] Build Operating System: Linux 4.0.4-2-ARCH x86_64
[223075.475] Current Operating System: Linux thegibson 4.2.2-1-ARCH #1 SMP PREEMPT Tue Sep 29 22:21:33 CEST 2015 x86_64
[223075.475] Kernel command line: BOOT_IMAGE=/boot/vmlinuz-linux root=UUID=6e373443-1cb5-4aef-8ab5-59c32737913f rw quiet
[223075.476] Build Date: 17 July 2015 05:38:19PM
[223075.476]
[223075.477] Current version of pixman: 0.32.8
@tmerr
tmerr / xdiff.txt
Last active October 11, 2015 20:37
The following are changes in Xorg.0.log after running
xrandr --output HDMI-1-0 --auto eDP-1-0 --pos 5x5
(Initially eDP-1-0 is the only connected monitor. The crash only happens when
I connect HDMI-1-0 and set the pos of eDP-1-0 simultaneously.)
696,733d695
< [222960.512] (II) modeset(G0): EDID vendor "SDC", prod id 18001
< [222960.512] (II) modeset(G0): Printing DDC gathered Modelines:
< [222960.512] (II) modeset(G0): Modeline "1366x768"x0.0 76.30 1366 1430 1478 1606 768 770 775 792 -hsync -vsync (47.5 kHz eP)
< [222960.512] (II) modeset(G0): Modeline "1366x768"x0.0 50.80 1366 1430 1478 1606 768 770 775 792 -hsync -vsync (31.6 kHz e)
fn mutate(s: &mut SomeStruct) {
s.field += 1;
}
struct SomeStruct {
field: i32
}
impl SomeStruct {
fn do_something(&mut self) {
def subs2(expr, substitutions):
"""
extends subs to conveniently support arrays
subs2(['a', [3,4]]) becomes subs([('a_0', 3), ('a_1', 4)])
"""
subslist = []
for name, val in substitutions:
if hasattr(val, '__getitem__') and not isinstance(val, str):
for i, vali in enumerate(val):
indexedname = '{}_{}'.format(name, i)