Skip to content

Instantly share code, notes, and snippets.

@alltom
alltom / ContentView.swift
Created Dec 17, 2021
Is it this complicated to debounce a search box?
View ContentView.swift
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 Dec 29, 2020
Go proto example
View generate.go
// 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
View twoman.eve
# [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 Jan 27, 2022
"Tested" with Trix 0.9.4
View trix-sanitize-html.js
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']);
View gist:df50ffe7a2b4e0537b04
// https://gist.github.com/Eiam8821/07a7372667879172e9df
enum TakeWhileState {
case Continuing(Int)
case Done
}
struct TakeWhileGenerator<T>: GeneratorType {
let sequence: TakeWhile<T>
var state: TakeWhileState
View gist:9746309
### 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:
View UICollectionViewLayout-subclass.m
@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 Aug 29, 2015
git sub-command for removing superfluous "gits" from commands like "git git status"
View git-git
#!/bin/sh
# translates "git git status" -> "git status"
# install as "git-git" in your path
while [[ $1 == "git" ]]; do
shift
done
git $*
View oo.rb
#!/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
View gist:525381
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