Skip to content

Instantly share code, notes, and snippets.

View 0xced's full-sized avatar

Cédric Luthi 0xced

View GitHub Profile
@0xced
0xced / CopyLaunchedApplicationsInFrontToBackOrder.c
Created August 7, 2009 14:06
Get an array of running applications ordered by last use
#import <Carbon/Carbon.h>
#import <dlfcn.h>
/*
* Returns an array of CFDictionaryRef types, each of which contains information about one of the processes.
* The processes are ordered in front to back, i.e. in the same order they appear when typing command + tab, from left to right.
* See the ProcessInformationCopyDictionary function documentation for the keys used in the dictionaries.
* If something goes wrong, then this function returns NULL.
*/
CFArrayRef CopyLaunchedApplicationsInFrontToBackOrder(void)
@0xced
0xced / screenNameForDisplay.m
Created August 7, 2009 14:44
Human readable string for a display name (as in the Displays preference pane)
#import <IOKit/graphics/IOGraphicsLib.h>
#import <IOKit/graphics/IOGraphicsTypes.h>
NSString* screenNameForDisplay(CGDirectDisplayID displayID)
{
NSString *screenName = nil;
NSDictionary *deviceInfo = (NSDictionary *)IODisplayCreateInfoDictionary(CGDisplayIOServicePort(displayID), kIODisplayOnlyPreferredName);
NSDictionary *localizedNames = [deviceInfo objectForKey:[NSString stringWithUTF8String:kDisplayProductName]];
@0xced
0xced / fixXQuery.m
Created August 9, 2009 17:13
Fix for NSXMLNode XPath/XQuery using regular expressions bug (10.5.8)
#import <Foundation/Foundation.h>
#import <dlfcn.h>
#import <mach/vm_map.h>
#import <mach-o/dyld.h>
#import <mach-o/nlist.h>
#if defined(__i386__) || defined(__x86_64__)
@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
@0xced
0xced / absim.sh
Created March 11, 2010 21:25
Use your own Address Book in the iPhone Simulator
#!/bin/bash
cd ~/Library/Application\ Support/MobileSync/Backup
backup=`ls -t1 | sed -n '1p'` # most recent backup
for f in "$backup"/*.mdinfo; do
grep -q "Library/AddressBook/AddressBook.sqlitedb" $f
if [ $? -eq 0 ]; then
addressbook=`basename $f .mdinfo`
cp -v "`pwd`/$backup/$addressbook.mddata" ~/Library/Application\ Support/iPhone\ Simulator/User/Library/AddressBook/AddressBook.sqlitedb
exit $?
@0xced
0xced / pollAppleStore.sh
Created March 12, 2010 14:18
Notify when Apple Store is back
#!/bin/bash
while true; do
curl --silent http://store.apple.com | grep --silent "backsoon"
if [ $? -ne 0 ]; then
growlnotify --sticky --name 'Apple Store' --image ~/Pictures/Apple.tiff --message 'Apple Store is now open!'
exit 0
fi
sleep 60
done
@0xced
0xced / README.md
Created April 5, 2010 22:31
ABGetMe implementation for iOS
@0xced
0xced / gist:372236
Created April 20, 2010 09:34
Automatically show keyboard in MFMailComposeViewController
@try
{
id textView = [mailComposeViewController valueForKeyPath:@"internal.mailComposeView.textView"];
if ([textView respondsToSelector:@selector(becomeFirstResponder)])
[textView becomeFirstResponder];
}
@catch (NSException *e) {}
@0xced
0xced / NSMutableURLRequest+CaseSensitive.h
Created May 26, 2010 13:03
NSMutableURLRequest+CaseSensitive
/*
* NSMutableURLRequest+CaseSensitive is a category on NSMutableURLRequest
* that let you control the exact value of the HTTP header fields.
*
* NSMutableURLRequest documentation says:
* "The name of the header field to set. In keeping with the HTTP RFC,
* HTTP header field names are case-insensitive."
*
* Unfortunately, not all HTTP implementations are RFC compliant and some
* require case-sensitive header fields. To set such headers, use the
@0xced
0xced / UIDevice+serialNumber.h
Last active February 7, 2024 06:14
UIDevice+serialNumber
/*
* Adds the serialNumber property to the UIDevice class
*
* The implementation uses undocumented (for iOS) IOKit functions,
* so handle with caution and be prepared for nil.
*/
#import <UIKit/UIDevice.h>
@interface UIDevice (serialNumber)