Skip to content

Instantly share code, notes, and snippets.

View mohshin-shah's full-sized avatar

Mohshin Shah mohshin-shah

View GitHub Profile
@mohshin-shah
mohshin-shah / String+subscript.swift
Created November 18, 2022 04:18 — forked from foxicode/String+subscript.swift
Swift String subscript extension
import Foundation
extension String {
subscript (i: Int) -> Character {
return self[index(startIndex, offsetBy: i)]
}
subscript (bounds: CountableRange<Int>) -> Substring {
let start = index(startIndex, offsetBy: bounds.lowerBound)
let end = index(startIndex, offsetBy: bounds.upperBound)
@mohshin-shah
mohshin-shah / clean_code.md
Created August 26, 2020 06:48 — forked from wojteklu/clean_code.md
Summary of 'Clean code' by Robert C. Martin

Code is clean if it can be understood easily – by everyone on the team. Clean code can be read and enhanced by a developer other than its original author. With understandability comes readability, changeability, extensibility and maintainability.


General rules

  1. Follow standard conventions.
  2. Keep it simple stupid. Simpler is always better. Reduce complexity as much as possible.
  3. Boy scout rule. Leave the campground cleaner than you found it.
  4. Always find root cause. Always look for the root cause of a problem.

Design rules

class Solution {
func compareVersion(version1: String, _ version2: String) -> Int {
var v1 = version1.characters.split(".").map { Int(String($0)) }
var v2 = version2.characters.split(".").map { Int(String($0)) }
var result = 0
for i in 0..<max(v1.count,v2.count) {
let left = i >= v1.count ? 0 : v1[i]
let right = i >= v2.count ? 0 : v2[i]
if (left == right) {
//
// UILabel+JumpingDots.swift
// JumpingDots
//
// Copyright (c) 2016 Arkadiusz Holko. All rights reserved.
//
import UIKit
import ObjectiveC
struct S0<V> {
typealias F = () -> V
}
struct S1<T1,V>{
typealias F = (T1) -> V
}
//0, 0
func curry<T1, V>(f: S1<T1, V>.F, a1:T1) -> S0<V>.F {
@mohshin-shah
mohshin-shah / dispatch.swift
Created October 18, 2016 07:52 — forked from amw/dispatch.swift
Swift wrapper for Grand Central Dispatch (GCD)
//
// dispatch.swift
//
// Created by Adam Wróbel. Read more at:
// http://adamwrobel.com/blog/2016/05/08/swift-gcd-wrapper/
//
import Foundation
internal extension dispatch_queue_t {
@mohshin-shah
mohshin-shah / README.md
Created October 17, 2016 08:45 — forked from cgrieger/README.md
Fixing git ssl client certs on OSX Mavericks

git clone - SSLRead() return error -9824

  1. Run fix.sh

  2. git is installed to /opt/git

  3. Add git to path

echo "export PATH=/opt/git/bin:$PATH" &gt;&gt; ~/.bash_profile
@mohshin-shah
mohshin-shah / example.m
Created March 30, 2016 09:53 — forked from Kozlov-V/example.m
upload task in background using afnetworking + progress
Use:
NSURLSessionConfiguration:backgroundSessionConfiguration:
instead of
NSURLSessionConfiguration:defaultSessionConfiguration
From the NSURLSessionConfiguration:backgroundSessionConfiguration: documentation:
Upload and download tasks in background sessions are performed by an external daemon instead of by the app itself. As a result, the transfers continue in the background even if the app is suspended, exits, or crashes.
So in your case, change: