Skip to content

Instantly share code, notes, and snippets.

View ik5's full-sized avatar
🎯
Focusing

ik5 ik5

🎯
Focusing
View GitHub Profile
@ik5
ik5 / generate_pki.rb
Created September 26, 2016 09:38
quick and dirty pki generator using ruby
require 'openssl'
require 'base64'
root_key = OpenSSL::PKey::RSA.new 2048 # the CA's public/private key
root_ca = OpenSSL::X509::Certificate.new
root_ca.version = 2 # cf. RFC 5280 - to make it a "v3" certificate
root_ca.serial = 1
root_ca.subject = OpenSSL::X509::Name.parse "/DC=org/DC=ruby-lang/CN=Ruby CA"
root_ca.issuer = root_ca.subject # root CA's are "self-signed"
root_ca.public_key = root_key.public_key
@ik5
ik5 / time_format_with_tz.go
Created October 11, 2016 14:36
Example for using format and timezone to display current time in format of "dd/mm/yyyy hh:MM::ss TZ"
package main
import (
"fmt"
"time"
)
func main() {
t := time.Now()
loc, err := time.LoadLocation("Asia/Jerusalem")
@ik5
ik5 / output
Last active October 11, 2016 17:46
Testing an INI library
Raw configuration:
[section] ; comment type of ; ?
item = 1 ; comment 2
arr = 1, 4, 5
str = "hey"
str2 = 'hey'
float = 1.10
[[second section]] # comment type of # ?
@ik5
ik5 / int64_join.go
Created October 11, 2016 23:32
Example on how to create join function for int64 - originally created it here: https://play.golang.org/p/KpdkVS1B4s
package main
import (
"fmt"
"strconv"
)
func UJoin(list []uint64, sep string) string {
length := len(list)
@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"
@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 / 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 / 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 / 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 / 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"
)