Skip to content

Instantly share code, notes, and snippets.

@dgmltn
dgmltn / speedtest
Created October 29, 2014 20:58
Speed test shell script (using curl or wget)
#!/bin/sh
FILE_URL=http://speedtest.wdc01.softlayer.com/downloads/test10.zip
if [ -e /usr/bin/curl ] && [ -e /usr/bin/bc ] && [ -e /usr/bin/xargs ]; then
echo "scale=2; `curl --progress-bar -w "%{speed_download}" $FILE_URL -o /dev/null` / 131072"\
| bc\
| xargs -I {} echo {} mbps
elif [ -e /usr/bin/curl ]; then
curl -o /dev/null $FILE_URL
@zssz
zssz / UINavigationController+Swizzle.m
Created November 19, 2010 12:20
Swizzling navbar hide methods to tackle this bug http://screenr.com/UEc - No luck.
//
// UINavigationController+Swizzle.m
//
// Created by Zsombor Szabó on 11/19/10.
// Copyright 2010 IZE. All rights reserved.
//
#import "UINavigationController+Swizzle.h"
#import <objc/runtime.h>
@yene
yene / gist:964741
Created May 10, 2011 15:53
pre-commit hook which uses clang static analyter before commit
#!/bin/sh
RESULT=$(xcodebuild -configuration Debug RUN_CLANG_STATIC_ANALYZER=YES)
if `echo ${RESULT} | grep "generated." 1>/dev/null 2>&1`
then
echo "commit failed: anaylzer error found"
exit 1
fi
@tgaul
tgaul / InfDebugLog.h
Created June 14, 2011 19:07
InfDebugLog
#ifndef NDEBUG
#define InfDebugLog( ... ) NSLog( __VA_ARGS__ )
#else
#define InfDebugLog( ... )
#endif
#define blockSafe_cat(A, B) A##B
#define blockSafe_line(V, TMP) typeof(V) blockSafe_cat(blockSafe_tmp__, TMP) = V; __block typeof(V) V = blockSafe_cat(blockSafe_tmp__, TMP)
#define blockSafe(V) blockSafe_line(V, __LINE__)
@thekarladam
thekarladam / gist:1174535
Created August 26, 2011 22:04
Cocoa commandments
1. Thou shalt always use Key Value Observing
2. Thou shalt not block the main thread
3. Thou shalt compile with zero errors or warnings
4. Thou shalt use #pragma mark to separate code into groups based on related functionality
@davedelong
davedelong / gist:1236778
Created September 23, 2011 05:07
Snippet to discover the BOM of a text encoding
NSData *bom = nil;
NSStringEncoding encoding = ...;
NSData *a = [@"a" dataUsingEncoding:encoding];
NSData *aa = [@"aa" dataUsingEncoding:encoding];
if ([a length] * 2 != [aa length]) {
NSUInteger characterLength = [aa length] - [a length];
bom = [a subdataWithRange:NSMakeRange(0, [a length]-characterLength)];
}
@stevestreza
stevestreza / foo.m
Created March 23, 2012 01:37
How to add a Twitter username to an ABRecordRef
-(void)addContact{
ABRecordRef person;
ABMultiValueRef social = ABMultiValueCreateMutable(kABMultiDictionaryPropertyType);
ABMultiValueAddValueAndLabel(social, [NSDictionary dictionaryWithObjectsAndKeys:
(NSString *)kABPersonSocialProfileServiceTwitter, kABPersonSocialProfileServiceKey,
@"justinbieber", kABPersonSocialProfileUsernameKey,
nil], kABPersonSocialProfileServiceTwitter, NULL);
ABRecordSetValue(person, kABPersonSocialProfileProperty, social, NULL);
CFRelease(social);
require ["envelope", "imapflags", "fileinto", "reject", "notify", "vacation", "regex", "relational", "comparator-i;ascii-numeric", "body", "copy"];
# Spam processing
if not header :contains ["X-Spam-known-sender"] "yes" {
if allof (
header :contains ["X-Backscatter"] "yes",
not header :matches ["X-LinkName"] "*"
) {
discard;
stop;
#!/usr/bin/env ruby
#
# This script can be used to check the in-store availability of the iPhone 5S.
# By default, it searches for all AT&T models. You can change this by editing
# the MY_DEVICES array below. While the Apple API supports searching for
# multiple devices at once, there is a limit.
#
# Once you have properly configured the MY_DEVICES array, you can run this script
# from the terminal. It takes a single parameter, which should be the zip code you
# wish to use for your search.