Skip to content

Instantly share code, notes, and snippets.

@itfrombit
itfrombit / sampletextfield.m
Created March 6, 2019 19:18
Programmatically creating an NSTextField with label
NSTextField* xxxUIControlCreateTextField(NSStackView* parent, const char* label, const char* default_value, u32 tag, float preferred_width, float view_width)
{
NSStackView* stack = [[NSStackView alloc] init];
stack.translatesAutoresizingMaskIntoConstraints = NO;
stack.orientation = NSUserInterfaceLayoutOrientationHorizontal;
stack.spacing = 4;
NSTextField* tf_label = nil;
@itfrombit
itfrombit / cglayer_blit.m
Last active November 4, 2018 16:43
Bit Blitting with CGLayer
- (void)drawRect:(NSRect)dirtyRect
{
[super drawRect:dirtyRect];
static int redOffset = 0;
static int greenOffset = 0;
static int blueOffset = 0;
for (int y = 0; y < _bitmapHeight; y++)
{
@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";
@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: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);
});
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 / 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:@" "];
(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))
(macro dbg (s)
`(let ((_a ,s))
(print ',s)
(print " = ")
(puts _a)
_a))
(function factorial (n)
(if (< n 2)
(then n)
@interface JSBClass : NSObject
{
int anIntArray[12];
struct jsbStruct aStruct;
struct jsbStruct aStruct2;
union jsbUnion aUnion;
int anEnum;
char aChar;
int anInteger;
short aShort;