Skip to content

Instantly share code, notes, and snippets.

View milanpanchal's full-sized avatar
🏠
Working from home

Milan Panchal milanpanchal

🏠
Working from home
View GitHub Profile
@JohnSundell
JohnSundell / AnyOf.swift
Created August 21, 2017 21:23
A way to easily compare a given value against an array of candidates
import Foundation
struct EquatableValueSequence<T: Equatable> {
static func ==(lhs: EquatableValueSequence<T>, rhs: T) -> Bool {
return lhs.values.contains(rhs)
}
static func ==(lhs: T, rhs: EquatableValueSequence<T>) -> Bool {
return rhs == lhs
}
@milanpanchal
milanpanchal / CSwift.swift
Created February 9, 2017 08:39 — forked from ankitspd/CSwift.swift
Swift ++ operator
prefix func ++(inout x: Int) -> Int {
x = x + 1
return x
}
postfix func ++(inout x: Int) -> Int {
let oldX = x
x = x + 1
return oldX
}
@bright23
bright23 / DeviceConst.swift
Created November 26, 2016 05:34
DeviceConst.swift
//
// AppConst.swift
// AdBlockSample
//
// Created by bright on 2016/11/26.
// Copyright © 2016年 bright. All rights reserved.
//
import Foundation
import UIKit
import Foundation
extension UITextField {
func containsOnlyNumbers(string: String, maximumDecimalPlaces: NSInteger, maximumValue: NSInteger) -> Bool {
// Check that textfield only contains allowed number of decimal places (this can also be done in regex, but avoiding so that is easier to understand and debug
if string.characters.contains(".") {
if string.componentsSeparatedByString(".").count > 2 {
return false
} else {
let newStringSplitAtDecimal = string.componentsSeparatedByString(".")
extension PHPhotoLibrary {
typealias PhotoAsset = PHAsset
typealias PhotoAlbum = PHAssetCollection
static func saveImage(image: UIImage, albumName: String, completion: (PHAsset?)->()) {
if let album = self.findAlbum(albumName) {
saveImage(image, album: album, completion: completion)
return
}
@paulomcnally
paulomcnally / OperatorInfo.swift
Created January 21, 2016 01:59
Swift MCCMNC
import Foundation
import CoreTelephony
class OperatorInfo {
func id() -> String {
let networkInfo = CTTelephonyNetworkInfo()
let carrier = networkInfo.subscriberCellularProvider
let mcc = carrier!.mobileCountryCode
let mnc = carrier!.mobileNetworkCode
@ankitspd
ankitspd / CSwift.swift
Created December 14, 2015 19:37
Swift ++ operator
prefix func ++(inout x: Int) -> Int {
x = x + 1
return x
}
postfix func ++(inout x: Int) -> Int {
let oldX = x
x = x + 1
return oldX
}
@victorchee
victorchee / KeyboardNotification.m
Created December 10, 2015 06:25
Handle keyboard notification
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillChangeFrame:) name:UIKeyboardWillChangeFrameNotification object:nil];
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
[[NSNotificationCenter defaultCenter] removeObserver:self];
@victor-codestuffs
victor-codestuffs / .bash_profile
Last active December 10, 2015 18:29
Aliased git commands
alias gs='git status'
alias gsu='git status -uno'
alias gp='git pull --rebase'
alias gl='git log'
alias glf='git log -p'
alias glp='git log --pretty=oneline'
alias glg='git log --pretty=format:"%h %s" --graph'
alias gd='git diff'
alias gss='git stash save'
alias gsl='git stash list'
@joseluisq
joseluisq / terminal-git-branch-name.md
Last active April 20, 2024 02:26
Add Git Branch Name to Terminal Prompt (Linux/Mac)

Add Git Branch Name to Terminal Prompt (Linux/Mac)

image

Open ~/.bash_profile in your favorite editor and add the following content to the bottom.

# Git branch in prompt.

parse_git_branch() {