Skip to content

Instantly share code, notes, and snippets.

View codeactual's full-sized avatar

David Smith codeactual

  • Found Apparatus
View GitHub Profile
@codeactual
codeactual / Concurrent map benchmarks
Created January 24, 2016 03:21 — forked from donovanhide/Concurrent map benchmarks
Benchmarks for different implementations of a concurrent map
To benchmark:
go test -bench=".*" > machine_description.txt
@codeactual
codeactual / trace-to-mp4.js
Created March 4, 2017 02:32 — forked from krisselden/trace-to-mp4.js
Make an mp4 out of a Chrome DevTools trace with screenshots.
#!/usr/bin/env node
const fs = require('fs');
const path = require('path');
const execSync = require('child_process').execSync;
if (process.argv.length < 3) {
console.log(`node ${path.relative('.', process.argv[1])} [DevToolsProfile]`);
process.exit(1);
}
let traceFile = path.resolve(process.argv[2])
@codeactual
codeactual / postgres.go
Created March 28, 2018 19:40 — forked from rivo/postgres.go
A demo Go application (a PostgreSQL database browser) highlighting the use of the rivo/tview package. See https://github.com/rivo/tview/wiki/Postgres
package main
import (
"database/sql"
"fmt"
"net/url"
"os"
"reflect"
"regexp"
"strconv"
$ cat test.js
function foo () { while (true) { } }
function bar () { return foo(); }
bar();
$ node test.js &
$ gdb attach $(pidof node)
0x00000bf778c63d5f in ?? ()
(gdb) b v8::internal::Runtime_StackGuard
Breakpoint 1 at 0x84a1f0
(gdb) print 'v8::V8::TerminateExecution'(0)
@codeactual
codeactual / switchgo.sh
Created September 24, 2019 12:20 — forked from fatih/switchgo.sh
Switch between go version using https://github.com/golang/dl
function switchgo() {
version=$1
if [ -z $version ]; then
echo "Usage: switchgo [version]"
return
fi
if ! command -v "go$version" > /dev/null 2>&1; then
echo "version does not exist, download with: "
echo " go get golang.org/dl/${version}"
@codeactual
codeactual / VideoPlayerControls.swift
Created September 9, 2021 16:43 — forked from Martini024/VideoHelper.swift
SwiftUI: Rewrite iOS Photos Video Scrubber
import SwiftUI
import AVKit
struct VideoPlayerControls: View {
let player: AVPlayer
@Binding var currentTime: CGFloat
var height: CGFloat = 50
//
// ContentView.swift
// SwiftUIDemo
//
// Created by Damir Stuhec on 07/10/2021.
//
import SwiftUI
// MARK: - CustomButtonStyle
// Swift's untyped errors are a goddam PiTA. Here's the pattern I use to try to work around this.
// The goal is basically to try to guarantee that every throwing function in the app throws an
// ApplicationError instead of some unknown error type. We can't actually enforce this statically
// But by following this convention we can simplify error handling
enum ApplicationError: Error, CustomStringConvertible {
// These are application-specific errors that may need special treatment
case specificError1
case specificError2(SomeType)
@codeactual
codeactual / WithPopover.swift
Created October 25, 2021 18:02 — forked from wassupdoc/WithPopover.swift
Custom size popover in iOS SwiftUI
// -- Usage
struct Content: View {
@State var open = false
@State var popoverSize = CGSize(width: 300, height: 300)
var body: some View {
WithPopover(
showPopover: $open,
popoverSize: popoverSize,
@codeactual
codeactual / PHImageManager-requestImage-async.swift
Created November 3, 2021 16:01 — forked from sindresorhus/PHImageManager-requestImage-async.swift
How to use `PHImageManager#requestImage` with async/await in Swift.
import Photos
struct UnexpectedNilError: Error {}
extension PHImageManager {
func requestImage(
for asset: PHAsset,
targetSize: CGSize,
contentMode: PHImageContentMode,
options: PHImageRequestOptions?