Skip to content

Instantly share code, notes, and snippets.

@dabrahams
dabrahams / ModuleRepl.md
Last active May 18, 2021 00:16
Linking and importing a swift module for use in the REPL
$ echo 'public func f() { print("YES") }' > x.swift
$ swiftc -emit-library -emit-module -module-link-name x  x.swift
$ swift -L . -I .
Welcome to Apple Swift version 5.4 (swiftlang-1205.0.26.9 clang-1205.0.19.55).
Type :help for assistance.
  1> import x
import x
  2> f()
f()
@acrookston
acrookston / README.md
Last active January 26, 2022 11:05
Xcode pre-action to build custom Info.plist

Automatic build versions from git in Xcode (and other goodies)

Installation procedure for pre-build actions to automatically populate Xcode Info.plist with dynamic data.

1. Xcode Scheme pre-action

Edit Xcode Scheme and add a pre-action script. Copy the contents of preaction.sh into the pre-action script box.

@kaishin
kaishin / snapshot.swift
Created January 10, 2016 14:29
NSView Snapshot
extension NSView {
var snapshot: NSImage {
guard let bitmapRep = bitmapImageRepForCachingDisplayInRect(bounds) else { return NSImage() }
bitmapRep.size = bounds.size
cacheDisplayInRect(bounds, toBitmapImageRep: bitmapRep)
let image = NSImage(size: bounds.size)
image.addRepresentation(bitmapRep)
return image
}
}
@eliburke
eliburke / NSUUID+uuid5.h
Created May 1, 2015 17:55
iOS NSUUID category for calculating an RFC4122 compliant uuid5. Tested / compatible with python's uuid.uuid5
//
// NSUUID+uuid5.h
//
// MIT License (aka, do with it what you want)
//
// Copyright (c) 2015 Eli Burke eburke@pobox.com
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software
// and associated documentation files (the "Software"), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge, publish, distribute,
@ajayjapan
ajayjapan / gist:5e7ba49e51f1ca24b76d
Created August 28, 2014 18:16
Adjust content size of collection view when flexible iOS 8 simulator size changes
@interface UICollectionViewFlowLayout (InvalidateOnBoundsChange)
@end
@implementation UICollectionViewFlowLayout (InvalidateOnBoundsChange)
- (UICollectionViewLayoutInvalidationContext *)invalidationContextForBoundsChange:(CGRect)newBounds {
UICollectionViewLayoutInvalidationContext *context = [super invalidationContextForBoundsChange:newBounds];
CGRect oldBounds = self.collectionView.bounds;
CGFloat widthAdjustment = newBounds.size.width - oldBounds.size.width;
@bunnyhero
bunnyhero / ReusableCellExample.m
Last active February 19, 2022 02:04
Example of Reactive Cocoa binding for a reusable cell.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell =
[tableView dequeueReusableCellWithIdentifier:REUSABLE_CELL_ID];
UILabel *label = (UILabel *)[cell viewWithTag:VIEW_TAG];
Model *someModel = [self getModelFromIndexPath:indexPath];
// `takeUntil:` makes the RACObserve() signal complete (and thus breaks the subscription)
// when the cell is recycled.
@lfender6445
lfender6445 / gist:9919357
Last active July 25, 2024 02:05
Pry Cheat Sheet

Pry Cheat Sheet

Command Line

  • pry -r ./config/app_init_file.rb - load your app into a pry session (look at the file loaded by config.ru)
  • pry -r ./config/environment.rb - load your rails into a pry session

Debugger

@bradmontgomery
bradmontgomery / dummy-web-server.py
Last active July 25, 2024 03:38
a minimal http server in python. Responds to GET, HEAD, POST requests, but will fail on anything else.
#!/usr/bin/env python
"""
Very simple HTTP server in python (Updated for Python 3.7)
Usage:
./dummy-web-server.py -h
./dummy-web-server.py -l localhost -p 8000
Send a GET request: