Skip to content

Instantly share code, notes, and snippets.

View ik5's full-sized avatar
🎯
Focusing

ik5 ik5

🎯
Focusing
View GitHub Profile
@ik5
ik5 / scryp.go
Created March 2, 2017 20:35
example on using scrypt
package main
import (
"crypto/rand"
"fmt"
"golang.org/x/crypto/scrypt"
)
func main() {
@ik5
ik5 / main.go
Created February 18, 2017 10:33
go 1.8 plugins
package main
import "C"
import (
"fmt"
"plugin"
)
func main() {
p, err := plugin.Open("./plugins.so")
@ik5
ik5 / requeue.go
Created January 28, 2017 19:49
how to re-queue a scheduled item in amqp
package main
import (
"fmt"
"net/url"
"github.com/streadway/amqp"
)
// InitByConfigServices loads configuration from a conf file
@ik5
ik5 / to_uint64.go
Created January 27, 2017 13:09
convert a list of items in a string to a uint64 list
package main
import (
"fmt"
"strconv"
"strings"
)
func toUin64(data, sep string) []uint64 {
fields := strings.Split(data, sep)
@ik5
ik5 / main.go
Created January 21, 2017 15:26
Listen to a Pg event in go
package main
import (
"database/sql"
"fmt"
"time"
"github.com/lib/pq"
)
@ik5
ik5 / tar_handler.rb
Created November 29, 2016 17:00
Work with native TAR files on Ruby
# based on https://gist.github.com/sinisterchipmunk/1335041
require 'rubygems/package'
require 'fileutils'
require 'zlib'
def create_tar(path, opts={})
tarfile = StringIO.new("")
Gem::Package::TarWriter.new(tarfile) do |tar|
Dir[File.join(path, "**/*")].each do |file|
mode = File.stat(file).mode
@ik5
ik5 / time_format.go
Created November 9, 2016 09:04
A full example of all possible time formats in Golang
package main
import (
"fmt"
"time"
)
func main() {
fmt.Println("Times: ")
t := time.Now()
@ik5
ik5 / searchString.go
Created October 12, 2016 18:26
searches for elements in a slice
package main
import "fmt"
func sliceIndex(limit int, predicate func(i int) bool) int {
for i := 0; i < limit; i++ {
if predicate(i) {
return i
}
}
@ik5
ik5 / load_lib.go
Created October 12, 2016 12:57
loading external shared library made by go
package main
// #cgo LDFLAGS: -L /path/to/lib/ -lgolibrary
//
// #include <golibrary_header.h>
//
import "C"
func main() {
C.func2()
@ik5
ik5 / libgolibrary.go
Last active October 12, 2016 13:03
Creating
package main
/*
go build -buildmode=c-shared -o libgolibrary.so libgolibrary.go
go tool cgo
*/
import "C"
import "fmt"