Skip to content

Instantly share code, notes, and snippets.

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

Saroar Khandoker saroar

🏠
Working from home
View GitHub Profile
@saroar
saroar / combine-retry.md
Created September 1, 2020 19:23 — forked from dry1lud/combine-retry.md
Retry operation in Swift/Combine.

There is a function .retry() in Combine that helps to retry a request. Although it is not enough just to call retry() to achieve retring logic. The retry() function does not do another request but it re-subscribes only to a publisher. To make another request the tryCatch() might be used. In the code below if the first call fails there are three attempts to retry (retry(3)):

import UIKit
import Combine
import PlaygroundSupport

enum CustomNetworkingError: Error {
    case invalidServerResponse
}
@saroar
saroar / letsencrypt_2020.md
Created June 14, 2020 08:11 — forked from cecilemuller/letsencrypt_2020.md
How to setup Let's Encrypt for Nginx on Ubuntu 18.04 (including IPv6, HTTP/2 and A+ SSL rating)

How to setup Let's Encrypt for Nginx on Ubuntu 18.04 (including IPv6, HTTP/2 and A+ SLL rating)


Virtual hosts

Let's say you want to host domains first.com and second.com.

Create folders for their files:

@saroar
saroar / nginx.conf
Created June 14, 2020 07:52 — forked from nrollr/nginx.conf
NGINX config for SSL with Let's Encrypt certs
# UPDATED 17 February 2019
# Redirect all HTTP traffic to HTTPS
server {
listen 80;
listen [::]:80;
server_name www.domain.com domain.com;
return 301 https://$host$request_uri;
}
# SSL configuration
@saroar
saroar / xcode-how-to-backtrace.md
Created May 5, 2020 08:47 — forked from weissi/xcode-how-to-backtrace.md
xcode-how-to-backtrace.md

@saroar
saroar / benchmarkSwift.swift
Created September 29, 2019 09:10 — forked from minikin/benchmarkSwift.swift
Benchmark Swift code execution
/*
The former will log out the time required for a given section of code, with the latter returning that as a float.
Read more : http://stackoverflow.com/questions/25006235/how-to-benchmark-swift-code-execution
*/
func printTimeElapsedWhenRunningCode(title:String, operation:()->()) {
let startTime = CFAbsoluteTimeGetCurrent()
operation()
@saroar
saroar / mac-setup-redis.md
Created May 18, 2019 06:37 — forked from tomysmile/mac-setup-redis.md
Brew install Redis on Mac

type below:

brew update
brew install redis

To have launchd start redis now and restart at login:

brew services start redis
@saroar
saroar / P12toPEM.txt
Created March 3, 2019 20:03 — forked from shahdhiren/P12toPEM.txt
Convert P12 file for Push Notification to PEM format
Development Phase:
Step 1: Create Certificate .pem from Certificate .p12
Command: openssl pkcs12 -clcerts -nokeys -out apns-dev-cert.pem -in apns-dev-cert.p12
Step 2: Create Key .pem from Key .p12
Command : openssl pkcs12 -nocerts -out apns-dev-key.pem -in apns-dev-key.p12
Step 3: Optional (If you want to remove pass phrase asked in second step)
Command : openssl rsa -in apns-dev-key.pem -out apns-dev-key-noenc.pem
@saroar
saroar / gist:9dbc233d4f0d15ad4dfcccbe74490209
Created July 24, 2018 14:09 — forked from CristinaSolana/gist:1885435
Keeping a fork up to date

1. Clone your fork:

git clone [email protected]:YOUR-USERNAME/YOUR-FORKED-REPO.git

2. Add remote from original repository in your forked repository:

cd into/cloned/fork-repo
git remote add upstream git://github.com/ORIGINAL-DEV-USERNAME/REPO-YOU-FORKED-FROM.git
git fetch upstream
@saroar
saroar / SimpleClient.swift
Created May 16, 2018 21:12 — forked from sarpsolakoglu/SimpleClient.swift
Simple Swift 4 Rest Client that uses the Codable protocol for JSON conversion
//
// SimpleClient.swift
//
// Created by Sarp Solakoglu on 18/09/2017.
// Copyright © 2017 Sarp Solakoglu. All rights reserved.
//
import Foundation
enum RestMethod: String {
extension Route {
init<IN: Codable, OUT: Codable>(uri: String, _ handler: @escaping (IN) throws -> OUT) {
self.init(method: .post, uri: uri) {
req, resp in
do {
guard let body = req.postBodyBytes else {
throw DecodingError.dataCorrupted(.init(codingPath: [], debugDescription: "This request requires JSON input."))
}
let input = try JSONDecoder().decode(IN.self, from: Data(bytes: body))
resp.setBody(bytes: try JSONEncoder().encode(try handler(input)).map{$0})