Skip to content

Instantly share code, notes, and snippets.

@drewmccormack
drewmccormack / SerialMacro.swift
Created July 26, 2024 11:49
A macro that can be applied to an async func to generate a peer func (serial_<funcname>) that uses an internal queue to serialize execution. That is, it guarantees that only one copy of the func will run at a time. (Note that this can deadlock if it reenters.)
import SwiftSyntax
import SwiftSyntaxMacros
import SwiftCompilerPlugin
public enum SerialError: Error, CustomStringConvertible {
case invalidInput
case invalidOutput
public var description: String {
switch self {
@mingodad
mingodad / fts3-compress-column.diff
Created September 24, 2018 13:43
Here is the diffs to an implementation of "notcompressed" option for columns in fts3/4 in sqlite3
Index: ext/fts3/fts3.c
==================================================================
--- ext/fts3/fts3.c
+++ ext/fts3/fts3.c
@@ -851,11 +851,12 @@
}else{
zFree = zFunction = fts3QuoteId(zFunc);
}
fts3Appendf(pRc, &zRet, "docid");
for(i=0; i<p->nColumn; i++){
#!/usr/bin/perl
# This filter changes all words to Title Caps, and attempts to be clever
# about *un*capitalizing small words like a/an/the in the input.
#
# The list of "small words" which are not capped comes from
# the New York Times Manual of Style, plus 'vs' and 'v'.
#
# 10 May 2008
# Original version by John Gruber:
@madrobby
madrobby / gist:8dc43c58114466d6a894
Created June 24, 2014 12:20
Code to prevent drag/drop in a Webview inside a Mac app. You can throw this in a `<script>` tag first thing inside the `<body>`. Users will no longer be able to accidentally break your app by dropping something (like a web page URL) onto it.
document.addEventListener('dragover', function(e){
e.preventDefault();
e.stopPropagation();
}, false);
document.addEventListener('drop', function(e){
e.preventDefault();
e.stopPropagation();
}, false)
@matej
matej / CALayer+MBAnimationPersistence.h
Last active May 28, 2024 17:42
Persists (pauses) layer animations (including UIView animation generated animations) when the application enters into background and restores (resumes) animations from where they left off upon returning from background.
//
// CALayer+MBAnimationPersistence.h
//
// Created by Matej Bukovinski on 19. 03. 14.
// Copyright (c) 2014 Matej Bukovinski. All rights reserved.
//
#import <QuartzCore/QuartzCore.h>
@eternalstorms
eternalstorms / NSSharingServicePicker+ESSSharingServicePickerMenu.h
Created November 22, 2012 18:50
A category on NSSharingServicePicker to create a menu that can be used as a sharing submenu or main menu
//
// NSSharingServicePicker+ESSSharingServicePickerMenu.h
//
// Created by Matthias Gansrigler on 22.11.12.
// Copyright (c) 2012 Eternal Storms Software. All rights reserved.
//
#import <Cocoa/Cocoa.h>
@interface NSSharingServicePicker (ESSSharingServicePickerMenu)
@rsms
rsms / HUTF8MappedUTF16String.h
Created November 26, 2010 14:41
Convert a UTF-16 string to UTF-8, mapping indices to provide low-complexity range and index lookups
#ifndef H_UTF8_MAPPED_UTF16_STRING_H_
#define H_UTF8_MAPPED_UTF16_STRING_H_
#import <Foundation/Foundation.h>
#import <string>
/*
* Convert a UTF-16 string to UTF-8, mapping indices to provide low-complexity
* range and index lookups.
*