Skip to content

Instantly share code, notes, and snippets.

View ik5's full-sized avatar
🎯
Focusing

ik5 ik5

🎯
Focusing
View GitHub Profile
@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 / 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 / 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 / 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 / empty_string.c
Last active July 5, 2016 12:46
example on how to validate if a dynamic array of chars is empty
#include <stdio.h>
#include <string.h>
int empty_string(char * str) {
return(str == NULL || strlen(str) == 0 );
}
int main(int argc, char **argv) {
char * ch = NULL;
@ik5
ik5 / uuid_regex.rb
Last active May 26, 2016 09:02
small regex to find a uuid in a sting
puts $1 if str =~ /([a-fA-F\d]{8}(-[a-fA-F\d]{4}){3}-[a-fA-F\d]{12}?)/
@ik5
ik5 / conf.json
Created January 2, 2016 15:12
An example for dynamic configuration loading in ruby (using json)
{
"key1": "string",
"key2": true,
"key3": 10,
"nested": {
"nested_key1": [1]
}
}
@ik5
ik5 / colors.go
Last active January 3, 2025 00:23
Simple golang expirement with ANSI colors
package main
// http://play.golang.org/p/jZ5pa944O1 <- will not display the colors
import "fmt"
const (
InfoColor = "\033[1;34m%s\033[0m"
NoticeColor = "\033[1;36m%s\033[0m"
WarningColor = "\033[1;33m%s\033[0m"
ErrorColor = "\033[1;31m%s\033[0m"
DebugColor = "\033[0;36m%s\033[0m"
@ik5
ik5 / gist:65de721ca495fa1bf451
Last active August 5, 2020 11:58 — forked from bradleypeabody/gist:185b1d7ed6c0c2ab6cec
golang, convert UTF-16 to UTF-8 string
package main
import "fmt"
import "unicode/utf16"
import "unicode/utf8"
import "bytes"
func main() {
b := []byte{
@ik5
ik5 / gsm0338.go
Created August 18, 2015 09:46
Functions to convert between UTF8 and GSM 03.38 in go
package main
import (
"fmt"
"regexp"
"strings"
)
var utf8GsmChars = map[string]string{
`@`: "\x00", `£`: "\x01", `$`: "\x02",