Skip to content

Instantly share code, notes, and snippets.

Avatar
🚀
Doing new things

Wil Gieseler wilg

🚀
Doing new things
View GitHub Profile
View tasks.swift
extension Task where Success == Void, Failure == Error {
@discardableResult
/// A task that performs a non-throwing `operation`.
static func strict<S>(priority: TaskPriority? = nil, operation: @escaping @Sendable () async -> S) -> Self {
Task(priority: priority, operation: {
_ = await operation()
})
}
}
@wilg
wilg / parallel_map.swift
Last active Nov 3, 2021 — forked from DougGregor/parallel_map.swift
Swift async/await implementation of a parallel map
View parallel_map.swift
import Foundation
// https://gist.github.com/DougGregor/92a2e4f6e11f6d733fb5065e9d1c880f
extension Collection {
func parallelMap<T>(
parallelism requestedParallelism: Int? = nil,
_ transform: @escaping (Element) async throws -> T
) async rethrows -> [T] {
let defaultParallelism = 2
let parallelism = requestedParallelism ?? defaultParallelism
@wilg
wilg / asyncMap.swift
Last active Apr 17, 2020
A helper function to make error propagation for asynchronous operations easier in Swift.
View asyncMap.swift
/// `asyncMap` helps you with error propagation for asynchronous tasks.
/// - Parameters:
/// - onFailure: A closure that will be called in an error condition if in an error state.
/// - onSuccess: A closure that will be called with your success value if succesful.
/// - Returns: A closure that will call `onError` if it is passed a failing result, and that will execute `onSuccess` if it is successful.
func asyncMap<Success, NeverSuccess, Error: Swift.Error>(
_ onFailure: @escaping ((Result<NeverSuccess, Error>) -> Void),
_ onSuccess: @escaping (Success) -> Void
) -> ((Result<Success, Error>) -> Void) {
return { result in
@wilg
wilg / example.eson.js
Last active Sep 10, 2019
ESON (or: yet another stab at slightly improving JSON)
View example.eson.js
// ESON is like JSON.
// ESON files should use the `.eson` file extension and the `application/eson` MIME type.
// This is meant to be as close to JSON as possible (and backwards compatible), but having learned a few lessons.
{
// It's backwards compatible with JSON.
"key": "value",
// Obviously, the big feature is it supports comments:
@wilg
wilg / index.js
Last active Oct 31, 2018 — forked from tommoor/index.js
requirebin sketch
View index.js
const React = require('react');
const ReactDOM = require ('react-dom');
const Render = require('react-emoji-render');
// try swapping the commented lines below and hit "Run Code" in the top right
// to see another rendering style!
const Emoji = Render.Emojione;
//const Emoji = Render.Twemoji;
@wilg
wilg / omnisharp.json
Created Jul 26, 2018
C# for Unity OmniSharp and VS Code Formatting Settings
View omnisharp.json
{
"FormattingOptions": {
"NewLine": "\n",
"IndentationSize": 4,
"NewLinesForBracesInMethods": false,
"NewLinesForBracesInAccessors": false,
"NewLinesForBracesInAnonymousMethods": false,
"NewLinesForBracesInAnonymousTypes": false,
"NewLinesForBracesInControlBlocks": false,
"NewLinesForBracesInLambdaExpressionBody": false,
View AutoLipSyncBlendshape.cs
using UnityEngine;
using System.Collections.Generic;
using System.Collections;
[RequireComponent (typeof (AudioSource))]
public class AutoLipSyncBlendshape : MonoBehaviour
{
public SkinnedMeshRenderer skinnedMeshRenderer;
View indiana_county_topojson_v3.topo.json
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@wilg
wilg / gist:b9cdd0274f24c743ad52
Created Jul 19, 2014
Embed an NSViewController in another view with auto layout
View gist:b9cdd0274f24c743ad52
- (void)embedViewController:(NSViewController *)controller inView:(NSView *)container {
[container addSubview:controller.view];
controller.view.translatesAutoresizingMaskIntoConstraints = NO;
controller.view.frame = container.bounds;
[container addConstraint:[NSLayoutConstraint constraintWithItem:container
attribute:NSLayoutAttributeTop
relatedBy:NSLayoutRelationEqual
toItem:controller.view
attribute:NSLayoutAttributeTop
multiplier:1.0
@wilg
wilg / GeneratePreviewForURL.m
Last active Aug 29, 2015
Quick Look Doesn't Work!
View GeneratePreviewForURL.m
#include <CoreFoundation/CoreFoundation.h>
#include <CoreServices/CoreServices.h>
#include <QuickLook/QuickLook.h>
#include <Cocoa/Cocoa.h>
OSStatus GeneratePreviewForURL(void *thisInterface, QLPreviewRequestRef preview, CFURLRef url, CFStringRef contentTypeUTI, CFDictionaryRef options);
void CancelPreviewGeneration(void *thisInterface, QLPreviewRequestRef preview);
OSStatus GeneratePreviewForURL(void *thisInterface, QLPreviewRequestRef preview, CFURLRef url, CFStringRef contentTypeUTI, CFDictionaryRef options)
{