Skip to content

Instantly share code, notes, and snippets.

View katiesmillie's full-sized avatar

Katie Smillie katiesmillie

View GitHub Profile
1.upto(100) { |i|
if i % 3 == 0 and i % 5 == 0
puts "CracklePop"
elsif i % 3 == 0
puts "Crackle"
elsif i % 5 == 0
puts "Pop"
else
puts i
@katiesmillie
katiesmillie / future.rb
Last active August 29, 2015 14:13
Code for Hacker School Application. I had never written anything from scratch, so I decided to tackle something that mimicked the basic functionality one of my side projects, a Rails app called dearfuture.me.
#!/usr/bin/env ruby
require 'yaml'
require 'date'
unless File.exist?("notes.yaml")
File.new "notes.yaml", "w"
end
note_struct = Struct::new("NoteStruct", :message_date, :message, :days_ago)
func swiftCracklePop() {
var myArray = [String]()
for i in 1...100 {
if i % 5 == 0 && i % 3 == 0 {
myArray.append("CracklePop")
} else if i % 3 == 0 {
myArray.append("Crackle")
func tappedInstagram(sharingOptionsView: SharingOptionsView) {
Analytics().track(event: "Share Instagram")
guard let instagramURL = URL(string: "instagram://app") else {return}
if UIApplication.shared.canOpenURL(instagramURL) {
guard let imageToShare = makeCompositeToShare() else { return }
let imageData = UIImageJPEGRepresentation(imageToShare, 1.0)
do {
func tappedFacebook(sharingOptionsView: SharingOptionsView) {
Analytics().track(event: "Share Facebook")
guard let imageToShare = makeCompositeToShare() else { return }
let photo = FBSDKSharePhoto()
photo.image = imageToShare
photo.isUserGenerated = true
let content = FBSDKSharePhotoContent()
content.photos = [photo]
FBSDKShareDialog.show(from: self, with: content, delegate: nil)
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
UIDevice.current.setValue(UIInterfaceOrientation.portrait.rawValue, forKey: "orientation")
}
@katiesmillie
katiesmillie / gist:833c67cd9be8d1603eed9ae9c071e087
Created December 5, 2016 15:38
UIImage Extension Swift 3 - Change Alpha & Scale / Change Size
extension UIImage {
func alpha(value: CGFloat) -> UIImage {
let format = UIGraphicsImageRendererFormat()
return UIGraphicsImageRenderer(size: size, format: format).image { _ in
draw(at: CGPoint.zero, blendMode: .normal, alpha: value)
}
}
func imageByAddingBorder(width: CGFloat, color: UIColor) -> UIImage? {
UIGraphicsBeginImageContext(self.size)
let imageRect = CGRect(x: 0, y: 0, width: self.size.width, height: self.size.height)
self.draw(in: imageRect)
let context = UIGraphicsGetCurrentContext()
let borderRect = imageRect.insetBy(dx: width / 2, dy: width / 2)
context?.setStrokeColor(color.cgColor)
@katiesmillie
katiesmillie / Date+Extension.swift
Created January 27, 2017 15:56
Time Ago String Swift 3
extension: Date {
var timeAgoString: String {
let interval = Calendar.current.dateComponents([.year, .month, .day, .hour], from: self, to: Date())
if let year = interval.year, year > 0 {
return year == 1 ? "\(year) year ago" : "\(year) years ago"
} else if let month = interval.month, month > 0 {
return month == 1 ? "\(month) month ago" : "\(month) months ago"
} else if let day = interval.day, day > 0 {
@katiesmillie
katiesmillie / CircleProgressView.swift
Created February 16, 2017 20:59
Circular Progress View (starts at the 12:00 position like App Store or Netflix downloading indicator)
// Adapated from https://www.raywenderlich.com/94302/implement-circular-image-loader-animation-cashapelayer
// Swift 3
// Init with frame size or set in storyboard and use an IBOutlet
// Set end stroke to 1 and animate with duration, or pass in the progress (between 0 and 1) while downloading, etc
class CircleProgressView: UIView {
let circlePathLayer = CAShapeLayer()
let circleRadius: CGFloat = 10.0