Skip to content

Instantly share code, notes, and snippets.

@bogen
bogen / badPointer.nim
Last active August 29, 2015 14:25
c pointers trunctaed when module importing related functions is not in the same module that is using them
import somePointerMod
let cptr = somePointer ()
cptr.printPointer
@bogen
bogen / python_signal_handling.py
Last active August 29, 2015 14:22
Python's signal handling with Gtk seems broken.... (not sure if it is Gtk/Gobject, or in the python binding for them)
#!/usr/bin/env python3
from gi.repository import Gtk, GObject
import signal, sys, os
count = {}
def signal_handler (signal, frame):
print('Signal %d trapped!' % signal)
@bogen
bogen / cgenTrace.nim
Created August 9, 2014 17:47
scraping getStackTrace () but should use what getStrackTrace uses.
proc cgenTrace (skip:int = 0, drop:int = 16):string =
var a = ""
var b = getStackTrace ()
while a != b:
a = b
b = replace (a, " ", " ")
let c = split (a, "\n")
let e = c.len-(3+skip)
let g = 1+drop;
if (e < 1) or (g > e):
@bogen
bogen / nimecho-out.txt
Created August 8, 2014 06:23
echo that will handle embedded nuls
See https://github.com/Araq/Nimrod/issues/1137 (nimecho0 and nimecho1 echo strings with embedded nuls)
$ nimrod c -x:off --opt:speed --deadCodeElim:on --stackTrace:off --lineTrace:off nimecho.nim
$ ./nimecho 0 > /dev/null
using nimecho0
1.8825269999999998e+00 seconds elapsed
1.8825269999999999e-06 seconds per iteration
string used: some very long string some very long string some very long string some very long string some very long string some very long string
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
void nimecho (int n, ...) {
typedef char* cptr;
va_list ap;
int i;
int len = 0;
@bogen
bogen / make_buffer2.c
Created August 6, 2014 23:15
make line feed terminated string #2
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
auto const src = "This is a test. This is a test. This is a test. This is a test.";
ssize_t len;
char* dst;
void copy_append () {
memcpy (dst, src, len);
@bogen
bogen / make_buffer.c
Created August 6, 2014 23:07
make line feed terminated string
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
auto const src = "This is a test. This is a test. This is a test. This is a test.";
ssize_t len;
char* dst;
void copy_append () {
memcpy (dst, src, len);
@bogen
bogen / Input Source #2
Last active August 29, 2015 14:04
os::parseCmdLine fails on multiline strings
import os, macros
macro huh (cmd1, cmd2: expr) : stmt =
let cs = toStrLit(callsite ())
echo "entering ", cs
echo parseCmdLine ($cmd1)
var a = $cmd2
echo a
echo "leaving ", cs, "\n"
discard
@bogen
bogen / Input source
Last active August 29, 2015 14:04 — forked from anonymous/gist:4fabe7421046e7648829
TRIPLESTR_LIT not working in places where STR_LIT does work
#import macros
macro foo (first, second : expr) : stmt =
echo first
echo second
echo ""
discard
foo one, two