Skip to content

Instantly share code, notes, and snippets.

// 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 {
@caelifer
caelifer / oms.go
Last active November 23, 2016 15:34
package main
import (
"fmt"
"log"
"sync"
)
func main() {
// Create OMS instance
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 November 10, 2016 21:39
Sample Linux filesystem create event watcher based on inotify(7) framework.
#!/bin/bash
handle() {
file=$1
if [ -f $file ]
then
{
# Send on the background
echo "Started processing '$file'"
let "n = $RANDOM % 9 + 1"
package main
import (
"errors"
"flag"
"io"
"io/ioutil"
"net"
"os"
"os/user"
@caelifer
caelifer / page_size.go
Last active October 27, 2016 12:41
Getting page size on POSIX system.
// +build !windows
package main
import (
"fmt"
"log"
)
/*
package main
import (
"fmt"
)
func main() {
fmt.Println("Sz", "Pg", "Bn", "Pad")
pageSize := 1 << 5
for _, off := range []int{10, 15, 16, 31, 33} {
package main
import (
"fmt"
"strings"
)
func main() {
strs := StringSlice{"Hello", "foo", "bar"}
ints := IntSlice{1, 2, 3, 4}
package main
import (
"fmt"
"unicode"
"golang.org/x/text/unicode/norm"
)
func main() {
package main
import (
"bufio"
"encoding/json"
"fmt"
"log"
"strings"
)