Skip to content

Instantly share code, notes, and snippets.

View unakatsuo's full-sized avatar

Masahiro Fujiwara unakatsuo

View GitHub Profile
@unakatsuo
unakatsuo / main.go
Created June 6, 2022 16:50
Copy from a pointer of Go fixed array to a C array.
package main
/*
#include <stdlib.h>
#include <string.h>
struct AAA {
char a[10];
};
*/
@unakatsuo
unakatsuo / gist:718ba2a9edd2cc44f2535558a4133e54
Created January 12, 2021 07:35
Detect an interface if it has a PPPoE peer
# Sends PADI then waits for PADO during 5 sec
pppoe -d -A -t 5
@unakatsuo
unakatsuo / iprange.go
Created December 7, 2020 12:05
IP range iteration utility for golang
// IterateIPRange calculates the sequence of IP address from beginAddr to endAddr
// then calls the callback cb for each address of the sequence.
// beginAddr value must be smaller than endAddr.
func IterateIPRange(beginAddr, endAddr net.IP, cb func(addr net.IP)) error {
incIP := func(ip net.IP) net.IP {
for j := len(ip) - 1; j >= 0; j-- {
ip[j]++
if ip[j] > 0 {
break
}
@unakatsuo
unakatsuo / meta-data
Last active March 4, 2020 09:43
Packer template for Ubuntu 18.04 cloud image + VirutualBox.
local-hostname: ubuntu1
@unakatsuo
unakatsuo / debian.sh
Created February 25, 2020 06:55
Switch by /etc/os-release
#!/bin/sh
set -e
. /etc/os-release
case "${ID} ${ID_LIKE}" in
*ubuntu*) ;;
*debian*) ;;
*)
@unakatsuo
unakatsuo / gist:64abd3ff70ab9d96131a4acf4ab8214e
Created July 2, 2019 08:19
Onliner which compares kernel version just using coreutils.
# test/[, uname, sort and head are from coreutils.
% uname -r
4.20.11-1.el7.elrepo.x86_64
% [ "4.12" == $((echo "4.12"; echo $(uname -r)) | sort --version-sort | head -1) ]
% echo $?
0
@unakatsuo
unakatsuo / tee-bash4.4.sh
Last active April 4, 2019 15:09
Capture exit code from pipe command and stdout gets the original outputs.
#!/bin/bash
set -e
OUTPUTSCRIPT="test1"
test1(){
timeout 3 grep 5 > /dev/null
echo "found 5"
@unakatsuo
unakatsuo / gist:5af19c9e646413b25955724630c906e7
Created March 13, 2019 12:01
docker-ce-18.09 service file override
[Service]
ExecStart=
ExecStart=/usr/bin/dockerd --icc=true --dns 8.8.8.8 -H fd://
# --icc=true: Set ACCEPT to the iptables forward chain policy.
# --dns=8.8.8.8: Avoid DNS error during docker build.
@unakatsuo
unakatsuo / README.md
Created January 6, 2019 09:54
Running strongswan in Linux net namespace.

Version:

  • strongswan-5.7.1-1.el7.x86_64
@unakatsuo
unakatsuo / jenkins-slave
Created November 10, 2018 11:20
systemd Jenkins JNLP Slave service
JENKINS_URL=http://192.168.1.57:8080
JENKINS_WORKSPACE=/home/jenkins/workspace
JENKINS_NODE=node1