Skip to content

Instantly share code, notes, and snippets.

View drinkius's full-sized avatar

Alexander Telegin drinkius

View GitHub Profile
@drinkius
drinkius / storage.swift
Created September 26, 2016 15:15 — forked from avdyushin/storage.swift
CoreData stack for iOS 9 and iOS 10 using Swift 3
//
// Storage.swift
//
// Created by Grigory Avdyushin on 30.06.16.
// Copyright © 2016 Grigory Avdyushin. All rights reserved.
//
import UIKit
import CoreData
@drinkius
drinkius / gist:7a497f25aaa54963de2c1269f77627d4
Created November 15, 2016 09:04 — forked from Tron5000/gist:7bb51318db1da86a3a78
Compressing/Decompressing UUID to 22 characters via base64
import Foundation
// Compressing and decompressing a UUID to 22 characters via base64.
// Works great as a Swift playground. These articles were helpful:
// http://blog.codinghorror.com/equipping-our-ascii-armor/
// http://69.195.124.60/~jasondoh/2013/08/14/creating-a-short-guid-in-objective-c/
let identifier = NSUUID().uuidString
let base64TailBuffer = "="
@drinkius
drinkius / iOS.8.3.txt
Created December 30, 2016 22:22
iOS UIFont names
UIFont: family Thonburi
UIFont: font Thonburi-Bold
UIFont: font Thonburi
UIFont: font Thonburi-Light
UIFont: family Khmer Sangam MN
UIFont: font KhmerSangamMN
UIFont: family Snell Roundhand
UIFont: font SnellRoundhand-Black
UIFont: font SnellRoundhand-Bold
UIFont: font SnellRoundhand
import CoreGraphics
import Foundation
import UIKit
class GradientLabel : UILabel {
let gradient: CGGradient!
let alignedToSuperview: Bool!
func setupGradientBackground() {
let firstColor = UIColor.black.withAlphaComponent(0.6)
let secondColor = UIColor.black.withAlphaComponent(0.0)
let gradient = CGGradient.with(easing: Cubic.EaseIn, between: firstColor, and: secondColor)
var updatedSize = self.navigationBar.bounds.size
updatedSize.height += 20
UIGraphicsBeginImageContextWithOptions(updatedSize, false, 0);
@drinkius
drinkius / about_swizzling.md
Created February 17, 2017 13:46 — forked from dodikk/about_swizzling.md
Поговорки про swizzling
  • с утра посвизлил - весь день свободен
  • украл, посвиззлил - в тюрьму
  • волков бояться - в лесу не свиззлить
  • не все золото что свиззлит
  • свиззлинг - всему голова
  • и рыбку съесть, и посвиззлить
  • в большой семье свиззлом не щелкают
@drinkius
drinkius / how-to-connect-an-iOS-device-to-your-computer-using-SOCKS.md How to connect an iOS device to your computer via a SOCKS proxy. Say you're running a virtual machine on your work computer. Say this machine, for whatever reason, can only connect to the internet over NAT - as in, it does not get it's own IP address. Say this VM is running a webserver, and you need a device outside of your computer to connect t…

How to connect an iOS device to your computer via a SOCKS proxy

Say you're running a virtual machine on your work computer. Say this machine, for whatever reason, can only connect to the internet over NAT - as in, it does not get it's own IP address. Say this VM is running a webserver, and you need a device outside of your computer to connect to it.

If only there was a way to get your work computer to 'share' it's network, so that you could get at that VM… Here's how you do it!

For all instructions, I assume your work computer is a mac

  1. Get your computer's IP address:
@objc public enum AppContextError: Int, CustomStringConvertible, CustomNSError, LocalizedError {
case badParameters
case unknownError
case connectNotSupported
public static var errorDomain: String {
return "AppContextError"
}
@drinkius
drinkius / gist:0b66842b3fb05cbab95c121b7361d9ea
Created March 28, 2017 13:41
Save managed object context
NSManagedObjectContext *context = object.managedObjectContext;
while (context != nil) {
NSError *error = nil;
BOOL result = [context save:&error];
NSAssert(result != NO, @"[ERROR]: Context was not saved");
if (result) {
context = context.parentContext;
} else {
@drinkius
drinkius / latency.txt
Created April 19, 2017 19:31 — forked from jboner/latency.txt
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers
--------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD