Skip to content

Instantly share code, notes, and snippets.

@zef
zef / gist:4080042
Created November 15, 2012 17:46
Shell commands for seeing space taken by .log files and truncating them.
# how much space is being taken up by .log files?
find . -regex '.*\.log' -exec du -hc {} +
# recursively clear all .log files in current directory
find . -regex '.*\.log' -exec cp /dev/null {} \;
# view .log files sorted by file size
find . -regex '.*\.log' -print0 | xargs -0 du | sort -gr
@zef
zef / check_image_dimensions.rb
Created December 3, 2013 18:39
Prints a list of @2x assets that have odd dimensions. Requires imagemagick and the mini_magick gem.
require 'mini_magick'
root_path = '/Users/zef/Dropbox/code/some_project'
local_path = 'some_project/assets'
path = File.join(root_path, local_path, '**.png')
list = []
Dir.glob(path).each do |file|
@zef
zef / gist:10904278
Created April 16, 2014 16:37
Was messing with replacing color in an image with another color. Didn't work that well, mostly saturation and brightness problems
- (UIImage *)imageByShiftingFromColor:(UIColor *)startColor toColor:(UIColor *)endColor
{
CGFloat startHue, startSaturation, startBrightness, startAlpha;
BOOL parsedStartColor = [startColor getHue:&startHue saturation:&startSaturation brightness:&startBrightness alpha:&startAlpha];
NSLog(@"start success: %i hue: %0.2f, saturation: %0.2f, brightness: %0.2f, alpha: %0.2f", parsedStartColor, startHue, startSaturation, startBrightness, startAlpha);
CGFloat endHue, endSaturation, endBrightness, endAlpha;
BOOL parsedEndColor = [endColor getHue:&endHue saturation:&endSaturation brightness:&endBrightness alpha:&endAlpha];
NSLog(@"end success: %i hue: %0.2f, saturation: %0.2f, brightness: %0.2f, alpha: %0.2f", parsedEndColor, endHue, endSaturation, endBrightness, endAlpha);
@zef
zef / bb.rb
Created November 11, 2014 04:57 — forked from jerodsanto/bb.rb
#!/usr/bin/env ruby
if remote = `git remote -v`.lines.find { |l| l.match /bitbucket/ }
matches = remote.match /(?<domain>bitbucket.org).(?<path>.*)\.git/
url = "https://#{matches[:domain]}/#{matches[:path]}"
branch = `git symbolic-ref --short HEAD`.lines.first
url += "/branch/#{branch}"
system "open #{url}"
@zef
zef / NSURL+QueryDictionary.swift
Created October 16, 2015 17:14
Swift NSURL extension to turn the query into a dictionary
extension NSURL {
var queryDictionary: [String: String] {
guard let components = NSURLComponents(string: absoluteString), items = components.queryItems else { return [:] }
return items.reduce([:]) { dictionary, item in
var dictionary = dictionary
dictionary[item.name] = item.value
return dictionary
}
}
@zef
zef / value-enumerable.swift
Last active January 21, 2016 14:56
Example of Swift enum with allValues array containing constructors for cases with associated values
protocol ValueEnumerable {
static var allValues: [Any] { get }
}
enum ColorScheme: ValueEnumerable {
typealias SchemeTuple = (name: String, background: UIColor, foreground: UIColor, border: UIColor)
case Light
case Dark
case custom(SchemeTuple)
@zef
zef / keybase.md
Created April 7, 2016 04:14
keybase.md

Keybase proof

I hereby claim:

  • I am zef on github.
  • I am zef (https://keybase.io/zef) on keybase.
  • I have a public key whose fingerprint is F64A 8E5B F886 3060 D810 54AC D97C 988F 6778 C42C

To claim this, I am signing this object:

@zef
zef / Reusable.swift
Created March 14, 2019 21:17
Reusable cells for iOS
//
// Reusable.swift
//
// Created by Zef Houssney
//
import UIKit
protocol Reusable {
static var reuseIdentifier: String { get }
@zef
zef / Puralizable.swift
Last active December 17, 2019 17:50
A simple protocol to enable a collection of Pluralizable objects to return either the singular or the plural, depending on the count of the collection.
protocol Pluralizable {
static var singular: String { get }
// Override with the correct plural, if simply appending an "s" is incorrect
static var plural: String { get }
}
extension Pluralizable {
static var singular: String {
return String(describing: self)
}
@zef
zef / CollectionView.swift
Created January 16, 2020 22:50
A layout similar to a CollectionViewFlowLayout, but in SwiftUI.
// Created by Zef Houssney on 1/9/20.
// This takes some inspiration from https://gist.github.com/chriseidhof/3c6ea3fb2102052d1898d8ea27fbee07
// but uses a different approach.
// Instead of trying to calculate the position of each item and placing them manually using calculated coordinates,
// this calculates the amount of space each item wants to take up, then splits the items into rows that should fit
// within the available width.
// Then, the views are distributed into rows, made up of an HStack for each row inside a VStack.
//
// This seems non-conventional, but I was having trouble getting the frame of my top-level view to be respected when returning