Skip to content

Instantly share code, notes, and snippets.

View christopherkarani's full-sized avatar

Christopher Karani christopherkarani

View GitHub Profile
@christopherkarani
christopherkarani / README-Template.md
Created December 7, 2017 11:38 — forked from PurpleBooth/README-Template.md
A template to make good README.md

Project Title

One Paragraph of project description goes here

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.

Prerequisites

Contributing

When contributing to this repository, please first discuss the change you wish to make via issue, email, or any other method with the owners of this repository before making a change.

Please note we have a code of conduct, please follow it in all your interactions with the project.

Pull Request Process

  1. Ensure any install or build dependencies are removed before the end of the layer when doing a
@christopherkarani
christopherkarani / us-states-array
Created January 31, 2018 11:27 — forked from iamjason/us-states-array
Swift US States Array
let state = [ "AK - Alaska",
"AL - Alabama",
"AR - Arkansas",
"AS - American Samoa",
"AZ - Arizona",
"CA - California",
"CO - Colorado",
"CT - Connecticut",
"DC - District of Columbia",
"DE - Delaware",
@christopherkarani
christopherkarani / countries.swift
Created February 1, 2018 09:11 — forked from maxgiraldo/countries.swift
All country codes including full name
let countries = [
"AF - Afghanistan",
"AX - Aland Islands",
"AL - Albania",
"DZ - Algeria",
"AS - American Samoa",
"AD - Andorra",
"AO - Angola",
"AI - Anguilla",
"AQ - Antarctica",
class ArrayImpl<T> {
var space: Int
var count: Int
var ptr: UnsafeMutablePointer<T>
init(count: Int = 0, ptr: UnsafeMutablePointer<T> = nil) {
self.count = count
self.space = count
if !UIAccessibilityIsReduceTransparencyEnabled() {
view.backgroundColor = .clear
let blurEffect = UIBlurEffect(style: .dark)
let blurEffectView = UIVisualEffectView(effect: blurEffect)
//always fill the view
blurEffectView.frame = self.view.bounds
blurEffectView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
view.addSubview(blurEffectView) //if you have more UIViews, use an insertSubview API to place it where needed
protocol Dimension {
func constraint(equalToConstant c: CGFloat) -> NSLayoutConstraint
}
protocol Anchor {
func constraint(equalTo anchor: Self, constant: CGFloat) -> NSLayoutConstraint
func constraint(greaterThanOrEqualTo anchor: Self, constant: CGFloat) -> NSLayoutConstraint
func constraint(lessThanOrEqualTo anchor: Self, constant: CGFloat) -> NSLayoutConstraint
}
/// A little pieve of genius by me that culculates cell size base on the image given while maintaining aspect ratio
open class MediaMessageSizeCalculator {
open func messageContainerSize(for image: UIImage) -> CGSize {
let maxWidth = UIScreen.main.bounds.width - 16
let sizeForMediaItem = { (maxWidth: CGFloat, item: UIImage) -> CGSize in
if maxWidth < item.size.width {
// Maintain the ratio if width is too great
let height = maxWidth * item.size.height / item.size.width
return CGSize(width: maxWidth, height: height)
}
extension UIView {
func height(constant: CGFloat) {
setConstraint(value: constant, attribute: .height)
}
func width(constant: CGFloat) {
setConstraint(value: constant, attribute: .width)
}
private func removeConstraint(attribute: NSLayoutConstraint.Attribute) {
var millisecondsSince1970: Int {
return Int(self.timeIntervalSince1970.rounded())
}
init(milliseconds: Int) {
self = Date(timeIntervalSince1970: TimeInterval(milliseconds / 1000))
}