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
View disruptor.go
package disruptor
import (
"encoding/binary"
"log"
"runtime"
"sync/atomic"
"time"
)
@caelifer
caelifer / change.go
Last active Oct 27, 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 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 memorized-fibonacci.go
package main
import (
"fmt"
)
func main() {
for i := 0; i <= 45; i++ {
fmt.Printf("%3d %10d\n", i, memFib(i))
}
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
View pangram.go
package main
import (
"fmt"
"unicode"
)
func main() {
for _, tc := range []string{
"the quick brown fox jumps over the lazy dog",
@caelifer
caelifer / linux_watch_fs_create_event.sh
Last active Nov 10, 2016
Sample Linux filesystem create event watcher based on inotify(7) framework.
View linux_watch_fs_create_event.sh
#!/bin/bash
handle() {
file=$1
if [ -f $file ]
then
{
# Send on the background
echo "Started processing '$file'"
let "n = $RANDOM % 9 + 1"
View ssh_client.go
package main
import (
"errors"
"flag"
"io"
"io/ioutil"
"net"
"os"
"os/user"
@caelifer
caelifer / page_size.go
Last active Oct 27, 2016
Getting page size on POSIX system.
View page_size.go
// +build !windows
package main
import (
"fmt"
"log"
)
/*
You can’t perform that action at this time.