Skip to content

Instantly share code, notes, and snippets.

Avatar

Jessica Turner jesskturner

View GitHub Profile
@jesskturner
jesskturner / LimitHasMany.rb
Created Apr 14, 2016
Limit has_many associations to a set limit
View LimitHasMany.rb
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 Jan 26, 2016
Log iOS Font Names, Swift
View fontlog.swift
for family: String in UIFont.familyNames()
{
print("family: \(family)")
for names: String in UIFont.fontNamesForFamilyName(family)
{
print("== \(names)")
}
}
@jesskturner
jesskturner / fontlog.m
Created Jan 26, 2016
Log iOS Font Names, Objective-C
View fontlog.m
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 Mar 18, 2018 — forked from aorcsik/string-truncate.swift
A little truncate function extension for the default String type
View string-truncate.swift
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
}
}