Skip to content

Instantly share code, notes, and snippets.

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

Jonathan McAllister Joony

🏠
Working from home
  • Copenhagen, Denmark
View GitHub Profile
@Joony
Joony / node-test-server
Created June 23, 2011 08:02
A Node.js test server
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}).listen(8080);
console.log('Server running.');
@Joony
Joony / cssdoc.grammar
Created December 14, 2011 16:11
PEG grammar for CSSDoc
start
= yarr*
yarr
= __ docComment:docComment __ {
return docComment
}
docComment
= comment:comment lineTerminator styles:styles* __ orphanStyles* {
@Joony
Joony / HexToUIColorMacro.m
Created March 1, 2012 09:27
On Objective-C Macro for converting Hex values (or any number) to a UIColor object.
#define UIColorFromRGBA(rgbaValue) [UIColor colorWithRed:((float)((rgbaValue & 0xFF0000) >> 16)) / 255.0 \
green:((float)((rgbaValue & 0xFF00) >> 8)) / 255.0 \
blue:((float)(rgbaValue & 0xFF)) / 255.0 \
alpha:((float)((rgbaValue & 0xFF000000) >> 24)) / 255.0]
@Joony
Joony / gist:1948567
Created March 1, 2012 09:37
Objective-C string formats.
NSString *hexString = [NSString stringWithFormat:@"0x%02x%02x%02x%02x", alpha, red, green, blue]; // Will output 0x00000000 to 0xFFFFFFFF
@Joony
Joony / <#Class#>ViewController.h
Created March 23, 2012 17:40
Storyboard delegate pattern to return from a View.
@class <#Class#>ViewController;
@protocol <#Class#>ViewControllerDelegate <NSObject>
- (void)<#class#>ViewControllerDidCancel:(<#Class#>ViewController *)controller;
@end
// Interface
import Foundation
infix operator >=>: MonadPrecedenceRight
infix operator =>=: MonadPrecedenceRight
infix operator =>>: MonadPrecedenceRight
infix operator <^>: ApplicativePrecedence
infix operator <*>: ApplicativePrecedence
precedencegroup ApplicativePrecedence {
associativity: left
@Joony
Joony / SuperEllipse.swift
Created August 7, 2018 13:51
Create a super-ellipse, similar to Apple's app icons. Creates all the correct points so you can animate correctly between super-ellipses with different corners.
struct SuperEllipse {
static func superEllipse(forRect rect: CGRect, topRightCornerRadius trcr: CGFloat, bottomRightCornerRadius brcr: CGFloat, bottomLeftCornerRadius blcr: CGFloat, topLeftCornerRadius tlcr: CGFloat) -> UIBezierPath {
let trcr = 1.2 * trcr
let brcr = 1.2 * brcr
let blcr = 1.2 * blcr
let tlcr = 1.2 * tlcr
let path = UIBezierPath()
@Joony
Joony / gist:0580d7207bbfee29daf53a0fe841afaa
Created September 27, 2018 14:32
Find Ambiguous Constraints
expr -l Swift -- import UIKit
expr -l Swift -- unsafeBitCast(0x6000001d6350, to: UIView.self).backgroundColor = UIColor.red
@Joony
Joony / #FirebaseUserPublisher-Example.swift
Last active March 10, 2022 09:52
A Swift Combine publisher that publishes updates to the Firebase Auth User.
// Get notified of changes to the uid (logged in user).
let cancellable = FirebaseUserPublisher()
.map(\.?.uid)
.removeDuplicates()
.sink { userId in
guard let user = userId else {
// No user
return
}
print(userId)
@Joony
Joony / #AppStorageObject-Example.swift
Created March 10, 2022 14:15
An example of how to save an array in AppStorage (SwiftUI)
@AppStorage("saved_array") var savedArray = ArrayTypeToSave()
savedArray = ["Hello", "World"]