Skip to content

Instantly share code, notes, and snippets.

View iljaiwas's full-sized avatar

Ilja Iwas iljaiwas

View GitHub Profile
@iljaiwas
iljaiwas / GSSavedAttributeSet.m
Last active December 11, 2021 15:32
Example how to build a class for iwascoding's Objective-C ORM system
// GSSavedAttributeSet.h
#import "SDBObject.h"
#import <SDBSynch/SDBSynchProtocols.h>
NS_ASSUME_NONNULL_BEGIN
@class GSEbayItemSpecific;
/** A named set of pre-filled listing attributes, which is specific to a certain eBay site and possibly categories */
Sampling process 1375 for 3 seconds with 1 millisecond of run time between samples
Sampling completed, processing symbols...
Analysis of sampling Tweetbot (pid 1375) every 1 millisecond
Process: Tweetbot [1375]
Path: /Applications/Tweetbot.localized/Tweetbot.app/Contents/MacOS/Tweetbot
Load Address: 0x108181000
Identifier: com.tapbots.Tweetbot3Mac
Version: 3.5.4 (35400)
Code Type: X86-64
Platform: macOS
@iljaiwas
iljaiwas / IHPredicateBuilder.m
Created May 19, 2020 09:52
Tinkering with a predicate builder in Objective-C.
/* I'm trying to come up with with a general predicate builder in Objective-C, that can build NSPredicates for
arbitrary classes. I want to write something like this:
predicate = [[[[[builder name] contains:@"ilja"] age] greaterThan:@20] predicate];
But the compiler insists on sprinkling ids everywhere.
predicate = [[(id)[[(id) [(id) builder name] contains:@"ilja"] age] greaterThan:@20] predicate];
Any ideas how to omit the 'id' casts? Also, need a good idea for or and not methods.
@iljaiwas
iljaiwas / Continuity Camera.m
Created April 1, 2020 16:10
Getting hold of the image data inserted into your WebView by Apple's Continuity Camera feature
- (BOOL)webView:(WebView *)inWebView shouldInsertNode:(DOMNode *)node replacingDOMRange:(DOMRange *)range givenAction:(WebViewInsertAction)action
{
if (WebViewInsertActionPasted == action) {
if ([node isKindOfClass:DOMDocumentFragment.class]) {
DOMDocumentFragment *frag = (DOMDocumentFragment*) node;
if ([[frag childNodes] length] == 1) {
DOMNode *firstChildNode = [[node childNodes] item:0];
if ([firstChildNode isKindOfClass:DOMHTMLImageElement.class]) {
DOMHTMLImageElement *imageElement = (DOMHTMLImageElement*) firstChildNode;
NSURL *imageURL = [imageElement absoluteImageURL];
@iljaiwas
iljaiwas / BinaryData.swift
Created March 14, 2019 11:11
Drop-in replacement for Data ivars that gets stored efficiently in MySQL by Vapor 3.
import Foundation
import Vapor
import FluentMySQL
final class BinaryData {
private let data: Data
init(data: Data) {
self.data = data
}
@iljaiwas
iljaiwas / datatest.swift
Created March 2, 2018 15:31
Swift Data Ranges
import Cocoa
var str = "01234567890123456789012345678901234567"
var buffer = Data()
if let data = str.data(using: .utf8) {
buffer.append(data)
buffer = buffer[15..<38]
buffer = buffer[2..<23]
}
@iljaiwas
iljaiwas / Spindump.txt
Created September 25, 2017 19:06
Spindump of hanging GarageSale
This file has been truncated, but you can view the full file.
Date/Time: 2017-09-25 19:14:38 +0200
OS Version: Mac OS X 10.12.6 (Build 16G29)
Architecture: x86_64h
Report Version: 25
Data Source: Stackshots
Command: GarageSale
Path: /Applications/GarageSale.app/Contents/MacOS/GarageSale
Version: 7.0.9b5 (809)
@iljaiwas
iljaiwas / gist:a7d198e56b758926854655d30c092ae7
Created June 2, 2017 08:44
This code crashes unless CFBridgingRetain is called. Any Ideas why?
private class func createReachabilityManager() -> AFNetworkReachabilityManager? {
var localWifiAddress = sockaddr_in()
bzero(&localWifiAddress, MemoryLayout.size(ofValue: localWifiAddress))
localWifiAddress.sin_len = UInt8(MemoryLayout.size(ofValue: localWifiAddress))
localWifiAddress.sin_family = sa_family_t(AF_INET)
// IN_LINKLOCALNETNUM is defined in <netinet/in.h> as 169.254.0.0
localWifiAddress.sin_addr.s_addr = (IN_LINKLOCALNETNUM).bigEndian
guard let reachabilityRef = withUnsafePointer(to: &localWifiAddress, {
$0.withMemoryRebound(to: sockaddr.self, capacity: 1) {
@iljaiwas
iljaiwas / FBKVOControllerSample.m
Last active November 25, 2016 15:39
Example of FBKVOController usage
#import <KVOController/KVOController.h>
- (void)viewDidLoad
{
[super viewDidLoad];
[self.KVOController observe:self keyPath:@"lastSelectedItem.primaryCategoryID" options:0 block:^(id weakself, id object, NSDictionary *change) {
[weakself updateConditionPopupForItems:[weakself selectedItems]];
[weakself updateConditionDescriptionAvailableForItems:[weakself selectedItems]];
}];