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 / async_await_notes.md
Last active January 18, 2018 01:20
async/await notes

async functions

general

  • await causes the function to pause until a Promise is fulfilled or rejected, and to resume execution of the async function after fulfillment. When resumed, the value of the await expression is that of the fulfilled Promise.
    • If the Promise is rejected, the await expression throws the rejected value.
    • If the value of the expression following the await operator is not a Promise, it's converted to a resolved Promise.

refs

@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?
@codeactual
codeactual / HasRootNavigationController.swift
Created November 20, 2021 16:13 — forked from michaelhenry/HasRootNavigationController.swift
UINavigationController in swiftUI.
import SwiftUI
import UIKit
protocol HasRootNavigationController {
var rootVC:UINavigationController? { get }
func push<Content:View>(view: Content, animated:Bool)
func setRootNavigation<Content:View>(views:[Content], animated:Bool)
func pop(animated: Bool)
func popToRoot(animated: Bool)