Skip to content

Instantly share code, notes, and snippets.

caelifer

Block or report user

Report or block caelifer

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@caelifer
caelifer / phone.go
Created Jan 7, 2020
Figure out if the phone number is correct without asking for it directly.
View phone.go
// This program provides an answer for one of the Google interview questions described here:
// https://www.businessinsider.com/answers-to-google-interview-questions-2011-11#you-need-to-check-that-your-friend-bob-has-your-correct-phone-number-10
package main
import (
"fmt"
"strings"
)
func main() {
@caelifer
caelifer / change.go
Last active Dec 10, 2019
Calculate change from available pool of coins simulating automatic cash register.
View change.go
package main
import (
"fmt"
"log"
"strings"
)
func main() {
b := NewBank(map[Coin]int{
View disruptor.go
package disruptor
import (
"encoding/binary"
"log"
"runtime"
"sync/atomic"
"time"
)
View moveFile.go
import (
"io"
"io/ioutil"
"os"
"path/filepath"
)
// moveFile safely moves files across different file systems.
func moveFile(src, dest string) error {
// Fast path: use os.Rename().
View .gitconfig
[alias]
lg1 = log --graph --abbrev-commit --decorate --date=relative --pretty=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C(dim yellow) - %an%C(reset)%C(bold yellow)%d%C(reset)' --all
lg2 = log --graph --abbrev-commit --decorate --date=relative --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%C(reset)'
lg = !"git lg1"
co = checkout
ci = commit
stat = status
sync-master = "!git checkout master && git fetch upstream && git reset --hard upstream/master"
sync-branch = "!git fetch upstream && git merge upstream/master"
[push]
View thinkers.go
package main
import (
"fmt"
"math/rand"
"time"
)
type Fork struct{}
View memorized-fibonacci.go
package main
import (
"fmt"
)
func main() {
for i := 0; i <= 45; i++ {
fmt.Printf("%3d %10d\n", i, memFib(i))
}
View ssh_client.go
package main
import (
"errors"
"flag"
"io"
"io/ioutil"
"net"
"os"
"os/user"
View io-pipe-examples.go
// Stolen from https://zupzup.org/io-pipe-go/
pr, pw := io.Pipe()
go func() {
// close the writer, so the reader knows there's no more data
defer pw.Close()
// write json data to the PipeReader through the PipeWriter
if err := json.NewEncoder(pw).Encode(&PayLoad{Content: "Hello Pipe!"}); err != nil {
View oms.go
package main
import (
"fmt"
"log"
"sync"
)
func main() {
// Create OMS instance
You can’t perform that action at this time.