Skip to content

Instantly share code, notes, and snippets.

View phausler's full-sized avatar

Philippe Hausler phausler

View GitHub Profile
@phausler
phausler / main.swift
Created September 10, 2016 17:56
Numeric Progressions
/// - Note: this requires Swift 3.0 (Mac OS X or iOS, Linux currently crashes in locale fetching)
import Foundation
func permuteLetterCountCycles(_ start: Int, _ formatter: NumberFormatter) -> [String] {
var foundNumbers = Set<Int>()
var result = Array<String>()
var number = start
formatter.numberStyle = .spellOut
while true {
// convert the number into the string representation (and presume all locales have a string representation)
import Foundation
class ConsumerOperation<T> : Operation {
private var consumer: (T) -> Void
private weak var prodcuer: ProducerOperation<T>?
init(prodcuer: ProducerOperation<T>, consumer: (T) -> Void) {
self.prodcuer = prodcuer
self.consumer = consumer
@phausler
phausler / build.sh
Last active June 24, 2016 19:34
Swift Toolchain Build Script
#!/usr/bin/env bash
set -e
# This should live in the same directory that contains the swift repository and other tools.
SRC_DIR=$PWD/swift
RUN_TESTS=
if [[ "$1" == "-t" || "$1" == "--test" ]] ; then
RUN_TESTS="-t"
#if DEBUG
#define ONLY_FOR_DEBUGGER
#else
#define ONLY_FOR_DEBUGGER UNAVAILABLE_ATTRIBUTE
#endif
diff --git a/lib/product.py b/lib/product.py
index 82684cc..bcc6b6c 100644
--- a/lib/product.py
+++ b/lib/product.py
@@ -115,7 +115,7 @@ class DynamicLibrary(Library):
def generate(self):
if Configuration.current.target.sdk == OSType.Linux:
- return Library.generate(self, ["-shared", "-Wl,-soname," + self.product_name, "-Wl,--no-undefined"])
+ return Library.generate(self, ["-shared", "-Wl,-soname," + self.product_name, "-Wl,--no-undefined", "-Wl,-Bsymbolic"])
@phausler
phausler / wrappers.h
Created September 17, 2014 18:48
portable function wrappers
#if defined(__APPLE__) // apple ld specific
// wrapped ala -Wl,-alias,___wrap_printf,_printf
#include <dlfcn.h>
#define WRAPFN(f) __wrap_##f
#define WRAPFN_DECL(f) WRAPFN(f)
#define REALFN(f) __real_##f
#define REALFN_DECL(f) (*REALFN(f))
@phausler
phausler / gist:8248182
Created January 3, 2014 22:47
NSGenericDeallocHandler for tracking when objects die
extern void _NSSetDeallocHandler(id object, void (^block)(void));
_NSSetDeallocHandler(someObject, ^{
NSLog(@"someObject was deallocated");
});
@phausler
phausler / CFBlockQueue.h
Created December 5, 2013 22:31
A simple CFRunLoopSource based atomic queue for block execution in a header implementation (poor man's GCD)
#ifndef _CFBLOCKQUEUE_H_
#define _CFBLOCKQUEUE_H_
#include <Block.h>
#include <libkern/OSAtomic.h>
#include <CoreFoundation/CFString.h>
#include <CoreFoundation/CFSet.h>
#include <CoreFoundation/CFRunLoop.h>
typedef void (^CFBlockQueueBlock)(void);
@phausler
phausler / gist:7190603
Last active December 26, 2015 17:59
CFType registration SublimeText snippet
<snippet>
<content><![CDATA[
#include "CFBase.h"
#include "CFRuntime.h"
#include "${1:name}.h"
struct __${1:name} {
CFRuntimeBase _base;
};
@phausler
phausler / gist:7079724
Created October 21, 2013 07:05
example bridge callbacks
/*
Foo.java
*/
package com.apportable.example;
...
public class Foo {
public static void initialize(Activity activity, String appId) {