Skip to content

Instantly share code, notes, and snippets.

View jlnr's full-sized avatar

Julian Raschke jlnr

View GitHub Profile
@alloy
alloy / README.md
Last active August 29, 2015 13:57
Fix system Ruby (2.0.0) on OS X 10.9.
@mikezila
mikezila / tilesheet.rb
Created March 2, 2017 19:28
TileSheet class for Gosu in Ruby
# tilesheet.rb
#
# This is for loading tile sheets that either have padding between the tiles,
# do not take up the whole of the image, or both. The normal Gosu method for
# loading from tiles doesn't work if there is padding or the tiles themselves
# are not wall-to-wall on the sheet. This can load such a sheet, though you
# will need to know how many tiles there are both wide and tall, as there's no
# way to guess on such a sheet. You'll also need to make sure the sheet is a
# power-of-two in size. You can do this by adjusting the sheet to 512x512 or
# 1024x1024, just add empty space if needed.
@mattt
mattt / nshipster-new-years-2015.md
Created November 25, 2014 19:38
NSHipster New Year's 2015

Season's Greetings, NSHipsters!

As the year winds down, and we take a moment to reflect on our experiences over the past months, one thing is clear: 2014 has been an incredible year professionally for Apple developers. So much has happened in such a short timespan, and yet it's hard to remember our relationship to Objective-C before Swift, or what APIs could have captivated our imagination as much as iOS 8 or WatchKit.

It's an NSHipster tradition to ask you, dear readers, to send in your favorite tips and tricks from the past year for publication over the New Year's holiday. This year, with the deluge of new developments—both from Cupertino and the community at large—there should be no shortage of interesting tidbits to share.

Submit your favorite piece of Swift or Objective-C trivia, framework arcana, hidden Xcode feature, or anything else you think is cool, and you could have it featured in the year-end blowout article. Just comment on this gist below!

If you're wondering about what to post, look to

@steipete
steipete / UITableViewMore.m
Last active January 29, 2018 14:19
Using the "More" button. Of course the simple way that Apple uses in Mail/iOS is not public. rdar://16600859
- (NSString *)tableView:(UITableView *)tableView titleForSwipeAccessoryButtonForRowAtIndexPath:(NSIndexPath *)indexPath {
return @"More";
}
- (void)tableView:(UITableView *)tableView swipeAccessoryButtonPushedForRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(@"I wanted to be a pretty public API, but then time ran out and they forgot me...");
// Hide the More/Delete menu.
[self setEditing:NO animated:YES];
}
@myokoym
myokoym / Gosu-Ruby-Tutorial-Japanese.md
Last active March 8, 2018 04:43
The Japanese translation of https://github.com/jlnr/gosu/wiki/Ruby-Tutorial (GosuのRubyチュートリアルの日本語訳)

Rubyチュートリアル

※この文書は、Ruby Tutorial · jlnr/gosu Wikiの日本語訳です。

翻訳

このチュートリアルの翻訳(中国語、スペイン語、フランス語)へのリンクについては、Homeページを参照してください。

ソースコード

@futuretap
futuretap / NSDate+Additions.m
Created March 22, 2018 10:22
relative time formatter
- (NSString*)localizedRelativeTime {
NSDateComponentsFormatter *formatter = [[NSDateComponentsFormatter alloc] init];
formatter.allowedUnits = NSCalendarUnitHour | NSCalendarUnitMinute;
formatter.unitsStyle = NSDateComponentsFormatterUnitsStyleShort;
if (self.timeIntervalSinceNow < 60 && self.timeIntervalSinceNow > -60) {
return NSLocalizedString(@"right now", @"from MapKit/Maps");
} else if (self.timeIntervalSinceNow > 0) {
NSString *start = [formatter stringFromDate:NSDate.date toDate:self];
return [NSString stringWithFormat:NSLocalizedString(@"in %@", @"placeholder: minutes/hours"), start];
} else {
/*! hsv_to_hsl.scss | MIT License | https://gist.github.com/voxpelli/1069204 */
@function max($v1, $v2) {
@return if($v1 > $v2, $v1, $v2);
}
@function min($v1, $v2) {
@return if($v1 < $v2, $v1, $v2);
}
@function hsv_to_hsl($h, $s: 0, $v: 0) {
@0xced
0xced / NSJSONSerializationError.m
Created January 22, 2016 16:23
Convoluted way to get [NSJSONSerialization dataWithJSONObject:options:error:] to return an error
// http://twitter.com/nicklockwood/status/690540488433274881
// @0xced hmm, you're right. So under what circumstances *does* it populate the error param? Why even have it at all?
// http://twitter.com/0xced/status/690543445404991488
// @nicklockwood Just disassembled again, seems it can errors if a string fails to convert to UTF8. @nst021 Idea how to produce such a string?
// http://twitter.com/mikeash/status/690564095322542081
// mikeash: @0xced @nicklockwood @nst021 Maybe try an NSString containing half of a surrogate pair.
#import <Foundation/Foundation.h>
@steipete
steipete / gist:8df39fea0d39680a7a6b
Last active September 17, 2020 23:24
Hunting down a regression in interface rotation on iOS 8 with multiple windows. (rdar://19592583)
This is the code path that changed the status bar orientation on iOS 7:
* thread #1: tid = 0x698dbf, 0x00085830 WindowRotationIssue`-[AppDelegate application:willChangeStatusBarOrientation:duration:](self=0x7a041f90, _cmd=0x0137a18d, application=0x79e39cc0, newStatusBarOrientation=UIInterfaceOrientationPortraitUpsideDown, duration=0.80000000000000004) + 96 at AppDelegate.m:23, queue = 'com.apple.main-thread', stop reason = breakpoint 3.1
* frame #0: 0x00085830 WindowRotationIssue`-[AppDelegate application:willChangeStatusBarOrientation:duration:](self=0x7a041f90, _cmd=0x0137a18d, application=0x79e39cc0, newStatusBarOrientation=UIInterfaceOrientationPortraitUpsideDown, duration=0.80000000000000004) + 96 at AppDelegate.m:23
frame #1: 0x00bb6ab5 UIKit`-[UIApplication setStatusBarOrientation:animationParameters:notifySpringBoardAndFence:] + 242
frame #2: 0x00bfa8e4 UIKit`-[UIWindow _setRotatableClient:toOrientation:updateStatusBar:duration:force:isRotating:] + 4761
frame #3: 0x00bf9646 UIKit`-[UIWi
@gruber
gruber / Reply.scpt
Last active October 22, 2020 19:48
Prompt with options to "Reply" or "Reply All" when replying to a message with multiple recipients in Apple Mail for Mac OS X. Also does away with top-posting.
tell application "Mail"
set _sel to get selection
if (count of _sel) > 1 then
-- multiple message selection, usually a conversation thread
choose from list {"Reply", "Reply All"} with prompt "Unknown recipient count." default items {"Reply"}
try
set _menu_command to item 1 of the result
on error
return