Skip to content

Instantly share code, notes, and snippets.

@uliwitness
uliwitness / NSStringCanDoNullsButNSLogCant.m
Created August 28, 2015 14:49
Test program that shows that NSString can do '\0' characters, however NSLog will terminate its entire output at encountering the first one:
#import <Foundation/Foundation.h>
int main(int argc, char *argv[]) {
@autoreleasepool {
NSString *str = [[NSString alloc] initWithBytes: "\0\r" length: 2 encoding: NSASCIIStringEncoding];
NSLog(@"len = %zu \"%@\"", str.length, str);
}
}
@uliwitness
uliwitness / forwarding_for_default_protocol_implementations.m
Created September 7, 2015 02:30
It's annoying that Objective-C doesn't let you provide a default implementation for a protocol. Maybe one could just create a proxy with that?
//
// main.m
// ProtocolImplementations
//
// Created by Uli Kusterer on 07/09/15.
// Copyright (c) 2015 Uli Kusterer. All rights reserved.
//
#import <Foundation/Foundation.h>
@uliwitness
uliwitness / constructorless_works.cpp
Last active September 8, 2015 16:42 — forked from anonymous/int_doesnt_work.cpp
The second example's second case won't compile (complains it expected a class after ~) but the third one through the template does. Anyone know what I'm doing wrong?
#include <string>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <malloc/malloc.h>
class JollyRoger
{
public:
@uliwitness
uliwitness / cppwrapper.cpp
Created October 21, 2015 00:16
Wrapping C++ in Swift via a C wrapper.
#include "cppwrapper.h"
#include "buff.hpp"
extern "C" void buff_deinit( buff* _this )
{
delete _this;
}
extern "C" buff* buff_init( int type, double amount, double max_amount, double start_angle, double relative_angle, double max_distance, double bleedthrough, bool permanent )
{
@uliwitness
uliwitness / cardflipper.hc
Last active November 21, 2015 15:33
How to flip through cards in HyperCard.
-- first approach:
-- sadly this causes a deep nested hierarchy where "go" calls "openCard"
-- which calls "go", eventually running out of memory.
on openCard
wait 5 seconds
go next
end openCard
-- second approach:
-- idle gets called periodically by HyperCard, but you don't have control over
You can specify the underlying name for a C function the linker/compiler should actually use. If you use an existing
function's name, it will just let you refer to it with your prototype's name. If you define the function, it'll give
it that name. It even complains if a function of that name already exists. Tested with clang on a Mac, but AFAIK also
works in GCC. You can even use special characters in your function names, like you can do in assembly.
struct eat_char_fcn
{
eat_char_fcn( struct eat_char_fcn (*inFun)( char currCh, xml_reader& reader, vector<shared_ptr<node>>& nod, attribute* att ) ) : function(inFun) {}
struct eat_char_fcn operator()( char currCh, xml_reader& reader, vector<shared_ptr<node>>& nod, attribute* att ) { return function(currCh,reader,nod,att); }
explicit operator bool() { return function != nullptr; }
struct eat_char_fcn (*function)( char currCh, xml_reader& reader, vector<shared_ptr<node>>& nod, attribute* att );
};
#import <Foundation/Foundation.h>
int main(int argc, char *argv[]) {
@autoreleasepool {
int* __nullable foo = NULL;
int& fooRef = *foo;
}
return 0;
}
<html>
<head>
<title>Streaming - Back Soon</title>
</head>
<body bgcolor="#00ff00">
<div id="message" style="font-size: 80pt; font-family: Helvetica; font-weight: bold; color: white; text-shadow: 2px 2px #000000;">
Back in <span id="timer">5:00</span> minutes
</div>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE dictionary SYSTEM "file://localhost/System/Library/DTDs/sdef.dtd">
<dictionary title="AppleScriptPropertyTest Terminology" xmlns:xi="http://www.w3.org/2003/XInclude">
<xi:include href="file://localhost/System/Library/ScriptingDefinitions/CocoaStandard.sdef" xpointer="xpointer(/dictionary/suite)"/>
<suite name="AppleScriptPropertyTest Suite" code="ASPT" description="AppleScriptPropertyTest Suite">
<cocoa name="ULIAppleScriptPropertyTestSuite"/>
<class-extension description="The App" extends="application">
<cocoa class="NSApplication"/>
<property name="boogaloo" code="ACTV" description="App&apos;s boogaloo prop." type="boolean">