Skip to content

Instantly share code, notes, and snippets.

(set malloc (NuBridgedFunction functionWithName:"malloc" signature:"li"))
(set memset (NuBridgedFunction functionWithName:"memset" signature:"llil"))
(set getchar (NuBridgedFunction functionWithName:"getchar" signature:"i"))
;; Allocate in 100MB chunks...
(set bytecount (* 1024 1024 100))
(set iterations 10)
(set i 0)
#include <Foundation/Foundation.h>
@protocol MyProto
@end
@interface JSBClass2 <MyProto>
@end
typedef struct jsbStruct
{
@interface JSBClass : NSObject
{
int anIntArray[12];
struct jsbStruct aStruct;
struct jsbStruct aStruct2;
union jsbUnion aUnion;
int anEnum;
char aChar;
int anInteger;
short aShort;
(macro dbg (s)
`(let ((_a ,s))
(print ',s)
(print " = ")
(puts _a)
_a))
(function factorial (n)
(if (< n 2)
(then n)
(load "NuMongoDB")
(load "NuJSON")
(load "Nutils:cl_utils") ; for butlast and last functions
(load "Nutils:with_object") ; for with-object
; Wrap the mongo connection and make sure the last value of body is
; the return value
(macro with-mongo ((user password db) *body)
(set __allbutlast (butlast *body))
(set __last (last *body))
@itfrombit
itfrombit / nu.m.diff
Created October 28, 2010 03:13
Detecting when nush is accidentally run instead of nutest on a NuTestCase
diff --git a/objc/nu.m b/objc/nu.m
index 1d21a56..170206c 100644
--- a/objc/nu.m
+++ b/objc/nu.m
@@ -230,6 +230,12 @@ int NuMain(int argc, const char *argv[], const char *envp[])
@catch (NuException* nuException)
{
printf("%s\n", [[nuException dump] cStringUsingEncoding:NSUTF8StringEncoding]);
+ if ([[nuException name] isEqualToString:@"NuUndefinedSuperclass"]) {
+ NSArray* a = [[nuException reason] componentsSeparatedByString:@" "];
var path = "/Users/jsb/Desktop/LayerTest";
var filename = "jefftest.acorn";
var acorn = JSTalk.application("Acorn");
var doc = acorn.open(path + "/" + filename);
var count = doc.layers().count();
for (i = 0; i < count; i++)
{
@itfrombit
itfrombit / gist:1033259
Created June 18, 2011 16:41
Handler generator
static IMP handler_returning_void(void* userdata)
{
return imp_implementationWithBlock(^(id receiver, ...) {
struct handler_description description;
description.handler = NULL;
description.description = userdata;
va_list ap;
va_start(ap, receiver);
nu_handler(0, &description, receiver, ap);
});
@itfrombit
itfrombit / gist:4969075
Created February 16, 2013 22:47
Two quick and dirty ways to capture the output of a system call from Nu.
(set popen (NuBridgedFunction functionWithName:"popen" signature:"l**"))
(set pclose (NuBridgedFunction functionWithName:"pclose" signature:"il"))
(set fgetc (NuBridgedFunction functionWithName:"fgetc" signature:"il"))
(set mktemp (NuBridgedFunction functionWithName:"mktemp" signature:"**"))
(set unlink (NuBridgedFunction functionWithName:"unlink" signature:"i*"))
(function sys (command)
(set tempfile (mktemp "temp.XXXXXX"))
(set c (+ "(" command " 2>&1) > " tempfile))
@itfrombit
itfrombit / gist:2075934dabf9a378b628
Created December 7, 2014 23:42
excerpt to programmatically create a menu in OS X
NSMenu* menubar = [NSMenu new];
NSMenuItem* appMenuItem = [NSMenuItem new];
[menubar addItem:appMenuItem];
[NSApp setMainMenu:menubar];
NSMenu* appMenu = [NSMenu new];
NSString* toggleFullScreenTitle = @"Toggle Full Screen";