This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
override func viewWillDisappear(_ animated: Bool) { | |
super.viewWillDisappear(animated) | |
UIDevice.current.setValue(UIInterfaceOrientation.portrait.rawValue, forKey: "orientation") | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 |
OlderNewer