Skip to content

Instantly share code, notes, and snippets.

View kaunteya's full-sized avatar

Kaunteya Suryawanshi kaunteya

View GitHub Profile
@antfarm
antfarm / CRC32.swift
Last active March 29, 2023 10:52
CRC32 checksum generation in a few lines of Swift 5. https://en.wikipedia.org/wiki/Cyclic_redundancy_check#CRC-32_algorithm
class CRC32 {
static var table: [UInt32] = {
(0...255).map { i -> UInt32 in
(0..<8).reduce(UInt32(i), { c, _ in
(c % 2 == 0) ? (c >> 1) : (0xEDB88320 ^ (c >> 1))
})
}
}()
name download_total
AFNetworking 61983241
Fabric 50998892
Crashlytics 49667729
SDWebImage 45471101
Alamofire 42097177
CocoaLumberjack 36071914
Bolts 35294870
FirebaseInstanceID 30277793
FirebaseAnalytics 30254593
@lattner
lattner / async_swift_proposal.md
Last active February 23, 2024 11:41 — forked from oleganza/async_swift_proposal.md
Concrete proposal for async semantics in Swift

Async/Await for Swift

Introduction

Modern Cocoa development involves a lot of asynchronous programming using closures and completion handlers, but these APIs are hard to use. This gets particularly problematic when many asynchronous operations are used, error handling is required, or control flow between asynchronous calls gets complicated. This proposal describes a language extension to make this a lot more natural and less error prone.

This paper introduces a first class Coroutine model to Swift. Functions can opt into to being async, allowing the programmer to compose complex logic involving asynchronous operations, leaving the compiler in charge of producing the necessary closures and state machines to implement that logic.

@preble
preble / NSTextStorageSubclass.swift
Created February 9, 2016 04:45
Base subclass of NSTextStorage in Swift
import Cocoa
@objc
class SomeTextStorage: NSTextStorage {
private var storage: NSMutableAttributedString
override init() {
storage = NSMutableAttributedString(string: "", attributes: nil)
super.init()
/**
* This Google Sheets script keeps data in the specified column sorted any time
* the data changes.
*
* After much research, there wasn't an easy way to automatically keep a column
* sorted in Google Sheets, and creating a second sheet to act as a "view" to
* my primary one in order to achieve that was not an option. Instead, I
* created a script that watches for when a cell is edited and triggers
* an auto sort.
*
@zeusdeux
zeusdeux / socketio.md
Last active March 18, 2020 22:51
Vanilla websockets vs socket.io

Vanilla websockets vs socket.io

Note: The points below are a comparison of using vanilla websockets on client and server and using 'em via socket.io and not about why only use socket.io

  • Native websockets provide us with only a send method to send data to the server. Send accepts only string input (not too sure about this). Socket.io lets us emit arbitrary events with arbitrary data (even binary blobs) to the server.
  • To receive messages on a vanilla websocket you can only assign a handler for the message event. The data you receive is mostly likely to be text (again not too sure about this) and you will have to parse it manually before consuming it. Socket.io lets the server and client both emit arbitrary events and handles all the parsing and packing/unpacking.
  • Socket.io gives us both a server and a client. Implementing a vanilla websocket server isn't something that you would want to do per project since it's quite painful. You will have to implement [RFC6455](https://tools.ietf.org/h
@JadenGeller
JadenGeller / Init Bool With Int.swift
Created March 23, 2015 07:48
Cast Int to Bool in Swift
extension Bool {
init<T : IntegerType>(_ integer: T){
self.init(integer != 0)
}
}
// Now you can do this
let x = Bool(5) // true
let y = Bool(-1) // true
let z = Bool(0) // false
@ryanchang
ryanchang / lldb_cheat_sheet.md
Last active March 12, 2024 11:03
LLDB Cheat Sheet

LLDB Cheat Sheet

A complete gdb to lldb command map.

Print out

  • Print object
(lldb) po responseObject
(lldb) po [responseObject objectForKey@"state"]
  • p - Print primitive type
@staltz
staltz / introrx.md
Last active April 19, 2024 18:49
The introduction to Reactive Programming you've been missing
@steipete
steipete / PSPDFThreadSafeMutableDictionary.m
Last active December 10, 2022 09:37
Simple implementation of a thread safe mutable dictionary. In most cases, you want NSCache instead, but it can be useful in situations where you want to manually control what is evicted from the cache in low memory situations.**Warning:** I only use this for setting/getting keys. Enumeration is not thread safe here and will still throw exception…
//
// PSPDFThreadSafeMutableDictionary.m
//
// Copyright (c) 2013 Peter Steinberger, PSPDFKit GmbH. All rights reserved.
//
// 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