Skip to content

Instantly share code, notes, and snippets.

@pk
pk / ExampleTest.m
Created June 21, 2011 15:00
Using method swizzling and blocks to test Class methods in Objective-C.
#import "SenTestCase+MethodSwizzling.m"
@interface ExampleTest : SenTestCase {}
+ (BOOL)trueMethod;
+ (BOOL)falseMethod;
@end
@implementation ExampleTest
+ (BOOL)trueMethod { return YES; }
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<style>
.feld1 {
margin: 20px;
}
.feld2 {
@pk
pk / .sleep
Created January 10, 2019 14:37
Sleep script to stop all Docker containers
#!/bin/bash
exec &> ~/.sleep.log
# Author: pavel@fry-it.com
# Version: 0.0.1
echo ".sleep triggered at $(date)"
# This have to be here otherwise launchctl won't find Docker commands
DOCKER=/usr/local/bin/docker
- (IBAction)buttonTapped:(UIButton *)aSender {
self.validationErrors = nil;
// Translate Button -> Option
NSUInteger index = [self.buttonsView.subviews indexOfObject:aSender];
PQMarkSheetAnswer *selectedOption = (self.options)[index];
// When we have single choice we need to toggle options
if (!self.allowsMultipleSelection && [self.selectedOptions count] > 0) {
PQMarkSheetAnswer *alreadySelectedOption = [self.selectedOptions firstObject];
@pk
pk / Adjusted Helvetica Neue LT Std 95 Black.hhea.xml
Last active December 12, 2015 02:58
Fixing ascender/descender for Helvetica Neue LT Std 95 Black for iOS
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE hheaTable [
<!ELEMENT hheaTable EMPTY>
<!ATTLIST hheaTable versionMajor CDATA #IMPLIED
versionMinor CDATA #IMPLIED
ascender CDATA #IMPLIED
descender CDATA #IMPLIED
lineGap CDATA #IMPLIED
advanceWidthMax CDATA #IMPLIED
minLeftSideBearing CDATA #IMPLIED
@pk
pk / gist:4694383
Created February 1, 2013 21:46
Trusting certain hosts using NSURLConnection delegate to bypass SSL certificate validation.
- (BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace {
return [protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust];
}
- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge {
if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust])
if ([[[GJEnvironment sharedEnvironment] trustedHosts] containsObject:challenge.protectionSpace.host])
[challenge.sender useCredential:[NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust] forAuthenticationChallenge:challenge];
[challenge.sender continueWithoutCredentialForAuthenticationChallenge:challenge];
@pk
pk / juicer_filter.rb
Created November 9, 2011 15:25
Nanoc Juicer filter for minifying CSS/JS
module PK
module Filter
class Juice < Nanoc3::Filter
identifier :juice
type :text
def run(content, params={})
input_filename = File.join('content', @item.path)
output_filename = File.absolute_path(File.join('tmp', "#{@item.path}"))
@pk
pk / list-issues.rb
Created April 10, 2011 11:59
Exports open issues for one project as CSV.
#!/usr/bin/env ruby
# Exports open issues for one project as CSV
#
# Usage:
# ./list-issues.rb > my-project-issues.csv
require 'net/http'
require 'json'
require 'csv'
@pk
pk / PKRespondsToMatcher.h
Created February 16, 2011 17:17
OCHamcrest RespondsTo matcher: assertThat(anObject, respondsTo(@"someMethod:")); Instead of something like: assertTrue([anObject respondsToSelector:@selector(someMethod:)]);
//
// PKRespondsToMatcher.h
//
// Created by Pavel Kunc on 11/02/2011.
// Copyright 2011 Pavel Kunc. All rights reserved.
//
#import <OCHamcrestIOS/HCBaseMatcher.h>
#import <OCHamcrestIOS/HCDescription.h>
#import <objc/objc-api.h>
@pk
pk / TestiTunesAppDelegate.h
Created February 11, 2011 20:14
Adding custom PDF to the iTunes iBooks an proof of concept code.
//
// TestiTunesAppDelegate.h
// TestiTunes
//
// Created by Pavel Kunc on 11/02/2011.
// Copyright 2011 Fry-IT, Limited. All rights reserved.
//
#import <Cocoa/Cocoa.h>