Skip to content

Instantly share code, notes, and snippets.

package disruptor
import (
"encoding/binary"
"log"
"runtime"
"sync/atomic"
"time"
)
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().
[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]
package main
import (
"fmt"
"math/rand"
"time"
)
type Fork struct{}
package main
import (
"errors"
"flag"
"io"
"io/ioutil"
"net"
"os"
"os/user"
// 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 (
"encoding/base64"
"fmt"
"log"
)
type MorseChar string