Skip to content

Instantly share code, notes, and snippets.

@o11c
o11c / gen.py
Created February 25, 2014 22:58
generators for control flow
def split_logic():
print('hello')
yield
print('world')
yield # just to suppress the exception in the second .next
gen = split_logic()
gen.next()
print('event')
gen.next()
# Set up the prompt
autoload -Uz promptinit
promptinit
prompt adam1
setopt histignorealldups sharehistory
# Use emacs keybindings even if our EDITOR is set to vi
bindkey -e
mod common {
pub trait MyTrait {
fn get(&self) -> int;
}
}
mod specific {
pub struct MyStruct {
value: int
}
impl MyStruct {
@o11c
o11c / gist:8088385
Last active January 1, 2016 03:49
gdb python timeout using alarm signal
(gdb) python
>import signal
>def handler(sig, frame):
> print 'sig:', sig, 'frame:', frame
>signal.signal(signal.SIGALRM, handler)
>end
(gdb) python
>signal.alarm(10)
>import time
>time.sleep(20)
@o11c
o11c / mystat.cpp
Created December 20, 2013 03:41
A technique to throw an exception only if a return value is ignored.
#include <sys/stat.h>
#include <cerrno>
#include <cstdio>
#include <cstring>
// never declare a variable of this type, only use it as the return type of a function.
class OptionalError
{
const char *msg;
@o11c
o11c / foo.c
Created December 16, 2013 22:09
int foo(bool c, int x, int n) {
while (n > 0) {
n--;
if (c) {
x += 2;
}
x += 3;
}
return x;
}
#!/bin/bash -eu
# autoupdate and restart a tmwa-map server
## config is now in tmwa-map-wrapper-config
## utilities
trap 'echo EXIT $? >&2' EXIT
# prevent interaction
export GIT_EDITOR=:
@o11c
o11c / item-script.py
Last active December 30, 2015 13:08
Hacky item and mob database readers for TMW. Make sure to download the raw file exactly, the line breaks are significant.
#!/usr/bin/env python
from __future__ import print_function
for line in open('db/item_db.txt'):
if not line.strip():
continue
if line.startswith('//'):
continue
ID, Name, Label, Type, Price, Sell, Weight, ATK, DEF, Range, Mbonus, Slot, Gender, Loc, wLV, eLV, View, scripts = line.split(',', 17)
Name = Name.strip()
// amd64
typedef unsigned long size_t;
void *tor_realloc(void *, size_t);
typedef struct smartlist_t {
/** @{ */
/** <b>list</b> has enough capacity to store exactly <b>capacity</b> elements
* before it needs to be resized. Only the first <b>num_used</b> (\<=
* capacity) elements point to valid data.
@o11c
o11c / model.cpp
Created November 27, 2013 01:10
Compiler fail
#include <memory>
#include <vector>
struct Model
{
virtual ~Model() {}
};
struct PositionedModel : public Model
{