Skip to content

Instantly share code, notes, and snippets.

View Pegolon's full-sized avatar

Markus Kirschner Pegolon

View GitHub Profile
@Pegolon
Pegolon / TestDictionaryPerformance.m
Created January 28, 2016 11:36
Performance of NSDictionary initialization
- (void)test_stepByStep_withCapacity
{
NSMutableArray *keys = [NSMutableArray new];
NSMutableArray *values = [NSMutableArray new];
srand(0x21112005);
int entryCount = 1000000;
for (int ix = 0, ixMax = entryCount; ix < ixMax ; ix++) {
NSString *key = [NSString stringWithFormat:@"Key#%d", (ix + 1)];
NSString *value = [NSString stringWithFormat:@"Value with %d", rand()];
[keys addObject:key];
@Pegolon
Pegolon / replace_xml.rb
Created January 14, 2016 12:14
Find all XML files and replace multiple strings
hash2id={"replace1":"with1","replace2":"with2"}
xml_files=`find "/path/to/folder" -type f -name '*.xml'`.strip.split("\n")
xml_files.each do |xml_file|
puts "Processing #{xml_file}"
original_text=File.read(xml_file)
text=original_text.dup
hash2id.each do |hash,id|
text.gsub!(hash.to_s, id)
@Pegolon
Pegolon / gist:0ff649190ddf80901912
Created July 15, 2015 10:40
Start app with lldb
# Select Xcode
sudo xcode-select --switch /Applications/Xcode.app/
# run app with lldb
xcrun lldb ...path to application.../Contents/MacOS/binaryname
(lldb) run
# pause app
ctrl+c
@Pegolon
Pegolon / gist:d2a9b31223be77deb2f4
Created July 14, 2015 13:42
Highlight layer with short animation
CABasicAnimation *color = [CABasicAnimation animationWithKeyPath:@"borderColor"];
color.fromValue = (id)[UIColor clearColor].CGColor;
color.toValue = (id)[UIColor redColor].CGColor;
CABasicAnimation *width = [CABasicAnimation animationWithKeyPath:@"borderWidth"];
width.fromValue = @0;
width.toValue = @1.5;
CAAnimationGroup *both = [CAAnimationGroup animation];
both.duration = 0.5;
both.animations = @[color, width];
both.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
@Pegolon
Pegolon / gist:1851436
Created February 17, 2012 07:02
Showing clang predefined macros
> find /Applications/Xcode.app -name clang
# Pick one
> /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -x c /dev/null -dM -E
@Pegolon
Pegolon / gist:1646742
Created January 20, 2012 11:14
Use a semaphore to block an asynchronous call
__block dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
[self callAsyncBlock:^() {
// Do some work
dispatch_semaphore_signal(semaphore);
}];
// Wait until the semaphore has been signaled
dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
dispatch_release(semaphore);
@Pegolon
Pegolon / gist:1550345
Created January 2, 2012 11:26
Remove extra space from ObjC method signature
Find: ^([+-] \(.* \*\))( )
Replace: \1
@Pegolon
Pegolon / Count lines of code
Created March 29, 2011 12:19
Find all header and implementation files and count the loc
find Classes -name '*.[hmM]' -print0|xargs -0 wc -l
@Pegolon
Pegolon / Repair a corrupt sqlite database
Created March 15, 2011 18:38
If you get an error like SQLite error code:11, 'database disk image is malformed' you can try to dump and reload the database with these commands
cd "$DATABASE_LOCATION"
echo '.dump'|sqlite3 $DB_NAME|sqlite3 repaired_$DB_NAME
mv $DB_NAME corrupt_$DB_NAME
mv repaired_$DB_NAME $DB_NAME
@Pegolon
Pegolon / show_branch_prompt.sh
Created January 7, 2011 10:10
Shows the current branch of a git or mercurial repository as the last part of your command line prompt
function parse_branch {
local BRANCH=$(git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/')
if [ -z "$BRANCH" ]
then
BRANCH=$(hg branch 2>/dev/null)
if [ -n "$BRANCH" ]
then
BRANCH="("$BRANCH")"
fi
fi