Skip to content

Instantly share code, notes, and snippets.

View Pegolon's full-sized avatar

Markus Kirschner Pegolon

View GitHub Profile
@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: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 / 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 / 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];
class MyClass {}
let anObject = MyClass()
print("The address of anObject is \(ObjectIdentifier(anObject))")
var simulateScrollingTimer: Timer?
var scrollUp = false
private func simulateScrolling() {
collectionView.contentOffset = CGPoint.zero
scrollUp = false
simulateScrollingTimer = Timer.scheduledTimer(timeInterval: 0.5, target: self, selector: #selector(simulateSwipe), userInfo: nil, repeats: true)
}
private func simulateSwipe() {
guard collectionView.contentSize.height > 0
@Pegolon
Pegolon / count_loc.sh
Created April 19, 2018 08:24
Count lines of code in Swift files
# brew install cloc
cloc --csv --csv-delimiter=";" --report-file=~/Desktop/output.csv .
@Pegolon
Pegolon / debug.swift
Created June 21, 2018 15:53
Cast pointer to Swift object (eg. print out current URL for webView from view debugger)
expr -l Swift -- import UIKit
expr -l Swift -- let $webview = unsafeBitCast(0x7b500026ca00, to: UIWebView.self)
expr -l Swift -- print($webview.request.url)
#!/usr/bin/env ruby
# This will compile the given Swift script and run it
unless ARGV.count == 1
puts "Please provide the path for the Swift source file to compile and run"
exit -1
end
SOURCE_FILE = ARGV[0]
BASE_NAME = File.basename(SOURCE_FILE, ".swift")
@Pegolon
Pegolon / testing.m
Last active September 27, 2018 13:10
#pragma mark - Simple Unit Test
- (void)test_callSomeoneWith_giveSomething_getSomething {
MyClass *sut = [MyClass new];
NSString *input = @„give something“;
NSString *expectedResult = @„get something“;
NSString *result = [sut callSomeoneWith:input];
XCTAssertEqualObjects(result, expectedResult);
}