Skip to content

Instantly share code, notes, and snippets.

@ostholz
ostholz / rails render options
Created July 17, 2015 09:29
Rails Render Options
render :edit
render action: :edit
render "edit"
render "edit.html.erb"
render action: "edit"
render action: "edit.html.erb"
render "books/edit"
render "books/edit.html.erb"
render template: "books/edit"
render template: "books/edit.html.erb"
__weak __typeof(self) weakSelf = self;
[self doSomeThingWithBlock:^(void) {
if (weakSelf) {
__strong __typeof(weakSelf) strongSelf = weakSelf;
strongSelf.someProperty = someValue;
[strongSelf performSomeMethod];
}
}];
###show all envirement variables
xcodebuild -workspace appname.xcworkspace -scheme scheme -showBuildSettings
xcodebuild -project appname.xcproj -target target -showBuildSettings
// copy from https://www.craftappco.com/blog/2018/5/30/simple-throttling-in-swift
class Throttler {
private var workItem: DispatchWorkItem = DispatchWorkItem(block: {})
private var previousRun: Date = Date.distantPast
private let queue: DispatchQueue
private let minimumDelay: TimeInterval
init(minimumDelay: TimeInterval, queue: DispatchQueue = DispatchQueue.main) {
self.minimumDelay = minimumDelay
@ostholz
ostholz / Handy_UIView_Autolayout
Created October 15, 2021 18:41
Handy AutoLayout Extension
extension UIView {
/**
* Set aspect ratio for self
*
* Examples: there is a view `v`
* v.aspectRatio(ratio: 2.0)
*/
public func aspectRatio(ratio: CGFloat) {
self.translatesAutoresizingMaskIntoConstraints = false
@ostholz
ostholz / Log.swift
Last active August 24, 2023 06:17
Log function
//
// Logger.swift
//
// Created by on 24.01.20.
//
import Foundation
import os.log
public struct Logger {
@ostholz
ostholz / LLDB
Created November 11, 2021 11:00
LLDB Commands
### Print swift object at address
`e -l swift -O -- 0xaddress`
### print ObjectivC object at address
`e -l objc -O -- 0xaddress`