Skip to content

Instantly share code, notes, and snippets.

@delebedev
delebedev / libdispatch-efficiency-tips.md
Created February 19, 2020 19:04 — forked from tclementdev/libdispatch-efficiency-tips.md
Making efficient use of the libdispatch (GCD)

libdispatch efficiency tips

I suspect most developers are using the libdispatch inefficiently due to the way it was presented to us at the time it was introduced and for many years after that, and due to the confusing documentation and API. I realized this after reading the 'concurrency' discussion on the swift-evolution mailing-list, in particular the messages from Pierre Habouzit (who is the libdispatch maintainer at Apple) are quite enlightening (and you can also find many tweets from him on the subject).

My take-aways are:

@delebedev
delebedev / bs.md
Created May 28, 2019 15:48
javascript hits again

Javascript is fun

a = new Date('2019-03-31T00:00:00.000Z');
a.setDate(a.getDate() + 1);
console.log(a);
Firefox macos Safari macos chrome macos
@delebedev
delebedev / curl.py
Last active June 19, 2018 11:31
curl lldb plugin (swift4)
#!/usr/bin/env python
import lldb
def process(debugger, command, result, internal_dict):
lldb.debugger.HandleCommand("""
expr -l swift --
func $process(_ request: URLRequest) {
func curl(_ request: URLRequest) -> String {
guard let url = request.url?.absoluteString else {
@delebedev
delebedev / minimal.swift
Created July 2, 2017 10:16 — forked from sjoerdvisscher/minimal.swift
Using Decodable to generate a minimal value
struct MinimalDecoder : Decoder {
var codingPath = [CodingKey?]()
var userInfo = [CodingUserInfoKey : Any]()
public func container<Key>(keyedBy type: Key.Type) throws -> KeyedDecodingContainer<Key> {
return KeyedDecodingContainer(MinimalKeyedDecodingContainer<Key>(decoder: self))
}
public func unkeyedContainer() throws -> UnkeyedDecodingContainer {
return DecodingContainer(decoder: self)
@delebedev
delebedev / xxx.swift
Last active March 17, 2017 15:28
Swift CoreData craziness
// Class Keyword: NSManagedObject is defined in objective-c (not sure if it matters)
// .keywords is CoreData to-many relationship pointing to "Keyword" objects.
// How do I convert .keywords to [Keyword]?
po type(of: keywords)
_NSFaultingMutableOrderedSet
po keywords is NSOrderedSet
true
Adyen Test Card Numbers
These cards are only valid on our TEST system and they will never involve any actual transaction or transfer of funds. The TEST card numbers will not work on the Adyen LIVE Platform.
For all cards use the following expiration and CVV2/CVC2/or CID for Amex.
For all cards:
Expiration Dates CVV2 / CVC3 CID (American Express)
06/2016 OR 08/2018 737 7373

Types

A type is a collection of possible values. An integer can have values 0, 1, 2, 3, etc.; a boolean can have values true and false. We can imagine any type we like: for example, a HighFive type that allows the values "hi" or 5, but nothing else. It's not a string and it's not an integer; it's its own, separate type.

Statically typed languages constrain variables' types: the programming language might know, for example, that x is an Integer. In that case, the programmer isn't allowed to say x = true; that would be an invalid program. The compiler will refuse to compile it, so we can't even run it.

@delebedev
delebedev / main.swift
Created April 12, 2016 14:22
Tiny networking revisited
import Result
import Unbox
public enum Method: String { // Bluntly stolen from Alamofire
case OPTIONS = "OPTIONS"
case GET = "GET"
case HEAD = "HEAD"
case POST = "POST"
case PUT = "PUT"
case PATCH = "PATCH"
@delebedev
delebedev / gimmeWWDC.rb
Last active August 29, 2015 14:22
Get all fresh WWDC sessions at once
#!/usr/bin/env ruby
require 'net/http'
require 'json'
require 'ostruct'
require 'fileutils'
PATH = "https://devimages.apple.com.edgekey.net/wwdc-services/ftzj8e4h/6rsxhod7fvdtnjnmgsun/videos.json"
WWDC_DIR = "#{Dir.home}/Downloads/wwdc"
@delebedev
delebedev / main.swift
Created June 7, 2015 11:09
Export Foursquare checkins to GPX
//
// main.swift
// ForsquareGPX
//
// Created by Dzianis Lebedzeu on 07/06/2015.
// Copyright (c) 2015 Home. All rights reserved.
//
import Foundation