Skip to content

Instantly share code, notes, and snippets.

View romainbriche's full-sized avatar

Romain Briche romainbriche

  • San Francisco, California
View GitHub Profile
@indragiek
indragiek / gist:5297435
Last active March 5, 2023 21:55
Draft of a ReactiveCocoa based interface for CoreData
//
// FGOManagedObjectContextStack.h
//
// Created by Indragie Karunaratne on 2012-12-23.
//
#import <Foundation/Foundation.h>
typedef void (^FGOConfigurationBlock)(id);
@benlodotcom
benlodotcom / ClearApplicationCache.m
Last active April 13, 2017 09:41
Methods to flush the HTML5 Application Cache on iOS. In a UIWebView Webkit uses an sqlite database to store the resources associated to a cache manifest, as there is no API yet to flush the Application Cache you can use this method which delete entries directly from the database. However, this approach could break anytime if the implementation o…
static NSString *cacheDatabaseName = @"ApplicationCache.db";
static NSString *cacheGroupTable = @"CacheGroups";
static NSString *cacheGroupTableManifestURLColums = @"manifestURL";
static NSString *cacheTable = @"Caches";
static NSString *cacheTableCacheGroupId = @"cacheGroup";
/**
Clears the cached resources associated to a cache group.
@param manifestURLs An array of `NSString` containing the URLs of the cache manifests for which you want to clear the resources.
@jverkoey
jverkoey / UIView Layout
Last active May 16, 2020 02:51
Layout + size calculations for iOS.
- (CGSize)sizeOfContentsWithSize:(CGSize)size
shouldLayout:(BOOL)shouldLayout {
// Calculate frames.
if (shouldLayout) {
// Update frames.
}
return // size
}
@drewmccormack
drewmccormack / gist:5262375
Created March 28, 2013 11:03
A category method for NSArray that facilitates enumeration with regular draining of the autorelease pool. Useful for those long, memory accumulating loops.
@implementation NSArray (AutoreleasePoolDraining)
-(void)enumerateObjectsDrainingEveryIterations:(NSUInteger)iterationsBetweenDrains usingBlock:(void (^)(id object, NSUInteger index, BOOL *stop))block
{
NSUInteger total = 0;
NSUInteger count = self.count;
NSUInteger numberOfChunks = (count / MAX(1,iterationsBetweenDrains) + 1);
BOOL stop = NO;
for ( NSUInteger chunk = 0; chunk < numberOfChunks; chunk++ ) {
@autoreleasepool {
@fform
fform / gist:5259003
Created March 27, 2013 23:13
Sketch Textures and Templates
@DerAndereAndi
DerAndereAndi / Description.md
Last active December 15, 2015 09:19
Ground Control additions, see description.md file below

Ground Control by @mattt is a great iOS library to remotely configure your iOS app by sending plists from a server to your app and then updating the user defaults values.

I wanted to extend this a bit with the following ideas in mind:

  • Define the values in a JSON file, instead of uploading an updated plist file to the server
  • Define values independently for given bundle identifiers, bundle version and language combination, so I can modify e.g. beta and debug versions independently from released apps
  • Values can be defined in a default language for a bundle version and overwritte on language specific entries like en. You can also only use default or only use specific languages
  • Return an empty plist for all unknown bundle identifiers or bundle versions
  • Don't check for config updates on every startup or every time the app becomes active, but only once a day or a remotely configurable amount of days
  • Right now the server side ph
@fcrespo82
fcrespo82 / SearchGooglePlaces.py
Last active September 29, 2021 23:01
Python script for pythonista (iOS app) to search google places API and open the first result in Apple Maps
# -*- coding: utf-8 -*-
import requests, json, webbrowser, urllib, sys
API_KEY = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' # Get your api key from https://code.google.com/apis/console/, you MUST add the Places API permission to it
GOOGLE_PLACES_URI = 'https://maps.googleapis.com/maps/api/place/textsearch/json?query={0}&sensor=false&key={1}'
APPLE_MAPS_URI = 'safari-http://maps.apple.com/?q={0}'
#call this script in pythonista for ios pythonista://GoogleToAppleMaps?action=run&argv=[prompt]
def main():
#import <Foundation/Foundation.h>
#import <mach/mach_time.h> // for mach_absolute_time() and friends
// clang -g -fobjc-arc -Weverything -Wno-unused-parameter -framework Foundation -o iteration iteration.m
// Run this by passing arguments on the command line. Run without any
// arguments to see the supported flags. Each time a flag is used causes
// that test to be run and timed, with the time (in seconds) output when
// it finishes. Be careful not to do anything else on your machine (such
// as surfing Redding while getting bored looking at the terminal) otherwise
@FredericJacobs
FredericJacobs / gist:5204090
Last active December 15, 2015 04:49
How to make load animated GIFS into a UIImageView

Use the Image Magic Command

convert +adjoin loading.gif out%d.gif

Then load them using the animationImages in the UIImageView.

UIImageView* animatedImageView = [[UIImageView alloc] initWithFrame:self.view.bounds];
animatedImageView.animationImages = [NSArray arrayWithObjects: 
@FredericJacobs
FredericJacobs / gist:5181824
Last active December 15, 2015 01:39
The Matrix
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<style type="text/css"></style>
</head>
<body style="margin:0" onload="for(s=window.screen,w=q.width=s.width,h=q.height=s.height,m=Math.random,p=[],i=0;i&lt;256;p[i++]=1);setInterval(&#39;9Style=\&#39;rgba(0,0,0,.05)\&#39;9Rect(0,0,w,h)9Style=\&#39;#0F0\&#39;;p.map(function(v,i){9Text(String.fromCharCode(3e4+m()*33),i*10,v);p[i]=v&gt;758+m()*1e4?0:v+10})&#39;.split(9).join(&#39;;q.getContext(\&#39;2d\&#39;).fill&#39;),33)">
<canvas id="q" width="2560" height="1440">
</canvas></body></html>