Skip to content

Instantly share code, notes, and snippets.

View ik5's full-sized avatar
🎯
Focusing

ik5 ik5

🎯
Focusing
View GitHub Profile
@ik5
ik5 / main.go
Created February 7, 2021 14:48
Example for getting machine hostname and all of it's IP numbers based on local devices
package main
import (
"fmt"
"net"
"os"
"strings"
)
// GetMachineInfo return a list of:
@ik5
ik5 / pause_resume.go
Created July 30, 2017 16:59
Example on pause and resume threads in golang
package main
import (
"fmt"
"runtime"
"time"
)
// Thread stages
const (
@ik5
ik5 / audio_windows.go
Last active October 2, 2020 05:12
Quick and dirty audio playing for MS Windows (No error validation) in Golang
// +build windows
package main
import (
"fmt"
"path/filepath"
"syscall"
"unsafe"
)
@ik5
ik5 / html_dom_example.php
Last active September 9, 2020 06:51
A simple example on reading a PHP <head> tag and print it's content including attributes
<?php
$doc = new DOMDocument();
$doc->loadHTMLFile('test.html', LIBXML_NOWARNING | LIBXML_NOERROR);
$nodes = $doc->getElementsByTagName('head');
if ($nodes->length <= 0) {
die('no head found');
}
@ik5
ik5 / israeli_id.py
Created September 7, 2020 18:26
calc israeli id number for valid last number in python 2
#!/usr/bin/env python2
def validate_id_number(id_num):
anID = id_num.zfill(9)
return sum(
sum(
map(
int, str(int(a)*(i % 2 + 1))
)
@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 / concat-wav.go
Created March 8, 2020 08:55
example on concating two (or more) wav files
package main
import (
"io"
"io/ioutil"
"github.com/moutend/go-wav"
)
func main() {
@ik5
ik5 / build.sh
Created January 2, 2020 09:26
shared object from go to c (re-take)
#!/usr/bin/env sh
echo "Building go library:"
go build -o libtest.so -buildmode=c-shared ./main.go || exit
echo "Building C executible:"
clang --verbose -DUSE_SHARED_LLVM=on -L/tmp/so -ltest -I/tmp/so main.c -o main -Wall || exit
echo "Done"
@ik5
ik5 / run-workers.sh
Created July 26, 2019 15:54
Creating 10 workers, takes the host ip using docker
#!/usr/bin/env bash
declare -i min=0
declare -i max=10
host=$(ip -4 addr show docker0 | grep -Po 'inet \K[\d.]+')
for (( c=min; c<max; c++ )) do
echo "Going to start worker # $c"
docker run\
@ik5
ik5 / language-layout.vue
Created July 22, 2019 10:01
solving layout changes in Vue.js
<template>
<ul class="language-selector">
<li
v-for="(language, idx) in $i18n.availableLocales"
:class="{selected: language === $i18n.locale}"
>
<a @click="changeLayout(language, $t(`languages.list[${idx}].bidi`))>
<Flag
:country="$t(`languages.list[${idx}].country-code`)"
:title="language"