Skip to content

Instantly share code, notes, and snippets.

View mikengyn's full-sized avatar

Mike Nguyen mikengyn

  • https://miken.design
  • Toronto
View GitHub Profile
@hilen
hilen / FLAnimatedImageView+SDWebImage.swift
Last active December 4, 2018 18:37
FLAnimatedImageView with SDWebImage
```
import Foundation
import FLAnimatedImage
import SDWebImage
import Kingfisher
/*
Add this repo(https://github.com/rs/SDWebImage) to your project
*/
extension FLAnimatedImageView {
@AshvinGudaliya
AshvinGudaliya / AGUploadImageWebServices.swift
Last active January 5, 2019 09:56
Multipart file/Images upload with parameters in Swift
//
// AGUploadImageWebServices.swift
// BaseProject
//
// Created by AshvinGudaliya on 27/02/18.
// Copyright © 2018 AshvinGudaliya. All rights reserved.
//
import UIKit
@EricShapiro
EricShapiro / Avoid Storyboards
Last active February 2, 2019 16:44
Reasons to create UI in code rather than storyboard
Reasons to create UIs in code rather than Storyboards:
Merge conflicts
Easier to diff revisions and see changes in code
More flexibility to move UI elements on iPad vs iPhone,
portrait vs landscape
Easier theme support
let a: Double? = 1.0
let b: Double? = 2.0
let c: Double? = 3.0
let d: Double? = 4.0
let e: Double? = 5.0
let f: Double? = 6.0
let g: Double? = 7.0
extension Optional {
func `or`(_ value : Wrapped?) -> Optional {
@ejmartin504
ejmartin504 / StackableWebView.swift
Created March 13, 2017 16:58
WKWebView that resizes itself
import Foundation
import WebKit
// See https://developer.apple.com/library/content/documentation/Swift/Conceptual/BuildingCocoaApps/AdoptingCocoaDesignPatterns.html for more details.
private var observerContext = 0
class StackableWebView: WKWebView {
// Keep track of height which will change when the view is loaded.
var webViewHeight: CGFloat = 0.0
@akshay1188
akshay1188 / whatsapp-image-compression
Last active June 10, 2023 16:42
Whatsapp like image compression
- (UIImage *)compressImage:(UIImage *)image{
float actualHeight = image.size.height;
float actualWidth = image.size.width;
float maxHeight = 600.0;
float maxWidth = 800.0;
float imgRatio = actualWidth/actualHeight;
float maxRatio = maxWidth/maxHeight;
float compressionQuality = 0.5;//50 percent compression
if (actualHeight > maxHeight || actualWidth > maxWidth) {
@startupcode
startupcode / HtmlToAttributedString.swift
Last active October 3, 2023 01:08
Swift - Assign HTML to NSAttributedString with custom FONT
//Usage
lbl.attributedText = htmlToAttributedString ("html text")
//Assign attributed string
func htmlToAttributedString(string : String) -> NSAttributedString{
var attribStr = NSMutableAttributedString()
do {//, allowLossyConversion: true
attribStr = try NSMutableAttributedString(data: string.dataUsingEncoding(NSUnicodeStringEncoding)!, options: [ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType], documentAttributes: nil)
@minorbug
minorbug / timeago.swift
Created November 7, 2014 15:28
"Time ago" function for Swift (based on MatthewYork's DateTools for Objective-C)
func timeAgoSinceDate(date:NSDate, numericDates:Bool) -> String {
let calendar = NSCalendar.currentCalendar()
let unitFlags = NSCalendarUnit.CalendarUnitMinute | NSCalendarUnit.CalendarUnitHour | NSCalendarUnit.CalendarUnitDay | NSCalendarUnit.CalendarUnitWeekOfYear | NSCalendarUnit.CalendarUnitMonth | NSCalendarUnit.CalendarUnitYear | NSCalendarUnit.CalendarUnitSecond
let now = NSDate()
let earliest = now.earlierDate(date)
let latest = (earliest == now) ? date : now
let components:NSDateComponents = calendar.components(unitFlags, fromDate: earliest, toDate: latest, options: nil)
if (components.year >= 2) {
return "\(components.year) years ago"
@maxcampolo
maxcampolo / NativeWebView.swift
Created July 28, 2016 13:58
WKWebView setup to make a web page adopt native behavior.
import WebKit
class NativeWebViewController: UIViewController {
let viewportScriptString = "var meta = document.createElement('meta'); meta.setAttribute('name', 'viewport'); meta.setAttribute('content', 'width=device-width'); meta.setAttribute('initial-scale', '1.0'); meta.setAttribute('maximum-scale', '1.0'); meta.setAttribute('minimum-scale', '1.0'); meta.setAttribute('user-scalable', 'no'); document.getElementsByTagName('head')[0].appendChild(meta);"
let disableSelectionScriptString = "document.documentElement.style.webkitUserSelect='none';"
let disableCalloutScriptString = "document.documentElement.style.webkitTouchCallout='none';"
override func viewDidLoad() {
// 1 - Make user scripts for injection
@angrycoffeemonster
angrycoffeemonster / Sublime Text 3 Build 3103 License Key - CRACK
Created April 18, 2016 02:13
Sublime Text 3 Build 3103 License Key - CRACK
I use the first
—– BEGIN LICENSE —–
Michael Barnes
Single User License
EA7E-821385
8A353C41 872A0D5C DF9B2950 AFF6F667
C458EA6D 8EA3C286 98D1D650 131A97AB
AA919AEC EF20E143 B361B1E7 4C8B7F04