Skip to content

Instantly share code, notes, and snippets.

@neonichu
neonichu / generics.swift
Created December 29, 2014 20:32
WTF Swift generics?
#!/usr/bin/env xcrun swift
import Foundation
class Base {
}
class Sub : Base {
}
@neonichu
neonichu / zama.rb
Created May 27, 2015 18:47
Do a development Pod install and archive the corresponding framework via Carthage automatically.
#!/usr/bin/env ruby
require 'cocoapods'
require 'fileutils'
def podfile_from_spec(spec)
podfile = File.open('Podfile', 'w')
podfile.write(<<-EOF
platform :ios, '8.0'
@cloudhead
cloudhead / haskell-fiddling.hs
Created August 28, 2009 01:50
learning haskell
doubleMe x = x + x
doubleUs x y = doubleMe x + doubleMe y
doubleSmallNumber x = if x < 100
then x * 2
else x
eoeo xs = [if mod x 2 == 0 then 'e' else 'o' | x <- xs]
length'' xs = sum [1 | _ <- xs]
combo xs ys = [x ++ " " ++ y | x <- xs, y <- ys]
nestedEven xxs = [[ x | x <- xs, even x] | xs <- xxs]
@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

public struct Error: ErrorType {
let source: String; let reason: String
public init(_ source: String = __FILE__, _ reason: String) {
self.reason = reason; self.source = source
}
}
protocol Contextualizable {}
extension Contextualizable {
func functionContext(function : String = __FUNCTION__) -> String {
// gem install cocoapods-playgrounds
// pod playgrounds LibYAML
// Update: @floriankugler had a great idea to use UnsafeBufferPointer
// Paste in the following:
import LibYAML
public struct YAMLError: ErrorType {
@steipete
steipete / gist:d76549ec262430354e7c
Last active December 3, 2018 23:56
Our set of warnings in PSPDFKit
//
// Warnings.xcconfig
//
// The list of warnings we (don’t) use, and the reasons why.
//
// :MARK: Warnings in use:
// :MARK: -everything
// We want the best possible diagnostics, so we simply enable everything that exists, and then opt–out of what doesn’t make sense for us.
//
// :MARK: - Warnings not to be promoted:
@zats
zats / script.swift
Last active March 5, 2021 01:32
Update all your plugins for the latest Xcode beta with a single
#!/usr/bin/env xcrun swift
// $ chmod +x script.swift
// $ ./script.swift
// or $ ./script.swift -xcode=/Applications/Xcode-beta.app
import Foundation
@noreturn private func failWithError(message: String) {
print("🚫 \(message)")
@kevinmcmahon
kevinmcmahon / gist:2295471
Created April 3, 2012 20:59
Create a 1x1 UIImage from a UIColor
- (UIImage *)imageWithColor:(UIColor *)color {
CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [color CGColor]);
CGContextFillRect(context, rect);
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
@KrauseFx
KrauseFx / orta_gifs.rb
Last active March 29, 2022 22:33
This gist opens all orta gifs in your browser
# taken from https://gist.github.com/orta/694004c20becead3ce1f
urls = %w[
https://ortastuff.s3.amazonaws.com/gifs/bike.gif
https://ortastuff.s3.amazonaws.com/gifs/bug-hunting.gif
https://ortastuff.s3.amazonaws.com/gifs/cheers-boxing.gif
https://ortastuff.s3.amazonaws.com/gifs/clap-2.gif
https://ortastuff.s3.amazonaws.com/gifs/clap.gif
https://ortastuff.s3.amazonaws.com/gifs/danger.gif
https://ortastuff.s3.amazonaws.com/gifs/delisa-nah.gif
https://ortastuff.s3.amazonaws.com/gifs/delisa-one-thumb.gif