Skip to content

Instantly share code, notes, and snippets.

View flavio-fernandes's full-sized avatar

Flavio Fernandes flavio-fernandes

View GitHub Profile
@flavio-fernandes
flavio-fernandes / .bashrc_vagrant.sh
Last active July 5, 2016 15:48 — forked from purpleidea/.bashrc_vagrant.sh
# Vagrant vsftp and other tricks# from: https://ttboj.wordpress.com/2013/12/21/vagrant-vsftp-and-other-tricks/# and# Vagrant clustered SSH and 'screen'# from: https://ttboj.wordpress.com/2014/01/02/vagrant-clustered-ssh-and-screen/# for use inside a ~/.bashrc or similar
# vagrant vsftp and other tricks
# from: https://ttboj.wordpress.com/2013/12/21/vagrant-vsftp-and-other-tricks/
# and
# Vagrant clustered SSH and 'screen'
# from: https://ttboj.wordpress.com/2014/01/02/vagrant-clustered-ssh-and-screen/
# for use inside a ~/.bashrc or similar
# copyright James Shubin, 2013, agplv.3+
### VAGRANT ###################################################################
# avoid needing to always add --provider=kvm

Let's say you have a Bash shell script, and you need to run a series of operations on another system (such as via ssh). There are a couple of ways to do this.

First, you can stage a child script on the remote system, then call it, passing along appropriate parameters. The problem with this is you will need to manually keep the remote script updated whenever you change it -- could be a bit of a challenge when you have something to execute on a number of remote servers (i.e., you have a backup script running on a central host, and it needs to put remote databases in hot backup mode before backing them up).

Another option is to embed the commands you want to run remotely within the ssh command line. But then you run into issues with escaping special characters, quoting, etc. This is ok if you only have a couple commands to run, but if it is a complex piece of Bash code, it can get a bit unwieldy.

So, to solve this, you can use a technique called rpcsh -- rpc in shell script, as follows:

First, place th

@flavio-fernandes
flavio-fernandes / bug and fix bug
Created May 26, 2018 14:47
C Linked List Data Structure Explained with an Example C Program
https://www.thegeekstuff.com/2012/08/c-linked-list-example/
$ diff -u orig.c bug.c
--- orig.c 2018-05-26 14:40:12.495407923 +0000
+++ bug.c 2018-05-26 14:41:03.335407923 +0000
@@ -150,6 +150,10 @@
print_list();
+ add_to_list(666,true);
@flavio-fernandes
flavio-fernandes / lb.go
Last active July 10, 2018 14:37
poormans' load balancer
package main
import (
"fmt"
"net"
"os"
"sync"
"io"
"strconv"
"flag"
#!/bin/bash
virt-addr() {
VM="$1"
vm_mac=$(virsh dumpxml $VM | grep "mac address" | sed "s/.*'\(.*\)'.*/\1/g")
arp -an | grep "${vm_mac}" | awk '{ gsub(/[\(\)]/,"",$2); print $2 }'
}
for x in $(virsh list --all | awk '{ if (NR > 2 && $2 != "") {print $2} }') ; do \
v=$(virsh vncdisplay $x 2> /dev/null || true)
@flavio-fernandes
flavio-fernandes / helm with no tiller
Created August 16, 2018 03:24
Error: could not find tiller
steps from trying https://github.com/tvieira/presentations/blob/master/kiali/DEMO.md
pre-reqs:
# install kvm...
sudo apt -y install uvtool ; # installs uvt-simplestreams-libvirt and uvt-kvm
time uvt-simplestreams-libvirt sync release=xenial arch=amd64
=-==-=-=
VM=minik
@flavio-fernandes
flavio-fernandes / gopacket.log
Created November 3, 2018 19:42
gopacket issues with old golang
vagrant@vagrant-ubuntu-trusty-64:~$ echo $GOPATH
/home/vagrant/go
vagrant@vagrant-ubuntu-trusty-64:~$
vagrant@vagrant-ubuntu-trusty-64:/vagrant/nfvapp$ cd ; rm -rf go ; mkdir -pv ~/go ; eval "$(gimme stable)"
mkdir: created directory ‘/home/vagrant/go’
go version go1.11.2 linux/amd64
vagrant@vagrant-ubuntu-trusty-64:~$ go version ; go get github.com/google/gopacket
go version go1.11.2 linux/amd64
vagrant@vagrant-ubuntu-trusty-64:~$ cd /vagrant/nfvapp && go build nfvapp.go && echo yay
yay
@flavio-fernandes
flavio-fernandes / gist:b1f40808307aed0386215bf1d74d087a
Last active December 21, 2018 10:57
Career Thoughts -- a personal reflection for the holidays
I've been doing this for a while. Over the years, this is the recipe that makes the most sense to me:
* be good at what you do -- there is no replacement for true competence in the computing industry;
* have fun -- together with being good, having fun makes you able to gracefully handle the work when things get challenging;
* burning bridges is a form of suicide -- there is no room for arrogance in this industry, it is a small world;
* working smart is as important as working hard -- burnout is real and life is short;
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: foo-example
namespace: default
spec:
replicas: 2
template:
metadata:
apiVersion: serving.knative.dev/v1alpha1
kind: Service
metadata:
name: foo-example-knative
namespace: default
spec:
runLatest:
configuration:
revisionTemplate:
spec: