Skip to content

Instantly share code, notes, and snippets.

View gradha's full-sized avatar

Grzegorz Adam Hankiewicz gradha

View GitHub Profile
@gradha
gradha / test.m
Created March 30, 2013 19:47
Example of why xml should be escaped
@interface TestAppledoc
- (void)testAppledoc:(NSNumber*)please;
@end
@implementation TestAppledoc
/// Pass a value <= 0 to crash the generation.
- (void)testAppledoc:(NSNumber*)please;
@end
@gradha
gradha / recycle.m
Created April 4, 2013 19:57
Moving files to the recycle bin on macosx in objc.
#include <stdlib.h>
#include <stdio.h>
#import <AppKit/AppKit.h>
void recycle(const char *filename)
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSString *path = [[NSString alloc] initWithUTF8String:filename];
NSString *folder = [path stringByDeletingLastPathComponent];
@gradha
gradha / recycle.nim
Last active December 15, 2015 19:48
Moving files to the recycle bin on macosx in nimrod.
import strutils, os
{.passL: "-framework AppKit".}
{.emit: """
#import <AppKit/AppKit.h>
// Returns zero on success, non zero on failure.
int macosxNimRecycle(const char *filename)
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
@gradha
gradha / generate.sh
Created April 11, 2013 19:29
Random compile failure generatior
#!/bin/sh
TESTDIR="testdir"
CURRDIR=`pwd`
COUNT=10
rm log
for iteration in `seq 1 $COUNT`; do
cd "${CURRDIR}"
rm -Rf $TESTDIR && mkdir $TESTDIR && cd $TESTDIR && \
#import <AppKit/AppKit.h>
#import <math.h>
// Returns -1 on failure, or length of the sound which started to play.
double playAif(const char *filename)
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSString *path = [[NSString alloc] initWithUTF8String:filename];
NSSound *sound = [[NSSound alloc]
initWithContentsOfFile:path byReference:YES];
@gradha
gradha / weird.nim
Created April 17, 2013 22:29
Nimrod does really weird things when it tries to drink too much whisky at once.
import os
const
whisky = true
when isMainModule:
let path = "todelete"
let filename = "todelete" / "something"
var temp: TFile
createDir(path)
@gradha
gradha / nestedweird.nim
Created April 17, 2013 22:39
Nested procs avoid iterator problems
import os
const
whisky = true
proc nested(path, filename: string) =
when whisky:
for kind, sub_path in walkDir(path):
case kind
of pcFile:
if (let m = input =~ re"abc"; m.isMatch):
echo m[0]
else:
echo m[1] # error: 'm' not declared
... let's suppose we have ...
if (let m = input =~ re"abc"; m.isMatch):
echo m[0]
elif (let c = f(); c):
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
span {font-family: monospace}
span.b1 {font-weight: bold; background-color: #DDDDDD}
span.b2 {font-weight: bold; background-color: #f5d4B5}
.b1 a:link {color: blue}
.b1 a:visited {color: rgb(85, 26, 139)}
.b2 a:link {color: #b26b2d}
.b2 a:visited {color: #8a411b}
@gradha
gradha / nimspeed.nim
Last active December 17, 2015 05:09
Initial Nimrod implementation of the file reading/scanning problem at http://saml.rilspace.org/calculating-gc-content-in-python-and-d-how-to-get-10x-speedup-in-d
import strutils
proc process(filename: string) =
var
input: TFile
lineBuf = newString(100)
gcCount = 0
totalBaseCount = 0
input = open(filename)