Skip to content

Instantly share code, notes, and snippets.

View jesskturner's full-sized avatar

Jessica Turner jesskturner

View GitHub Profile
@jesskturner
jesskturner / LimitHasMany.rb
Created April 14, 2016 14:01
Limit has_many associations to a set limit
class User
has_many :things
end
class Thing
belongs_to :user
validate :on => :create do
if user && user.things.length >= thing_limit
errors.add(:user, :too_many_things)
end
@jesskturner
jesskturner / fontlog.swift
Created January 26, 2016 18:42
Log iOS Font Names, Swift
for family: String in UIFont.familyNames()
{
print("family: \(family)")
for names: String in UIFont.fontNamesForFamilyName(family)
{
print("== \(names)")
}
}
@jesskturner
jesskturner / fontlog.m
Created January 26, 2016 18:41
Log iOS Font Names, Objective-C
for (NSString* family in [UIFont familyNames])
{
NSLog(@"family: %@", family);
for (NSString* name in [UIFont fontNamesForFamilyName: family])
{
NSLog(@" %@", name);
}
}
@jesskturner
jesskturner / string-truncate.swift
Last active March 18, 2018 17:37 — forked from aorcsik/string-truncate.swift
A little truncate function extension for the default String type
extension String {
/// Truncates the string to length number of characters and
/// appends optional trailing string if longer
func truncate(length: Int, trailing: String? = nil) -> String {
if self.characters.count > length {
return self.substringToIndex(self.startIndex.advancedBy(length)) + (trailing ?? "")
} else {
return self
}
}