Skip to content

Instantly share code, notes, and snippets.

View nst's full-sized avatar

Nicolas Seriot nst

View GitHub Profile
@0xced
0xced / CLAlert.h
Last active January 17, 2021 13:26
CLAlert
/*
* CLAlert is a drop-in replacement for NSAlert
*
* A CLAlert is exactly the same as a NSAlert, except for the alert style behavior
*
* - An alert with the informational style (NSInformationalAlertStyle) will always display a "Note icon" (kAlertNoteIcon)
* - An alert with the warning style (NSWarningAlertStyle) will always display a "Caution icon" (kAlertCautionIcon)
* - An alert with the critical style (NSCriticalAlertStyle) will always display a "Stop icon" (kAlertStopIcon)
*
* Tested on Mac OS X 10.5.8, 10.6.1 and 10.11.5
#!/usr/bin/env python
# Nicolas Seriot
# 2011-01-06
# https://gist.github.com/768457
"""
Input: path of an Objective-C project
Output: import dependancies Graphviz format
#include <time.h>
+ (NSDate *)dateFromISO8601String:(NSString *)string {
if (!string) {
return nil;
}
struct tm tm;
time_t t;
@rgov
rgov / debruijn.py
Last active November 14, 2023 07:37
de Bruijn sequence generator
def deBruijn(n, k):
'''
An implementation of the FKM algorithm for generating the de Bruijn
sequence containing all k-ary strings of length n, as described in
"Combinatorial Generation" by Frank Ruskey.
'''
a = [ 0 ] * (n + 1)
def gen(t, p):
@0xced
0xced / Makefile
Created April 22, 2011 23:07
Demonstrates gcc 4.2.1 variadic function weirdness for x86_64 architecture
# $ gcc --version
# i686-apple-darwin10-gcc-4.2.1 (GCC) 4.2.1 (Apple Inc. build 5666) (dot 3)
# Copyright (C) 2007 Free Software Foundation, Inc.
# This is free software; see the source for copying conditions. There is NO
# warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
# $ clang --version
# Apple clang version 1.7 (tags/Apple/clang-77) (based on LLVM 2.9svn)
# Target: x86_64-apple-darwin10
# Thread model: posix
@drewmccormack
drewmccormack / prefixer.py
Created May 10, 2011 07:25
Change the prefix of a Cocoa project
#!/usr/bin/env python
#---------
# Script to change the prefix of a framework
#---------
import os
import re
import string
@kongtomorrow
kongtomorrow / gist:974350
Created May 16, 2011 12:23
Get debug descriptions for enums in Objective-C via terrible terrible macro hackery.
/* Get strings descriptions for enum values for debugging.
Usage:
With enum
typedef enum {
AppleFruit = 0,
BlueberryFruit = 1,
BlackberryFruit = -1
} Fruit;
@0xced
0xced / NSData+CommonDigest.h
Created May 23, 2011 09:00
NSData+CommonDigest: The most elegant NSData category for cryptographic hash functions
/*
Licensed under the MIT License
Copyright (c) 2011 Cédric Luthi
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
@danielphillips
danielphillips / UILabel+dynamicSizeMe.h
Created June 2, 2011 22:54
Adjust UILabel to change it's frame according to it's content
@interface UILabel (dynamicSizeMe)
-(float)resizeToFit;
-(float)expectedHeight;
@end
@landonf
landonf / deadlock.m
Created June 4, 2011 04:02
Deadlocking a signal handler by using ObjC (ARM / x86-32)
#import <Foundation/Foundation.h>
static void unsafe_signal_handler (int signo) {
signal(signo, SIG_DFL);
/* Attempt to use ObjC to fetch the backtrace. Will trigger deadlock. */
[NSThread callStackSymbols];
}
int main(int argc, char *argv[]) {