Skip to content

Instantly share code, notes, and snippets.

View 0xced's full-sized avatar

Cédric Luthi 0xced

View GitHub Profile
@jspahrsummers
jspahrsummers / GHRunLoopWatchdog.h
Created January 28, 2015 20:50
A class for logging excessive blocking on the main thread
/// Observes a run loop to detect any stalling or blocking that occurs.
///
/// This class is thread-safe.
@interface GHRunLoopWatchdog : NSObject
/// Initializes the receiver to watch the specified run loop, using a default
/// stalling threshold.
- (id)initWithRunLoop:(CFRunLoopRef)runLoop;
/// Initializes the receiver to detect when the specified run loop blocks for
@defagos
defagos / gist:267d3b8b30604fac541f
Created December 2, 2014 10:59
git commit hook ensuring the correct branch URL is set for Travis badges found in README files. Install both as post-commit and post-merge hooks
#!/bin/sh
# Repository settings
REPOSITORY_NAME="YourRepositoryName"
README_FILE_NAME="README.markdown"
# Update a Travis badge URL found in the README to keep it in sync with the branch name
# Badge example:
# [![Build Status](https://img.shields.io/travis/$USER_NAME/$REPOSITORY_NAME/master.svg?style=flat)](https://travis-ci.org/$USER_NAME/$REPOSITORY_NAME)
branch_name=`git symbolic-ref --short HEAD`
@andymatuschak
andymatuschak / CollectionViewDataSource.swift
Last active February 12, 2021 09:44
Type-safe value-oriented collection view data source
//
// CollectionViewDataSource.swift
// Khan Academy
//
// Created by Andy Matuschak on 10/14/14.
// Copyright (c) 2014 Khan Academy. All rights reserved.
//
import UIKit
@rodionovd
rodionovd / xcodeargdumper.mm
Last active August 29, 2015 14:04
Xcode plugin snippet for dumping compiler/linker arguments for the given file(s)
#include <objc/runtime.h>
void dump_compiler_and_linker_args_for_file(NSString *file)
{
Class PBXReference = NSClassFromString(@"PBXReference");
if (! PBXReference) return;
id file_ref = [[PBXReference alloc] initWithPath: file];
@d-ronnqvist
d-ronnqvist / Thoughts on removedOnCompletion in SparkRecordingCircle.md
Last active May 16, 2020 02:51
What I think is wrong with the Spark Recording Circle code and why

There was [a tweet][tweetSoto] a couple of days ago that resulted in a discussion/question about what it wrong with the usage of removedOnCompletion = NO in the [SparkRecordingCircle code][code] for that [Subjective-C post][post].

We all kept saying that the explanation doesn't fit in a tweet, so here is my rough explanation about the issues.

But, let me first say that I think that the Subjective-C articles are reallt cool and useful to learn from. This is trying to reason about the general usage of removedOnCompletion = NO, using that code as an example, since that was what was discussed on twitter.


The root problem, as [Nacho Soto pointed out][rootProblem], is that removedOnCompletion = NO in combination with fillMode = kCAFillModeForwards is almost always used when you are not updating the model layer. This means that after the animation has finished, what you see on screen is not reflected in the property of the layer. The biggest issue that this can cause is that all the

@steipete
steipete / Macros.h
Last active January 6, 2024 07:24
Declare on your main init that all other init methods should call. It's a nice additional semantic warning. Works with Xcode 5.1 and above. Not tested with earlier variants, but should just be ignored. A reference to this macro shortly appeared in https://developer.apple.com/library/ios/releasenotes/ObjectiveC/ModernizationObjC/AdoptingModernObj…
#ifndef NS_DESIGNATED_INITIALIZER
#if __has_attribute(objc_designated_initializer)
#define NS_DESIGNATED_INITIALIZER __attribute((objc_designated_initializer))
#else
#define NS_DESIGNATED_INITIALIZER
#endif
#endif
@rostreim
rostreim / MultiStreamWriter.cs
Last active November 20, 2024 21:20
A text writer implementation that supports writing to multiple writers in one operation
//
// Copyright 2014, Desert Software Solutions Inc.
// MultiStreamWriter.cs: https://gist.github.com/rostreim/9441193
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
@chrismiles
chrismiles / reveal.py
Last active September 2, 2021 00:26
Lazy script to wrap Reveal lib load/start commands in one LLDB command.
""" File: reveal.py
Add to ~/.lldbinit:
command script import ~/.lldb-scripts/reveal.py
Q: Want to automatically load the Reveal lib on launch while debugging from Xcode?
A: In Xcode:
Add a Symbolic Breakpoint
Symbol: "UIApplicationMain"
Action: Debugger Command with value "reveal"
sbx()
{
echo '(version 1) (trace "/tmp/traceout.sb")' > /tmp/tracein.sb
sandbox-exec -f /tmp/tracein.sb "$@"
sandbox-simplify /tmp/traceout.sb > /tmp/tracesimple.sb
open -a "Sublime Text" /tmp/tracesimple.sb
}
@iamleeg
iamleeg / UIColor_literal.mm
Last active December 29, 2015 03:09
UIColor literals.
#import <UIKit/UIKit.h>
UIColor * operator"" _c(unsigned long long color)
{
unsigned long long redComponent = (color & 0xff0000 >> 16);
unsigned long long greenComponent = (color & 0x00ff00) >> 8;
unsigned long long blueComponent = color & 0xff;
float red = redComponent / 255.0;
float green = greenComponent / 255.0;
float blue = blueComponent / 255.0;