Skip to content

Instantly share code, notes, and snippets.

View konstantinpavlikhin's full-sized avatar

Konstantin Pavlikhin konstantinpavlikhin

View GitHub Profile
@cweinberger
cweinberger / EventLoopFutureQueue-example.swift
Last active January 19, 2021 22:03
Vapor 4 EventLoopFutureQueue
/**
Assuming the route handler is attached to `http://localhost:8080/import-data` you can test the implementation with this request (cURL):
```
curl -X "POST" "http://localhost:8080/import-data" \
-H 'Content-Type: application/json; charset=utf-8' \
-d $'{ "values": ["first", "foo", "bar", "last"] }'
```
Prints:
```
@ole
ole / load-misaligned.swift
Last active June 25, 2019 21:54
Load misaligned data from a blob of bytes. I don't know if this is correct.
import Foundation
let data = Data([0, 0, 0, 0, 0, 0x11, 0x22, 0x33, 0x44, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
data.count
extension UnsafeRawBufferPointer {
func loadUnaligned<T>(fromByteOffset offset: Int, as: T.Type) -> T {
// Allocate correctly aligned memory and copy bytes there
let alignedPointer = UnsafeMutableRawPointer.allocate(byteCount: MemoryLayout<T>.stride, alignment: MemoryLayout<T>.alignment)
defer {
@edenwaith
edenwaith / filesize.m
Last active February 22, 2023 09:45
Multiple ways to calculate the size of a file's resource fork
/*
* filesize.m
* Description: Multiple ways to calculate the size of a file's resource fork
* Author: Chad Armstrong
* Date: 14 April 2018 (Updated 28 October 2022)
* To compile: gcc -w -framework Cocoa filesize.m -o filesize
* To run: ./filesize path/to/file
*/
/* References:
@dannote
dannote / final-cut-pro-trial-reset.swift
Last active May 8, 2024 03:08
Final Cut Pro X trial reset
#!/usr/bin/swift
import Foundation
let path = URL(fileURLWithPath: NSString(string: "~/Library/Application Support/.ffuserdata").expandingTildeInPath)
let data = try! NSData(contentsOf: path) as Data
let dictionary = try! NSKeyedUnarchiver.unarchiveTopLevelObjectWithData(data) as! NSDictionary
let mutableDictionary = dictionary.mutableCopy() as! NSMutableDictionary
for (key, value) in mutableDictionary {
As of iOS 11/macOS High Sierra, and only including ones in Foundation and CoreFoundation
Strings:
_NSCFString - a CFStringRef or CFMutableStringRef. This is the most common type of string object currently.
- May have 8 bit (ASCII) or 16 bit (UTF-16) backing store
_NSCFConstantString - a compile time constant CFStringRef, like you'd get with @"foo"
- May also be generated by dynamic string creation if matches a string in a pre-baked table of common strings called the StringROM
NSBigMutableString - an NSString backed by a CFStorage (https://github.com/opensource-apple/CF/blob/master/CFStorage.h) for faster handling of very large strings
NSCheapMutableString - a very limited NSMutableString that allows for zero-copy initialization. Used in NSFileManager for temporarily wrapping stack buffers.
@mattlawer
mattlawer / DisableGDB.swift
Created December 25, 2016 17:13
Disable GDB with Swift 3
import Foundation
func disable_gdb() {
let PT_DENY_ATTACH: CInt = 31
let handle = dlopen("/usr/lib/libc.dylib", RTLD_NOW)
let sym = dlsym(handle, "ptrace")
typealias PtraceAlias = @convention(c) (CInt, pid_t, CInt, CInt) -> CInt
let ptrace = unsafeBitCast(sym, to: PtraceAlias.self)
_ = ptrace(PT_DENY_ATTACH, 0, 0, 0)
dlclose(handle)
@dodikk
dodikk / about_swizzling.md
Last active October 22, 2017 20:36
Поговорки про swizzling
  • с утра посвизлил - весь день свободен
  • украл, посвиззлил - в тюрьму
  • волков бояться - в лесу не свиззлить
  • не все золото что свиззлит
  • свиззлинг - всему голова
  • и рыбку съесть, и посвиззлить
  • в большой семье свиззлом не щелкают
@onjin
onjin / docker-compose.yml
Created September 5, 2016 09:17
example docker compose for postgresql with db init script
postgres:
image: postgres:9.4
volumes:
- ./init.sql:/docker-entrypoint-initdb.d/init.sql
@soffes
soffes / BaseTextStorage.swift
Last active July 1, 2023 10:14
Fast, concrete text storage intended to be subclassed.
import UIKit
/// Fast, concrete text storage intended to be subclassed.
class BaseTextStorage: NSTextStorage {
// MARK: - Properties
private let storage = NSMutableAttributedString()
// MARK: - NSTextStorage