Skip to content

Instantly share code, notes, and snippets.

@alltom
alltom / ContentView.swift
Created December 17, 2021 06:33
Is it this complicated to debounce a search box?
import SwiftUI
import Combine
struct ContentView: View {
@EnvironmentObject private var model: ViewModel
@StateObject private var searchQuery = SearchQueryDebouncer()
var body: some View {
List {
@alltom
alltom / generate.go
Created December 29, 2020 19:10
Go proto example
// file path: myproject/proto/msg1/generate.go
package proto
//go:generate protoc -I/usr/local/include -I. -I$GOPATH/src -I$GOPATH/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis --go_out=plugins=grpc:. msg1.proto
@alltom
alltom / twoman.eve
Last active October 19, 2016 07:53
# [Two-Man Rule](https://en.wikipedia.org/wiki/Two-man_rule)
## Model
Create two locks.
```
commit @model
[#lock name: "Lock 1", locked: true]
[#lock name: "Lock 2", locked: true]
```
Unlock locks when their key is turned.
@alltom
alltom / trix-sanitize-html.js
Last active January 27, 2022 03:47
"Tested" with Trix 0.9.4
var sanitizeHtml = require('sanitize-html');
function localSanitizeHtml(html) {
let allowedAttributes = JSON.parse(JSON.stringify(sanitizeHtml.defaults.allowedAttributes));
allowedAttributes.a = (allowedAttributes.a || []).concat(['data-trix-attachment', 'rel']);
allowedAttributes.figure = (allowedAttributes.figure || []).concat(['class']);
allowedAttributes.figcaption = (allowedAttributes.figcaption || []).concat(['class']);
allowedAttributes.img = (allowedAttributes.img || []).concat(['width', 'height']);
allowedAttributes.span = (allowedAttributes.span || []).concat(['class']);
@alltom
alltom / gist:df50ffe7a2b4e0537b04
Last active August 29, 2015 14:04
Swift Challenge #2
// https://gist.github.com/Eiam8821/07a7372667879172e9df
enum TakeWhileState {
case Continuing(Int)
case Done
}
struct TakeWhileGenerator<T>: GeneratorType {
let sequence: TakeWhile<T>
var state: TakeWhileState
### Keybase proof
I hereby claim:
* I am alltom on github.
* I am alltom (https://keybase.io/alltom) on keybase.
* I have a public key whose fingerprint is 83BA 6BBE 850C A897 1A4B FBF8 75F4 6A37 8603 F396
To claim this, I am signing this object:
@implementation VP2CollectionViewLayout
#pragma mark - Called during the layout process
// step 1
- (void)prepareLayout
{
// if it's not too much data, create all element attributes here
}
@alltom
alltom / git-git
Last active August 29, 2015 13:56
git sub-command for removing superfluous "gits" from commands like "git git status"
#!/bin/sh
# translates "git git status" -> "git status"
# install as "git-git" in your path
while [[ $1 == "git" ]]; do
shift
done
git $*
@alltom
alltom / oo.rb
Created January 30, 2011 21:43
oo
#!/usr/bin/env ruby
# context-sensitive "open" alternative
# just go into a directory and run "oo"
# the correct project editor be used to open it
# usage:
# $ oo guess what to do with current directory
# $ oo [file or directory] guess what to do with the given file/directory
require "rubygems"
require "osc"
SERVER_HOST = "localhost"
SERVER_PORT = 5000
conn = OSC::UDPSocket.new
msg = OSC::Message.new("/live/add", "s", $stdin.read)
conn.send msg, 0, SERVER_HOST, SERVER_PORT