Skip to content

Instantly share code, notes, and snippets.

View xianlubird's full-sized avatar

Xianlu Bird xianlubird

View GitHub Profile
@xianlubird
xianlubird / main.go
Created October 11, 2018 07:40 — forked from nak3/main.go
test of viper and glog combination
package main
import (
"flag"
"fmt"
"github.com/golang/glog"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"github.com/spf13/viper"
#!/bin/bash
# Script to determine what named images and containers are dependent on the specified image (or a containers image) from stdin or in the args
# An unmatchable input is ignored
# All of the following will be found:
# Any image name / tag / name:tag / id that has a prefix in it that matches the input
# Any other image that relies on the images specified
# Any containers (running or not) that use any of these images
set -euf -o pipefail

Installing SSHPASS

SSHPass is a tiny utility, which allows you to provide the ssh password without using the prompt. This will very helpful for scripting. SSHPass is not good to use in multi-user environment. If you use SSHPass on your development machine, it don't do anything evil.

Installing on Ubuntu

apt-get install sshpass

Installing on OS X

#!/usr/bin/expect -f
set timeout 20
if { [llength $argv] < 1} {
puts "Usage:"
puts "$argv0 ip username passwd"
exit 1
}
set ip [lindex $argv 0]
@xianlubird
xianlubird / remove_slice.go
Created June 20, 2016 08:25
remove slice while loop a slice
for i := len(config.Applications) - 1; i >= 0; i-- {
application := config.Applications[i]
// Condition to decide if current element has to be deleted:
if haveToDelete {
config.Applications = append(config.Applications[:i],
config.Applications[i+1:]...)
}
}
@xianlubird
xianlubird / heapsort.go
Created March 12, 2016 02:15
堆排序,go实现
// HeapSort project main.go
package main
import (
"fmt"
)
func HeapSort(s []int) {
length := len(s) - 1 //s[0]不用,实际元素数量和最后一个元素的角标都为length
//构造堆
@xianlubird
xianlubird / validate_uuid4.py
Created February 21, 2016 15:12 — forked from ShawnMilo/validate_uuid4.py
Validating a uuid4 with Python.
from uuid import UUID
def validate_uuid4(uuid_string):
"""
Validate that a UUID string is in
fact a valid uuid4.
Happily, the uuid module does the actual
checking for us.
@xianlubird
xianlubird / print_all_attr.py
Created February 21, 2016 15:05
打印一个对象的所有属性和值的对¶
for pro, value in vars(object).iteritems():
print pro, ": ", value
@xianlubird
xianlubird / 0_reuse_code.js
Created October 28, 2015 07:48
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console