Skip to content

Instantly share code, notes, and snippets.

View markohlebar's full-sized avatar
🏠
Working from home

Marko Hlebar markohlebar

🏠
Working from home
View GitHub Profile
@mattstevens
mattstevens / gist:4400775
Last active March 9, 2022 12:53
Resizing an NSImage on retina Macs for output as a 1x image
NSImage *computerImage = [NSImage imageNamed:NSImageNameComputer];
NSInteger size = 256;
NSBitmapImageRep *rep = [[NSBitmapImageRep alloc]
initWithBitmapDataPlanes:NULL
pixelsWide:size
pixelsHigh:size
bitsPerSample:8
samplesPerPixel:4
hasAlpha:YES
@dergachev
dergachev / GIF-Screencast-OSX.md
Last active July 17, 2024 14:20
OS X Screencast to animated GIF

OS X Screencast to animated GIF

This gist shows how to create a GIF screencast using only free OS X tools: QuickTime, ffmpeg, and gifsicle.

Screencapture GIF

Instructions

To capture the video (filesize: 19MB), using the free "QuickTime Player" application:

@steipete
steipete / PSPDFUIKitMainThreadGuard.m
Last active May 27, 2024 12:11
This is a guard that tracks down UIKit access on threads other than main. This snippet is taken from the commercial iOS PDF framework http://pspdfkit.com, but relicensed under MIT. Works because a lot of calls internally call setNeedsDisplay or setNeedsLayout. Won't catch everything, but it's very lightweight and usually does the job.You might n…
// Taken from the commercial iOS PDF framework http://pspdfkit.com.
// Copyright (c) 2014 Peter Steinberger, PSPDFKit GmbH. All rights reserved.
// Licensed under MIT (http://opensource.org/licenses/MIT)
//
// You should only use this in debug builds. It doesn't use private API, but I wouldn't ship it.
// PLEASE DUPE rdar://27192338 (https://openradar.appspot.com/27192338) if you would like to see this in UIKit.
#import <objc/runtime.h>
#import <objc/message.h>
@steipete
steipete / gist:6133152
Last active October 24, 2017 12:14
Create a hash from a CGRect
NSUInteger PSPDFHashFromCGRect(CGRect rect) {
return (*(NSUInteger *)&rect.origin.x << 10 ^ *(NSUInteger *)&rect.origin.y) + (*(NSUInteger *)&rect.size.width << 10 ^ *(NSUInteger *)&rect.size.height);
}
#!/usr/bin/ruby
# Create display override file to force Mac OS X to use RGB mode for Display
# see http://embdev.net/topic/284710
require 'base64'
data=`ioreg -l -d0 -w 0 -r -c AppleDisplay`
edids=data.scan(/IODisplayEDID.*?<([a-z0-9]+)>/i).flatten
vendorids=data.scan(/DisplayVendorID.*?([0-9]+)/i).flatten
@staltz
staltz / introrx.md
Last active July 19, 2024 22:21
The introduction to Reactive Programming you've been missing
@gamenerds
gamenerds / NSPointerArray+AbstractionHelpers.h
Last active September 17, 2019 12:49
A category to abstract the details of NSPointerArray
#import <Foundation/Foundation.h>
// This helps deal with NSPointerArray that stores pointers to objects that inherit from NSObject.
// Not sure if this will work for other pointer types!!
@interface NSPointerArray (Helpers)
/**
* Adds pointer to the given object to the array.
*
* @param object Object whose pointer needs to be added to the array.
@hooman
hooman / EquatableClass.swift
Last active January 26, 2018 05:47
Sample code on how to correctly implement `Equatable` protocol for class types.
// The correct implementation of `Equatable` (and `Comparable`) can be tricky for class
// hierarchies. To make it easier, it is better to follow a well-defined pattern. Here
// is my suggestion on how to do it:
// 1. Define a protocol for polymorphic test function for equality (or comparison):
// Note: operators are not polymorphic (not virtual in C++ terms)). The function to
// call is determined and hard-coded at compile time.
/// A protocol to ammend `Equatable` for use with `class` types.
@dornad
dornad / gist:f2a8ba4b3ddab35114cc
Last active October 2, 2017 12:24
NSError** mocking with OCMock 3
- (void)testMethodExpectingNoError
{
id someObject = [self someMethodThatReturnsAnExpectedObject];
id mockDependencuy = OCMClassMock([DependencyToBeMocked class]);
OCMStub([mockDependency someMethodWithErrorRef:[OCMArg anyObjectRef]).andReturn(someObject);
NSError * error = nil;
id someReturnedValue =[self.objectUnderTest someMethodWithErrorRef:&error]:
XCTAssertNotNil(someReturnedValue);

Turning Off Github Issues

My friend Michael Jackson turned off github issues on one of his smaller projects. It got me thinking...

Maintainers getting burned out is a problem. Not just for the users of a project but the mental health of the maintainer. It's a big deal for both parties. Consumers want great tools, maintainers want to create them, but maintainers don't want to be L1 tech support, that's why they