Skip to content

Instantly share code, notes, and snippets.

def get_interface_name
interfaces = {}
puts 'Valid network interfaces detected are:'
interfaces_with_mac = `ifconfig -a | grep -i hwaddr | awk '{ if( match($1, /^eth/) ) {print $1, $5} }'`.lines.map(&:chomp)
interfaces_with_mac.each_with_index do |x, index|
interfaces[index] = x.split[0]
puts " #{index}) #{x.split[0]} ( #{x.split[1]} )"
end
print 'Please choose an interface to configure: '
import java.io.IOException;
import java.io.InputStream;
import com.jcraft.jsch.Channel;
import com.jcraft.jsch.ChannelExec;
import com.jcraft.jsch.JSch;
import com.jcraft.jsch.JSchException;
import com.jcraft.jsch.Session;
public class Exec {
@kfei
kfei / Python: virsh-batch-start-vm.py
Last active August 29, 2015 14:02
Python: virsh-batch-start-vm
#!/usr/bin/env python
import sys
import threading
import Queue
import commands
import time
# thread class to run a command
import multiprocessing
def thread_func():
print "thread in"
while True:
pass
if __name__ == "__main__":
t1 = multiprocessing.Process(target = thread_func)
t1.start()
@kfei
kfei / fileio3.py
Created October 13, 2014 02:35
A Python3 ZMQ file transfer example
# File Transfer model #3
#
# In which the client requests each chunk individually, using
# command pipelining to give us a credit-based flow control.
import os
import sys
from threading import Thread
import zmq
addrs bits pref mask
1 0 /32 255.255.255.255
2 1 /31 255.255.255.254
4 2 /30 255.255.255.252
8 3 /29 255.255.255.248
16 4 /28 255.255.255.240
32 5 /27 255.255.255.224
64 6 /26 255.255.255.192
128 7 /25 255.255.255.128
@kfei
kfei / cpu-burn.sh
Created November 30, 2014 14:02
Burn CPU
# burn your 4 cores
for i in 1 2 3 4; do while : ; do : ; done & done
@kfei
kfei / gist:3e7f6de180ac84dd7fa1
Last active August 29, 2015 14:10
Redis Dockerfile
RUN buildDeps='gcc libc6-dev make'; \
set -x \
&& apt-get update && apt-get install -y $buildDeps --no-install-recommends \
&& rm -rf /var/lib/apt/lists/* \
&& mkdir -p /usr/src/redis \
&& curl -sSL "$REDIS_DOWNLOAD_URL" -o redis.tar.gz \
&& echo "$REDIS_DOWNLOAD_SHA1 *redis.tar.gz" | sha1sum -c - \
&& tar -xzf redis.tar.gz -C /usr/src/redis --strip-components=1 \
&& rm redis.tar.gz \
&& make -C /usr/src/redis \
@kfei
kfei / gist:5dbb32f118f373fc1a47
Last active April 25, 2020 03:25
Convert GIF using ffmpeg and ImageMagick
# Use ffmpeg to decode input video (GIF in this case)
ffmpeg -i input.gif decode/%d.png
# Use ImageMagick to crop, format: (W)x(H)+(W_SFHIT)+(H_SHIFT)
# Note the {from..to..skip} usage of Bash
convert decoded/{1..759..5}.png -crop 315x172+20+40 resized/%d.png
# An resize option
# convert decoded/{1..759..5}.png -crop 315x172+20+40 -resize 30% resized/%d.png
@kfei
kfei / gist:53a680d53bea1bab9f4c
Created January 8, 2015 16:12
Go: pass to C main
func main() {
args := os.Args
arg := make([](*_Ctype_char), 0)
l := len(args)
for i, _ := range args {
char := C.CString(args[i])
// defer C.free(unsafe.Pointer(char))
strptr := (*_Ctype_char)(unsafe.Pointer(char))
arg = append(arg, strptr)
}