Skip to content

Instantly share code, notes, and snippets.

@phiresky
phiresky / tune.md
Last active March 25, 2024 13:34
SQLite performance tuning

You can scale a SQLite database to multiple GByte in size and many concurrent readers by applying the below optimizations.

Run these every time you connect to the db

(some are applied permanently, but others are reset on new connection)

pragma journal_mode = WAL;

Instead of writing directly to the db file, write to a write-ahead-log instead and regularily commit the changes. Allows multiple concurrent readers, and can significantly improve performance.

@douglashill
douglashill / KeyboardTableView.swift
Last active March 30, 2023 22:01
A UITableView that allows navigation and selection using a hardware keyboard.
// Douglas Hill, December 2018
// Made for https://douglashill.co/reading-app/
// Find the latest version of this file at https://github.com/douglashill/KeyboardKit
import UIKit
/// A table view that allows navigation and selection using a hardware keyboard.
/// Only supports a single section.
class KeyboardTableView: UITableView {
// These properties may be set or overridden to provide discoverability titles for key commands.
@kainjow
kainjow / libproc_example.swift
Created November 24, 2018 20:09
Swift example of C libproc API
import Darwin
// Call proc_listallpids once with nil/0 args to get the current number of pids
let initialNumPids = proc_listallpids(nil, 0)
// Allocate a buffer of these number of pids.
// Make sure to deallocate it as this class does not manage memory for us.
let buffer = UnsafeMutablePointer<pid_t>.allocate(capacity: Int(initialNumPids))
defer {
buffer.deallocate()
@eguven
eguven / brew-list.sh
Last active February 7, 2024 06:16
List all packages installed using Homebrew and their sizes
brew list --formula | xargs -n1 -P8 -I {} \
sh -c "brew info {} | egrep '[0-9]* files, ' | sed 's/^.*[0-9]* files, \(.*\)).*$/{} \1/'" | \
sort -h -r -k2 - | column -t
I am not a fan of Xcode. Here are ~160~ 200 problems, the first hundred or so issues were filed mostly in
July and August 2016 in a fit of rage. Mostly on weekends working (slowly) on side-projects. I have also
taken days of my employer's time filing others of these - so the company was not getting value for my time.
I believe a paid intern could have found many of these - just start a screen recorder, and when you see something,
stop and cut a quick movie. Many have been around for several major versions.
I'm volunteering chunks of my life (15-30 minutes per) to one of the most valuable companies in the world, which seems
kind of messed up. Things get worse the more complex the project and the longer Xcode been's running.
Apple folks - check out rdar://22524679
@ffeldhaus
ffeldhaus / ds215j_bootstrap_ng.md
Last active September 26, 2023 11:09
Bootstrap Synology ds215j using optware-ng

Bootstrap the Synology DS215j with optware-ng

I tried the instructions described in the Blogpost Bootstrap DS215j to install optware for ds215j but was unsatisfied with the long outdated packages it provided. Luckily, there now is optware-ng which is a fork of optware and provides recent packages.

This is how I managed to install optware-ng on my Synology ds215j inspired by the instructions in the Gist Boostrap the Synology DS215j with optware, ipkg, and sudo:

Download & Install ipkg in a persistent manner

# become root

sudo -i

@599316527
599316527 / ddns-start
Last active October 18, 2019 08:32
asuswrt-merlin custom ddns script for dnspod
#!/bin/sh
# This file should be placed in /jffs/scripts/ folder.
# 后台申请token
# https://support.dnspod.cn/Kb/showarticle/tsid/227/
login_token='xxxxxxx,yyyyyyyyyyyyyyyyyyyyyyyyyyyyy'
# 先调 Domain.List 和 Record.List 接口取得 id
# https://www.dnspod.cn/docs/domains.html#domain-list
# https://www.dnspod.cn/docs/records.html#record-list
@randomsequence
randomsequence / cocoa-drawing.swift
Created July 14, 2015 15:25
Drawing images with CGContext and NSGraphicsContext in Swift
//: Playground - noun: a place where people can play
import Cocoa
let bounds = CGRectMake(0, 0, 100, 100);
func DrawImageInCGContext(#size: CGSize, #drawFunc: (context: CGContextRef) -> ()) -> NSImage {
let colorSpace = CGColorSpaceCreateDeviceRGB()
let bitmapInfo = CGBitmapInfo(CGImageAlphaInfo.PremultipliedLast.rawValue)
let context = CGBitmapContextCreate(
@c9iim
c9iim / AXUIElement_in_Swift.swift
Last active May 9, 2023 07:45
AXUIElement in Swift
import Cocoa
protocol AXUIProtocol {
func AXUIWindowArray(processIdentifier pid:pid_t) -> [AXUIElement]
func AXUIWindowArray(bundleIdentifier bid:NSString) -> [AXUIElement]
}
extension AXUIProtocol {
func AXUIWindowArray(processIdentifier pid:pid_t) -> [AXUIElement] {
let windowList : UnsafeMutablePointer<AnyObject?> = UnsafeMutablePointer<AnyObject?>.alloc(1)
@ku
ku / metatag.m
Created November 12, 2013 02:19
OSX10.9 tag manipulation util
#import <Foundation/Foundation.h>
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
// clang tag.m -o metatag -framework "foundation" -fobjc-arc && ./metatag
int main(int argc, char **argv) {
char *tagToAdd = NULL;