Skip to content

Instantly share code, notes, and snippets.

View jonatw's full-sized avatar
🌴
On vacation

Jonathan Huang jonatw

🌴
On vacation
View GitHub Profile
@jonatw
jonatw / linit7688_sdcard_rootfs.sh
Last active May 18, 2017 14:29
LinkIt7688 use sdcard as rootfs after factory reset ref: http://labs.mediatek.com/forums/posts/list/3619.page
#!/bin/ash
# ref http://labs.mediatek.com/forums/posts/list/3619.page
opkg update
opkg install block-mount kmod-fs-ext4 kmod-usb-storage-extras e2fsprogs
umount /tmp/run/mountd/mmcblk0p1
mkfs.ext4 -F /dev/mmcblk0p1
mount /dev/mmcblk0p1 /mnt
tar -C /overlay -cvf - . | tar -C /mnt -xf -
umount /dev/mmcblk0p1
block detect > /etc/config/fstab
wget -O /opt/cw.zip http://ec2-downloads.s3.amazonaws.com/cloudwatch-samples/CloudWatchMonitoringScripts-v1.1.0.zip
unzip /opt/cw.zip -d /opt/
rm -f /opt/cw.zip
yum install -y openssl openssl-devel perl-ExtUtils-MakeMaker
curl -L http://cpanmin.us | perl - --self-upgrade
cpanm Digest::SHA Bundle::LWP5_837 LWP LWP::Protocol::https
IAM_ROLE=`curl http://169.254.169.254/latest/meta-data/iam/security-credentials/`
DISK_PARAM=`mount |grep -E '[s|xv]d|mapper' | awk '{print "--disk-path="$3}' | tr '\n' ' '`
# {Rails.root}/shippable.yml
# shippleable example for rails 4 with mysql
language: ruby
rvm:
- 2.0.0
env:
- CI_REPORTS=shippable/testresults COVERAGE_REPORTS=shippable/codecoverage
#!/bin/bash
# please install aws-cli first
# easy_install pip
# pip install awscli
# project parameters
PROJECT_NAME='SomeCoolPropject'
SAMPLE_COUNT=20;
INTERVAL=0.5;
@jonatw
jonatw / nvidia_gpu_top.sh
Created March 3, 2014 10:27
home-made GPU top using nvidia-smi
#!/bin/bash
SAMPLE_COUNT=20;
INTERVAL=0.5;
for (( c=1; c<=$SAMPLE_COUNT; c++ )); do nvidia-smi --query-gpu=utilization.gpu,utilization.memory --format=csv,noheader,nounits >> /tmp/GPU_$TIMESTAMP; sleep $INTERVAL; done;
GPU_USG_SUM=`cat /tmp/GPU_$TIMESTAMP | sed 's/, / /g' | awk '{sum+=$1}END{print sum}'`
GPU_USG_MIN=`cat /tmp/GPU_$TIMESTAMP | sed 's/, / /g' |cut -d ' ' -f 1 | sort | head -n 1`
GPU_USG_MAX=`cat /tmp/GPU_$TIMESTAMP | sed 's/, / /g' |cut -d ' ' -f 1 | sort | tail -n 1`
@jonatw
jonatw / get_ec2_iam_role_credentials.sh
Last active August 29, 2015 13:56
this script allows ec2 instances to obtain iam role security credentials by query instance meta-data api
#!/bin/bash
function get_iam_role_credentials(){
BASE_URL='http://169.254.169.254/latest/meta-data/'
export AWS_DEFAULT_REGION=`curl -s $BASE_URL/placement/availability-zone | sed -e 's:\([0-9][0-9]*\)[a-z]*\$:\\1:'`
export AWS_ROLE_NAME=`curl -s $BASE_URL/iam/security-credentials/`
export AWS_ACCESS_KEY_ID=`curl -s $BASE_URL/iam/security-credentials/$ROLE_NAME | grep AccessKeyId | awk '{print $3}' | cut -d '"' -f 2`
export AWS_SECRET_ACCESS_KEY=`curl -s $BASE_URL/iam/security-credentials/$ROLE_NAME | grep SecretAccessKey | awk '{print $3}' | cut -d '"' -f 2`
export AWS_SECURITY_TOKEN=`curl -s $BASE_URL/iam/security-credentials/$ROLE_NAME | grep Token | awk '{print $3}' | cut -d '"' -f 2`
}
#! /bin/sh
### BEGIN INIT INFO
# Provides: chef-client
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Initscript to run chef-client daemon
# Description: Starts the chef-client daemon automatically upon start
### END INIT INFO
#!/usr/bin/env bash
apt-get -y update
apt-get -y install build-essential zlib1g-dev libssl-dev libreadline5-dev libyaml-dev
cd /tmp
wget http://ruby.taobao.org/mirrors/ruby/1.9/ruby-1.9.3-p194.tar.gz
tar -xvzf ruby-1.9.3-p194.tar.gz
cd ruby-1.9.3-p194/
./configure --prefix=/usr/local --disable-install-rdoc
make
#!/usr/bin/env bash
# Pre-requisites
sudo apt-get -y update
sudo apt-get --no-install-recommends -y install build-essential openssl libreadline6 libreadline6-dev curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev libgdbm-dev ncurses-dev automake libtool bison subversion pkg-config libffi-dev vim
# Download and compile Ruby 2.0.0-p0
cd /tmp
wget ftp://ftp.ruby-lang.org/pub/ruby/2.0/ruby-2.0.0-p0.tar.gz
tar -xvzf ruby-2.0.0-p0.tar.gz
AWS_ACCESS_KEY_ID="YOURAWSACCESSKEYID"
AWS_SECRET_KEY="YOURAWSSECRETKEY"
EC2_REGION=$(wget -q -O - http://169.254.169.254/latest/dynamic/instance-identity/document | grep region | awk -F\" '{print $4}')
EC2_INSTANCE_ID=$(wget -q -O - http://169.254.169.254/latest/meta-data/instance-id)
EC2_CLOUDWATCH_NAMESPACE='WebService'
NGINX_CONNECTIONS=$(wget -q -O - http://127.0.0.1/nginx_status | grep 'connections' | awk '{print $3}')
/usr/bin/mon-put-data --region \"$EC2_REGION\" --metric-name HttpConnections --namespace \"$EC2_CLOUDWATCH_NAMESPACE\" --dimensions \"InstanceId=$EC2_INSTANCE_ID\" --value \"$NGINX_CONNECTIONS\" -I \"$AWS_ACCESS_KEY_ID\" -S \"$AWS_SECRET_KEY\"