Skip to content

Instantly share code, notes, and snippets.

@artefactop
artefactop / async_swift_proposal.md
Created August 4, 2026 00:17 — forked from lattner/async_swift_proposal.md
Concrete proposal for async semantics in Swift

Async/Await for Swift

Introduction

Modern Cocoa development involves a lot of asynchronous programming using closures and completion handlers, but these APIs are hard to use. This gets particularly problematic when many asynchronous operations are used, error handling is required, or control flow between asynchronous calls gets complicated. This proposal describes a language extension to make this a lot more natural and less error prone.

This paper introduces a first class Coroutine model to Swift. Functions can opt into to being async, allowing the programmer to compose complex logic involving asynchronous operations, leaving the compiler in charge of producing the necessary closures and state machines to implement that logic.

@artefactop
artefactop / mysql_replication.go
Created April 21, 2017 07:39
Get mysql bin log and execute those operations in other server
package main
import (
"fmt"
"github.com/siddontang/go-mysql/client"
"github.com/siddontang/go-mysql/mysql"
"github.com/siddontang/go-mysql/replication"
"os"
)
package main
import (
"fmt"
"log"
"net"
"os"
"strconv"
"time"
)
# Delete remote branches already merged with development
git branch -a --merged | grep -v "\*" | grep -v master | grep -v main | grep -v develop | cut -d'/' -f 3-4 | xargs -n 1 -I {} git push origin :{}
# Delete local merged branches
git branch --merged | grep -v "\*" | grep -v master | grep -v main | grep -v dev | xargs -n 1 -I {} git branch -d {}
# Delete local squashed branches DANGEROUS https://github.com/not-an-aardvark/git-delete-squashed
git for-each-ref refs/heads/ "--format=%(refname:short)" | while read branch; do mergeBase=$(git merge-base master $branch) && [[ $(git cherry master $(git commit-tree $(git rev-parse $branch\^{tree}) -p $mergeBase -m _)) == "-"* ]] && git branch -D $branch; done
# Delete all local branches except main
@artefactop
artefactop / docker_tips
Last active January 25, 2017 14:56
Docker tooltips
# Remove all untagged images
docker rmi $(docker images | grep "^<none>" | awk '{print $3}')
# Remove all unused images
docker images -q |xargs docker rmi
@artefactop
artefactop / bin_to_hex.erl
Last active August 29, 2015 14:28
Erlang formatting a binary to hex
%% @doc Optimized HEX encoder.
%% Source http://stackoverflow.com/questions/3768197/erlang-ioformatting-a-binary-to-hex
-module(bin_to_hex).
-compile([native, {hipe, [o3]}]).
-export([bin_to_hex/1]).
bin_to_hex(B) when is_binary(B) ->
bin_to_hex(B, <<>>).
@artefactop
artefactop / parse_csv.erl
Last active June 10, 2024 19:25
Read csv file in Erlang
#!/usr/bin/env escript
-record(ecsv,{
state = field_start, %%field_start|normal|quoted|post_quoted
cols = undefined, %%how many fields per record
current_field = [],
current_record = [],
fold_state,
fold_fun %%user supplied fold function
}).
@artefactop
artefactop / jwt_example.go
Created January 22, 2015 14:43
jwt example
package main
import (
"errors"
"fmt"
"github.com/dgrijalva/jwt-go"
"time"
)
type User struct {
@artefactop
artefactop / get_random
Created July 24, 2013 09:31
Get N random elements from a list
#!/usr/bin/env escript
main([NS, SL]) ->
try
N = list_to_integer(NS),
List = eval(SL),
io:format("Result: ~p~n", [random(List,N)])
catch
_:_ ->
usage()
@artefactop
artefactop / calendar_iso8601.erl
Created May 21, 2013 18:04
erlang dates to integer iso8601
date_to_integer_iso8601({date,{Y,M,D}}) ->
datetime_to_integer_iso8601({datetime,{{Y,M,D},{0,0,0}}}).
datetime_to_integer_iso8601({datetime,{{Y,M,D},{H,Min,S}}}) ->
Y * 10000000000 + M * 100000000 + D * 1000000 + H * 10000 + Min * 100 + S.