Skip to content

Instantly share code, notes, and snippets.

@sergeytimoshin
sergeytimoshin / clean_assets.rb
Created October 19, 2012 21:11 — forked from soffes/clean_assets.rb
Rake task to clean unused images in your iOS project
desc 'Remove unused images'
task :clean_assets do
require 'set'
all = Set.new
used = Set.new
unused = Set.new
# White list
used.merge %w{Icon Icon-29 Icon-50 Icon-58 Icon-72 Icon-114}
@sergeytimoshin
sergeytimoshin / gist:3921145
Created October 19, 2012 22:41
mapbox save as image
- (UIImage *) loadMapImage {
const int MINZOOM = 13;
const int MAXZOOM = 17;
// TODO: calculate these from list of cycle hire locations
const float MINLAT = 51.483145; //minimum and max lattitude in degrees
const float MAXLAT = 51.542138;
const float MINLONG = -0.2242237; //min and max longitutde in degrees
const float MAXLONG = -0.002275;
@sergeytimoshin
sergeytimoshin / atomic.m
Created October 31, 2012 22:05 — forked from markd2/atomic.m
Exploring the 'atomic' keyword in properties.
#import <Foundation/Foundation.h>
// clang -g -Wall -framework Foundation -o atomic atomic.m
// gcc -g -Wall -framework Foundation -o atomic atomic.m
@interface Blah : NSObject
@property (assign, NS_NONATOMIC_IOSONLY) NSInteger frobnozzle;
@property (assign, ) NSInteger commaAtEnd;
// @property (, assign) NSInteger commaAtBeginning; // Syntax error
@property (atomic, assign) NSInteger blah; // complains in gcc
@sergeytimoshin
sergeytimoshin / dict.m
Last active December 14, 2015 17:59
Dictionary.app to console output.
/* clang -fobjc-arc -framework Foundation -framework CoreServices dict.m -o dict */
#import <Foundation/Foundation.h>
#import <CoreServices/CoreServices.h>
int main(int argc, const char * argv[])
{
@autoreleasepool {
if(argc < 2)
{
@sergeytimoshin
sergeytimoshin / uianimationdragcoefficient.m
Last active December 18, 2015 05:19
UIAnimationDragCoefficient
void *UIKit = dlopen([[[NSBundle bundleForClass:[UIApplication class]] executablePath] fileSystemRepresentation], RTLD_LAZY);
CGFloat (*UIAnimationDragCoefficient)(void) = (CGFloat (*) (void)) dlsym(UIKit, "UIAnimationDragCoefficient");
DLog(@"coefficient is %f", UIAnimationDragCoefficient ? UIAnimationDragCoefficient() : 1.f);
@sergeytimoshin
sergeytimoshin / notif.mm
Created June 7, 2013 19:36
Catch all notifications
[[NSNotificationCenter defaultCenter] addObserverForName:nil object:nil queue:nil usingBlock:^(NSNotification *note) {
NSLog(@"Catch-All: %@", note);
}];
#import <mach/mach_host.h>
int get_platform_memory_limit()
{
mach_port_t host_port;
mach_msg_type_number_t host_size;
vm_size_t pagesize;
host_port = mach_host_self();
host_size = sizeof(vm_statistics_data_t) / sizeof(integer_t);
let path = UIBezierPath()
let radius : CGFloat = 4
let topRightStartAngle = -CGFloat(M_PI_2)
let topRightEndAngle : CGFloat = 0.0
let bottomRightStartAngle : CGFloat = 0.0
let bottomRightEndAngle : CGFloat = -(CGFloat(M_PI) * 3) / 2
let bottomRightCenterPoint = CGPoint(x: CGRectGetWidth(self.bounds) - radius, y: CGRectGetHeight(self.bounds) - radius)
APP_PATH="${TARGET_BUILD_DIR}/${WRAPPER_NAME}"
# This script loops through the frameworks embedded in the application and
# removes unused architectures.
find "$APP_PATH" -name '*.framework' -type d | while read -r FRAMEWORK
do
FRAMEWORK_EXECUTABLE_NAME=$(defaults read "$FRAMEWORK/Info.plist" CFBundleExecutable)
FRAMEWORK_EXECUTABLE_PATH="$FRAMEWORK/$FRAMEWORK_EXECUTABLE_NAME"
echo "Executable is $FRAMEWORK_EXECUTABLE_PATH"
/// Translation of [Peter Norvig's spell checker](http://norvig.com/spell-correct.html) into Swift 3.
/// Sample input corpus [here](http://norvig.com/big.txt)
/// Swift 2 version: https://gist.github.com/airspeedswift/6d8c9d95f0d812f58be3
import Foundation // purely for IO, most things done with Swift.String
/// Given a word, produce a set of possible alternatives with
/// letters transposed, deleted, replaced or rogue characters inserted
func edits(word: String) -> Set<String> {
if word.isEmpty { return [] }