Skip to content

Instantly share code, notes, and snippets.

@shannoga
shannoga / gist:1008678
Created June 5, 2011 05:14
Get fonts family and font names list on iOS
// List all fonts on iPhone
NSArray *familyNames = [[NSArray alloc] initWithArray:[UIFont familyNames]];
NSArray *fontNames;
NSInteger indFamily, indFont;
for (indFamily=0; indFamily<[familyNames count]; ++indFamily)
{
NSLog(@"Family name: %@", [familyNames objectAtIndex:indFamily]);
fontNames = [[NSArray alloc] initWithArray:
[UIFont fontNamesForFamilyName:
[familyNames objectAtIndex:indFamily]]];
@jsundram
jsundram / cull.py
Last active April 5, 2023 15:22
Check if lat long is inside the bounds of the continental US (box model, not shape)
# http://en.wikipedia.org/wiki/Extreme_points_of_the_United_States#Westernmost
top = 49.3457868 # north lat
left = -124.7844079 # west long
right = -66.9513812 # east long
bottom = 24.7433195 # south lat
def cull(latlngs):
""" Accepts a list of lat/lng tuples.
returns the list of tuples that are within the bounding box for the US.
NB. THESE ARE NOT NECESSARILY WITHIN THE US BORDERS!
@0xc010d
0xc010d / ReCodeSign
Created November 14, 2011 22:38
Codesign an iOS app, with a different distribution certificate and mobileprovisioning file.
- Copy the delivered ipa into a directory to work in.
- export PlistBuddy="/usr/libexec/PlistBuddy" to get the PlistBuddy tool to your shell. If it is not added, all references to PlistBuddy
will need to be written as the full path.
- Take the delivered App.ipa and unzip it using the unzip command. This should produce a Payload directory containing the app and its
resources.
- Enter the command "codesign -d --entitlements :enterprise.plist Payload/PathToApp.app/" This pulls the entitlements out of the app, and
prints them to a plist, without a leading "blob" of data. Pay particular attention to the colon before the enterprise.plist file name.
@iluvcapra
iluvcapra / NSPredicate2SQL.mm
Last active October 3, 2020 23:08
Convert an NSPredicate to a SQL WHERE clause
static NSString *SQLNullValueString = [[NSString alloc] initWithString:@"NULL"];
/* Prototypes */
NSString *SQLWhereClauseForPredictate(NSPredicate *predicate);
NSString *SQLExpressionForNSExpression(NSExpression *expression);
/* Implementation */
@clayton
clayton / ffmpeg-install.sh
Created August 9, 2013 18:55
Install FFMPEG on OS X with HomeBrew to convert Mp4 to WebM
# Installation
brew install ffmpeg --with-vpx --with-vorbis --with-libvorbis --with-vpx --with-vorbis --with-theora --with-libogg --with-libvorbis --with-gpl --with-version3 --with-nonfree --with-postproc --with-libaacplus --with-libass --with-libcelt --with-libfaac --with-libfdk-aac --with-libfreetype --with-libmp3lame --with-libopencore-amrnb --with-libopencore-amrwb --with-libopenjpeg --with-openssl --with-libopus --with-libschroedinger --with-libspeex --with-libtheora --with-libvo-aacenc --with-libvorbis --with-libvpx --with-libx264 --with-libxvid
# Easy Peasy
ffmpeg -i video.mp4 video.webm
@jpavley
jpavley / ios_fonts.m
Last active January 5, 2023 22:47
Iterate through all the fonts families and fonts in an iOS device and print their names to the console.
NSArray *fontFamilyNames = [UIFont familyNames];
for (NSString *familyName in fontFamilyNames) {
NSLog(@"Font Family Name = %@", familyName);
NSArray *names = [UIFont fontNamesForFamilyName:familyName];
NSLog(@"Font Names = %@", names);
}
@mikeabdullah
mikeabdullah / gist:6685381
Created September 24, 2013 14:13
Build date for Cocoa apps
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setLocale:[[[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"] autorelease]];
[formatter setDateFormat:@"MMM d yyyy"];
[formatter setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0]];
NSString *string = @__DATE__;
NSDate *buildDate = [formatter dateFromString:string];
[formatter release];
@jefferythomas
jefferythomas / gist:7265536
Created November 1, 2013 13:36
+combinePDFURLs:writeToURL: takes in an array of PDFs and combines them all together in the output URL.
+ (void)combinePDFURLs:(NSArray *)PDFURLs writeToURL:(NSURL *)URL
{
CGContextRef context = CGPDFContextCreateWithURL((__bridge CFURLRef)URL, NULL, NULL);
for (NSURL *PDFURL in PDFURLs) {
CGPDFDocumentRef document = CGPDFDocumentCreateWithURL((__bridge CFURLRef)PDFURL);
size_t numberOfPages = CGPDFDocumentGetNumberOfPages(document);
for (size_t pageNumber = 1; pageNumber <= numberOfPages; ++pageNumber) {
CGPDFPageRef page = CGPDFDocumentGetPage(document, pageNumber);
@debloper
debloper / bandwidth.js
Last active November 5, 2023 19:15
Determine client's connection speed with JavaScript
// Let's initialize the primitives
var startTime, endTime, fileSize;
// Set up the AJAX to perform
var xhr = new XMLHttpRequest();
// Rig the call-back... THE important part
xhr.onreadystatechange = function () {
// we only need to know when the request has completed
@ShadoFlameX
ShadoFlameX / custom_callouts.md
Last active May 20, 2018 14:14
Custom Map Annotation Callouts on iOS
  1. Create a UIView subclass for the pin callout view.
  2. Create a subclass of MKAnnotationView for your map pins.
  3. Add an instance of the callout view subclass to your MKAnnotationView subclass.
  4. Add a property to toggle the callout view to your MKAnnotationView subclass. This example fades in/out:
    - (void)setShowCustomCallout:(BOOL)showCustomCallout
    {
        [self setShowCustomCallout:showCustomCallout animated:NO];
    }