Skip to content

Instantly share code, notes, and snippets.

View neilkimmett's full-sized avatar

Neil Kimmett neilkimmett

View GitHub Profile
@pietbrauer
pietbrauer / Rakefile
Created April 14, 2015 12:02
Rake task for cleaning header comments from objc files
namespace :housekeeping do
desc "Remove all header-comments"
task :remove_header_comments do
["Classes", "Tests"].each do |directory|
files = Dir["./#{directory}/**/*"].select { |value| File.file?(value) }
files.each do |file|
lines_array = File.open(file).readlines
if lines_array.first.match(/^\/\//) && !lines_array.first.match(/^\/\/ DO NOT EDIT/)
text = lines_array.drop_while { |line| line.match(/^\/\/|^\n/) }
File.open(file, 'w') do |f|
@tomlea
tomlea / hero.sh
Created August 1, 2013 16:02
When you have multiple heroku apps, for one repo, you're going to need a hero! hero production run rake db:migrate
function _hero_getRemoteNames(){
git config --get-regexp remote.*.url heroku.com |
sed -E 's/^remote\.([^\.]*)\.url .*$/\1/'
}
function _hero_herokuAppFor(){
git config --get remote.$1.url |
sed -E 's/^git@heroku.com:([^.]*)\.git/\1/'
}
@simonwhitaker
simonwhitaker / swmath.m
Last active January 1, 2016 22:58
Architecture-independent floor() function
/*
* Calling math.h functions like `floor` and `floorf` on CGFloat variables
* becomes problematic when compiling the same code for both 32-bit and
* 64-bit platforms, since CGFloat is double on 64-bit, float on 32-bit.
* Hence, if you compile with -Wconversion set, `floorf` will give a warning
* on 64-bit, while `floor` gives a warning on 32-bit.
*
* Here's a suggested implementation of an architecture-independent `floor`
* function, written using plain old function overloading which is enabled
* using the `__attribute__((overloadable))` Clang language extension.
@Sephiroth87
Sephiroth87 / ⦅╯°□°⦆╯
Created February 17, 2015 17:42
Swift flipping operator ⦅╯°□°⦆╯
let conversionMap: [Character: Character] = [
"\u{0021}" : "\u{00A1}",
"\u{0022}" : "\u{201E}",
"\u{0026}" : "\u{214B}",
"\u{0027}" : "\u{002C}",
"\u{0028}" : "\u{0029}",
"\u{002E}" : "\u{02D9}",
"\u{0033}" : "\u{0190}",
"\u{0034}" : "\u{152D}",
"\u{0036}" : "\u{0039}",
struct APIError: NetworkError {
let json: JSON
let apiCode: Int?
let message: String?
let httpResponse: HTTPURLResponse
@khanlou
khanlou / Enum+CaseCountable.swift
Created November 15, 2016 18:19
count and allValues on Int-based enums
protocol CaseCountable { }
extension CaseCountable where Self : RawRepresentable, Self.RawValue == Int {
static var count: Int {
var count = 0
while let _ = Self(rawValue: count) { count+=1 }
return count
}
@mpospese
mpospese / CGRectIntegralScaled.m
Created February 28, 2013 03:34
Pixel aligns rectangles, taking the device's screen scale into account.
CGRect CGRectIntegralScaledEx(CGRect rect, CGFloat scale)
{
return CGRectMake(floorf(rect.origin.x * scale) / scale, floorf(rect.origin.y * scale) / scale, ceilf(rect.size.width * scale) / scale, ceilf(rect.size.height * scale) / scale);
}
CGRect CGRectIntegralScaled(CGRect rect)
{
return CGRectIntegralScaledEx(rect, [[UIScreen mainScreen] scale]);
}
@irace
irace / CenteringView.swift
Last active November 29, 2017 19:31
I’m building a complex new app entirely with programmatic Auto Layout. It only supports iOS 9 so that means `UIStackView` and `NSLayoutAnchor` exclusively. These two classes have been very handy thus far, in the spirit of composition over inheritance.
final class CenteringView: UIView {
// MARK: - Initialization
init(contentView: UIView) {
super.init(frame: .zero)
addSubview(contentView)
contentView.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activateConstraints([
@jakebellacera
jakebellacera / gmail-fluidapp-userscript.js
Last active September 16, 2019 17:08
An updated Fluidapp Userscript for Gmail
// use for patterns:
// *gmail.com*
// *mail.google.com*
// *google.com*mail*
window.fluid.dockBadge = '';
setTimeout(updateDockBadge, 3000);
setInterval(updateDockBadge, 15000);
function updateDockBadge() {
@krzysztofzablocki
krzysztofzablocki / gist:4396302
Last active November 24, 2021 19:17
Set symbol breakpoint on objc_msgSend then setup this debug command to log all methods called in iOS Simulator. If you want to do device debugging change esp+4 register to r0, esp+8 to r1 Found long ago somewhere on stackoverflow.
expr -- (void)printf("[%s, %s]\n",(char *) object_getClassName(*(long*)($esp+4)), (char *) *(long *)($esp+8) )