Skip to content

Instantly share code, notes, and snippets.

View zhangxu's full-sized avatar
🏠
Working from home

ZhangXu zhangxu

🏠
Working from home
View GitHub Profile
systemctl enable systemd-networkd.service
inetface=$(ip -o -br link |grep -E ^en | awk '{ print $1 }')
cat - << EOF > /etc/systemd/network/20-wired.network
[Match]
Name=${inetface}
[Network]
DHCP=yes
timedatectl set-timezone US/Pacific
hwclock --systohc --local
echo vault106 > /etc/hostname
cat - << EOF > /etc/hosts
127.0.0.1 localhost
::1 localhost
127.0.1.1 vault106
EOF
mkfs.ext4 /dev/sda1 && \
mount /dev/sda1 /mnt && \
pacstrap /mnt/ base linux linux-firmware net-tools networkmanager openssh neovim sudo && \
genfstab -U /mnt >> /mnt/etc/fstab
@zhangxu
zhangxu / bump-version.sh
Last active June 20, 2016 00:46
bump-version
#!/bin/sh
cd ~/workspace/opus-dev/product
#new sprint
find . -name bump-version -type l -exec {} --minor \;
#release
#hotfix
@zhangxu
zhangxu / docker-machine-osx.md
Last active April 10, 2016 04:48
Docker Machine on Mac OS X

#Create docker machine

Option 1

create docker machine with the following options docker-machine create --driver "virtualbox" --engine-insecure-registry "" --engine-opt "http_proxy=$http_proxy" --engine-opt "https_proxy=$https_proxy" --engine-opt "no_proxy=$no_proxy" default

Option 2

create the machine using default configuration. Then later modify the /var/lib/boot2docker/profile and then restart docker daemon

EXTRA_ARGS='
--label provider=virtualbox
--insecure-registry ossa.docker.oraclecorp.com
@zhangxu
zhangxu / docker-dangling-images.sh
Created March 25, 2016 02:13
Docker Dangling Images
#!/bin/bash
#switch to docker daemon A
#build the base dummy the first pass
cat - << EOF | docker build -t ossa.docker.oraclecorp.com/dummy/helloworld:latest -
FROM busybox
RUN echo "world" > hello.txt
EOF
docker push ossa.docker.oraclecorp.com/dummy/helloworld:latest
@zhangxu
zhangxu / generate-xls.rb
Created March 7, 2016 20:06
Generate Xls
@sheets = [
{
:name => "s 1",
:headers => ["h11", "h12"],
:rows => [["s1r1c1", "s1r1c2"], ["s1r2c1", "s1r2c2"]]
},
{
:name => "s2",
:headers => ["h21", "h22"],
:rows => [["s2r1c1", "s2r1c2"], ["s2r2c1", "s2r2c2"]]
@zhangxu
zhangxu / read-from-xls.rb
Last active February 23, 2016 22:28
Read from Xls File
require 'roo'
path = '/workspace/data/import.xls'
file_type = `file -b --mime-type #{path}`.strip
xls =
case file_type
when 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'application/xml', 'application/vnd.ms-office'
Roo::Spreadsheet.open(path)
@zhangxu
zhangxu / copy-ag-data-from-csv.sh
Last active October 29, 2015 18:13
Copy from CSV File to Table
#!/bin/bash
zipfile=$1
output_folder=/tmp/`echo $RANDOM`
sql="$output_folder"/copy.sql
test ! -d $output_folder || rm -rf $output_folder
unzip -q $zipfile "*DailyData.csv" -d $output_folder && \
echo "truncate table raw_ag_data;" > $sql && \
find $output_folder -name "*.csv" -type f -print0 | xargs -0 -I {} echo \
"\\copy raw_ag_data(farm_name,ranch_name,field_name,zone_name,date,temp_high,temp_low,temp_soil,wind_speed,avg_humidity,precipitation,cimis_et0,cimis_etc,observed_etc,degree_days,cum_degree_days,water_efficiency,quality_spread,wind_run,chillhours_45f,chillhours_32f) from '{}' csv header" >> $sql && \
cat - << EOF >> $sql
@zhangxu
zhangxu / poi_xls.scala
Last active October 13, 2015 22:14
Generating Excel Workbook Using Apache POI
import org.apache.poi.hssf.usermodel._
import org.apache.poi.ss.util._
import java.io._
val fileOut = new FileOutputStream("/tmp/workbook.xls")
val wb = new HSSFWorkbook
val sheet1 = wb.createSheet(WorkbookUtil.createSafeSheetName("new sheet"))
val sheet2 = wb.createSheet(WorkbookUtil.createSafeSheetName("second sheet"))