| Latency Comparison Numbers (~2012) | |
| ---------------------------------- | |
| L1 cache reference 0.5 ns | |
| Branch mispredict 5 ns | |
| L2 cache reference 7 ns 14x L1 cache | |
| Mutex lock/unlock 25 ns | |
| Main memory reference 100 ns 20x L2 cache, 200x L1 cache | |
| Compress 1K bytes with Zippy 3,000 ns 3 us | |
| Send 1K bytes over 1 Gbps network 10,000 ns 10 us | |
| Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD |
| // General hints on defining types with constraints or invariants | |
| // | |
| // Just as in C#, use a private constructor | |
| // and expose "factory" methods that enforce the constraints | |
| // | |
| // In F#, only classes can have private constructors with public members. | |
| // | |
| // If you want to use the record and DU types, the whole type becomes | |
| // private, which means that you also need to provide: | |
| // * a constructor function ("create"). |
| // This is a bare bones example of creating a data channel between two WebRTC | |
| // peers. Let's imagine two peers trying to connect to each other. We'll call | |
| // one the "offer peer", and the other the "answer peer". The offer peer will | |
| // be the one initiating a connection, and the answer peer will be the one | |
| // responding to it. | |
| // | |
| // The two peers must use a separate connection to negotiate their connection. | |
| // A websocket connection to a shared server is often used for this negotiation. | |
| // They will exchange offers and answers using the websocket. Each peer will | |
| // also attempt to discover more details about themselves (ICE), such as their |
| package main | |
| import ( | |
| "encoding/json" | |
| "fmt" | |
| "reflect" | |
| ) | |
| type Message struct { | |
| Data string |
| MIT License | |
| Copyright (c) 2020 Zhu Liang | |
| Permission is hereby granted, free of charge, to any person obtaining a copy | |
| of this software and associated documentation files (the "Software"), to deal | |
| in the Software without restriction, including without limitation the rights | |
| to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
| copies of the Software, and to permit persons to whom the Software is | |
| furnished to do so, subject to the following conditions: |
| // Unfortunatelly it stopped working in F# 4.1 after this PR https://github.com/Microsoft/visualfsharp/pull/1650 | |
| // Will ask to revert it | |
| type FoldArgs<'t> = FoldArgs of ('t -> 't -> 't) | |
| let inline foldArgs f (x:'t) (y:'t) :'rest = (FoldArgs f $ Unchecked.defaultof<'rest>) x y | |
| type FoldArgs<'t> with | |
| static member inline ($) (FoldArgs f, _:'t-> 'rest) = fun (a:'t) -> f a >> foldArgs f | |
| static member ($) (FoldArgs f, _:'t ) = f |
A few days ago, I mentioned to Rob Ballou, that there's just something very satisfying about shell scripting. Once you've groked all its little idiosyncracies, it's really quite addictive. As developers, I think we all get some gratification from getting things done, but also from building elegant, complete systems. For me, shell scripting really scratches all those itches. I get to build a system from start to finish, completely self-contained and solve a real problem.
Elegant, complete systems might at first seem antithetical to what most people think of shell scripting. Shell scripting is plagued by weird quoting, strange unfamiliar constructions, and a lack useful data types. However, once you embrace the things that shell scripting is good at and learn a few strategies for writing scripts tidily, it can become a fantastic tool for solving real, every day problems.
So, what are those strategies and what are things that the shell does well?
#!/bin/bash| # Linux | |
| # add the following to "~/.gitconfig" file | |
| [merge] | |
| tool = intellij | |
| [mergetool "intellij"] | |
| cmd = /usr/local/bin/idea merge $(cd $(dirname "$LOCAL") && pwd)/$(basename "$LOCAL") $(cd $(dirname "$REMOTE") && pwd)/$(basename "$REMOTE") $(cd $(dirname "$BASE") && pwd)/$(basename "$BASE") $(cd $(dirname "$MERGED") && pwd)/$(basename "$MERGED") | |
| trustExitCode = true | |
| [diff] |
| package pools | |
| import ( | |
| "sync" | |
| "time" | |
| ) | |
| var timerPool sync.Pool | |
| // AcquireTimer returns time from pool if possible. |