Skip to content

Instantly share code, notes, and snippets.

View goppinath's full-sized avatar

Goppinath Thurairajah goppinath

View GitHub Profile
@ymyzk
ymyzk / semaphore.swift
Created August 10, 2015 19:43
Grand Central Dispatch (GCD) dispatch semaphore examples
private func example1() {
let queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)
for i in 0..<10 {
dispatch_async(queue) {
NSLog("Start: \(i)")
sleep(3)
NSLog("End: \(i)")
}
}
}
import Foundation
import PlaygroundSupport
/// A thread-safe array.
public class SynchronizedArray<Element> {
private let queue = DispatchQueue(label: "io.zamzam.ZamzamKit.SynchronizedArray", attributes: .concurrent)
private var array = [Element]()
public init() { }
@pirafrank
pirafrank / cloudflareDoH.mobileconfig
Last active January 24, 2024 19:57
iOS, iPadOS and tvOS 14 support MDM profile to set encrypted DNS requests (DNS-over-HTTPS and DNS-over-TLS) on cellular and Wi-Fi connection. To install, open this page from your device and click ‘Raw’ on the one of your choice in the GitHub page. Then continue installation in Settings app. Browse https://1.1.1.1/help after installing to check it
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>PayloadContent</key>
<array>
<dict>
<key>DNSSettings</key>
<dict>
<key>DNSProtocol</key>
@yutelin
yutelin / String+AES.swift
Last active January 22, 2024 12:36
String+AES.swift
import Foundation
import CryptoSwift
extension String {
func aesEncrypt(key: String, iv: String) throws -> String{
let data = self.dataUsingEncoding(NSUTF8StringEncoding)
let enc = try AES(key: key, iv: iv, blockMode:.CBC).encrypt(data!.arrayOfBytes(), padding: PKCS7())
let encData = NSData(bytes: enc, length: Int(enc.count))
let base64String: String = encData.base64EncodedStringWithOptions(NSDataBase64EncodingOptions(rawValue: 0));
@floriankugler
floriankugler / gist:6870499
Last active September 29, 2023 15:56
Mapping of NSURLConnection to NSURLSession delegate methods. Created by Mattt Thompson.
NSURLConnection | NSURLSession
------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------
NSURLConnectionDelegate connectionShouldUseCredentialStorage: |
------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------
NSURLConnectionDelegate connection:willSendRequestForAuthenticationChallenge: | NSURLSessionDelegate URLSession:didReceiveChallenge:completionHandler:
| N
@jochenschoellig
jochenschoellig / ChatCollectionViewFlowLayout.swift
Created January 19, 2017 15:49
A subclass of UICollectionViewFlowLayout to get chat behavior without turning collection view upside-down. This layout is written in Swift 3 and absolutely usable with RxSwift and RxDataSources because UI is completely separated from any logic or binding.
import UIKit
class ChatCollectionViewFlowLayout: UICollectionViewFlowLayout {
private var topMostVisibleItem = Int.max
private var bottomMostVisibleItem = -Int.max
private var offset: CGFloat = 0.0
private var visibleAttributes: [UICollectionViewLayoutAttributes]?
@celian-m
celian-m / SessionDelegate.swift
Created January 13, 2017 16:33
Perform client side certificate check
import Foundation
public struct IdentityAndTrust {
public var identityRef:SecIdentity
public var trust:SecTrust
public var certArray:NSArray
}
public func extractIdentity(certData:NSData, certPassword:String) -> IdentityAndTrust {
// MyURLStreamTask.swift
// Demonstrates using an NSURLSessionStreamTask to implement a bidirectional TCP socket connection
//
// by rhn@nicholson.com 2017-03-07
// distribution: BSD 2-clause
//
import Foundation
class MyURLStreamTask {
@NatashaTheRobot
NatashaTheRobot / WatchConnectivitySingletonDemo.swift
Last active December 29, 2022 14:44
WatchConnectivity Singleton Demo
//
// WatchSessionManager.swift
// WatchConnectivityDemo
//
// Created by Natasha Murashev on 9/3/15.
// Copyright © 2015 NatashaTheRobot. All rights reserved.
//
import WatchConnectivity
@Jaybles
Jaybles / UIDeviceHardware.h
Created October 28, 2011 19:33
UIDeviceHardware - Determine iOS device being used
//
// UIDeviceHardware.h
//
// Used to determine EXACT version of device software is running on.
#import <Foundation/Foundation.h>
@interface UIDeviceHardware : NSObject
- (NSString *) platform;