Skip to content

Instantly share code, notes, and snippets.

View hemangshah's full-sized avatar
🎯
Focusing

Hemang hemangshah

🎯
Focusing
  • Stockholm, Stockholm County, Sweden
View GitHub Profile
@reloni
reloni / gist:62a09f0e67631f62e38b5a3566e0f6bf
Last active April 17, 2018 03:55
Add blur to UITableView (Swift 3)
tableView.backgroundColor = UIColor.clear()
let blurEffect = UIBlurEffect(style: .light)
let blurEffectView = UIVisualEffectView(effect: blurEffect)
tableView.backgroundView = blurEffectView
@benbahrenburg
benbahrenburg / BaseController.swift
Last active October 4, 2018 16:57
Adding Consistent Back Button to view
import UIKit
class BaseViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let backTitle = NSLocalizedString("Back", comment: "Back button label")
self.addBackbutton(backTitle)
@roytornado
roytornado / AppDelegate.swift
Last active December 17, 2018 05:57
iOS Remote Notification
import UIKit
import Firebase
import UserNotifications
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
static var shared: AppDelegate { return UIApplication.shared.delegate as! AppDelegate }
@TheAlienMann
TheAlienMann / Grab The City
Last active December 8, 2019 15:58
"Grab The City" is a challenge that wants you to extract the name of the city in a given sentence which the name is wrapped in a pair of square brackets in the end of the sentence.
func grabCity(_ str: String) -> String {
// the commented line below (the regex to be exact) gets just the last word! which is wrong, my fault though, i didn't read the challenge corectly!
// let regex = try! NSRegularExpression(pattern: "(\\w+)(?!.*\\w)", options: [])
// the regex below get every matches in the sentence that is being wrapped in a pair of square brackets.
let regex = try! NSRegularExpression(pattern: "(?<=\\[)(.+?)(?=\\])", options: [])
// the "result" below is of type NSTextCheckingResult which is an array, since the challenge askes for the last match, and i couldn't get the last match through the regex, i ened up gtting the last match via the "last" item in the array.
let result = regex.matches(in: str, options: [], range: NSRange(location: 0, length: str.count)).last
/*
// from line 11 to 18, is an alternative for getting the matches out of the result array, since it is an array (of type NSTextCheckingResult) you can iterate thtough it (loop though it)
// you can use each o
@lukeredpath
lukeredpath / LICENSE
Last active March 22, 2020 08:21
A decorator around UILocalizedIndexedCollation that automatically adds the search icon. Updated to support ARC.
Copyright (c) 2010 Luke Redpath
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
import UIKit
enum LayoutableButtonVerticalAlignment: String {
case center
case top
case bottom
case unset
}
enum LayoutableButtonHorizontalAlignment: String {
@pietrobasso
pietrobasso / ExtractYouTubeId.playground
Last active October 7, 2020 22:59 — forked from zdk/extract_youtube_id.mm
A Regex to extract YouTube video ids from the given list of youtube URLs in Swift 4
//: Playground - noun: a place where people can play
//
// Created by Pietro Basso on 29/06/2018.
// Copyright (c) 2018 Pietro Basso. All rights reserved.
//
let urls = ["http://youtu.be/NLqAF9hrVbY",
"http://www.youtube.com/watch?feature=player_embedded&v=DJjDrajmbIQ",
"http://www.youtube.com/watch?v=dQw4w9WgXcQ",
"http://www.youtube.com/embed/NLqAF9hrVbY",
@gbitaudeau
gbitaudeau / LayoutableButton.swift
Last active April 2, 2021 08:38
I created a UIButton subclass whose purpose is to be able to choose where the button's image is layout, either vertically or horizontally. See http://stackoverflow.com/a/41744464/1661338
// Created by Guillaume BITAUDEAU on 19/01/2017.
// @see : http://stackoverflow.com/a/41744464/1661338
import UIKit
@IBDesignable
class LayoutableButton: UIButton {
enum VerticalAlignment : String {
@danielphillips
danielphillips / UILabel+dynamicSizeMe.h
Created June 2, 2011 22:54
Adjust UILabel to change it's frame according to it's content
@interface UILabel (dynamicSizeMe)
-(float)resizeToFit;
-(float)expectedHeight;
@end