Skip to content

Instantly share code, notes, and snippets.

View erichsu's full-sized avatar

eric.hsu erichsu

  • Ubiquiti, Inc
  • Taipei, TW
View GitHub Profile
@erichsu
erichsu / recreate-docker-qcow2-file.sh
Last active July 6, 2021 17:45
Create limited size qcow2 image for Docker
#!/bin/sh
# brew install qemu
# stop Docker daemon
rm -rf ~/Library/Containers/com.docker.docker/Data/com.docker.driver.amd64-linux/Docker.qcow2
qemu-img create -f qcow2 -o lazy_refcounts ~/Library/Containers/com.docker.docker/Data/com.docker.driver.amd64-linux/Docker.qcow2 4G
# restart Docker daemon
# done...
# brew rmtree qemu
@erichsu
erichsu / slide.js
Last active January 23, 2016 18:34
slide.js
var w = $('#whiteboard iframe')[0].contentWindow;
$('#whiteboard iframe').load(function() {
// $(this).focus();
if (window.location.search.substring(1) == 'con=yes') {
w.Reveal.addEventListener('slidechanged', function(event) {
// event.previousSlide, event.currentSlide, event.indexh, event.indexv
socket.emit('slide', w.Reveal.getIndices());
});
w.Reveal.addEventListener('fragmentshown', function() {
@erichsu
erichsu / webrtc-android.sh
Last active November 28, 2022 06:52
WebRTC for Mobile
#!/bin/sh
cd /root
export PATH=/root/depot_tools:$PATH \
export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64 \
export GYP_DEFINES="OS=android"
apt-get update && apt-get install -y openjdk-7-jdk git curl software-properties-common && \
add-apt-repository multiverse
git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git && \
mkdir chromium && cd chromium
private String md5(String input) {
String md5 = null;
try {
MessageDigest digest = MessageDigest.getInstance("MD5");
digest.update(input.getBytes(), 0, input.length());
md5 = new BigInteger(1, digest.digest()).toString(16);
} catch (NoSuchAlgorithmException e) {
Timber.e(e.getLocalizedMessage(), e);
}
return md5;
- (UIImage *)drawImage:(UIImage *)profileImage withBadge:(UIImage *)badge withText:(NSString *)count {
UIGraphicsBeginImageContextWithOptions(profileImage.size, NO, 0.0f);
[profileImage drawInRect:CGRectMake(0, 0, profileImage.size.width, profileImage.size.height)];
[badge drawInRect:CGRectMake(profileImage.size.width - badge.size.width, 0, badge.size.width, badge.size.height)];
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, badge.size.width, badge.size.height)];
label.text = count;
label.textAlignment = NSTextAlignmentCenter;
label.font = [UIFont systemFontOfSize:11.f];
label.textColor = [UIColor whiteColor];
[label drawTextInRect:CGRectMake(profileImage.size.width - badge.size.width, 0, badge.size.width, badge.size.height)];
######################
# Options
######################
NULL=
REVEAL_ARCHIVE_IN_FINDER=false
FRAMEWORK_NAME="StreamingFramework"
#"${PROJECT_NAME}"

Virtual Hosts on nginx (CSC309)

When hosting our web applications, we often have one public IP address (i.e., an IP address visible to the outside world) using which we want to host multiple web apps. For example, one may wants to host three different web apps respectively for example1.com, example2.com, and example1.com/images on the same machine using a single IP address.

How can we do that? Well, the good news is Internet browsers

@erichsu
erichsu / fetch.sh
Last active August 29, 2015 14:03
CI build binary fetcher
#!/bin/bash -e
set -e
## fetch
function fetch() { #$1=srcPath, $2=dstPath
srcPath="$1"; dstPath="$2"
srcName=$(basename "$srcPath")
dstName=$(basename "$dstPath")
if cmp -s "$srcPath" "$dstPath"; then
echo "$dstName is already up-to-date ($srcName)"
@erichsu
erichsu / ipfw.script
Created October 30, 2013 04:52
Update pow server settings.
#ipfw show
# 00010 fwd 127.0.0.1,80 tcp from any to me dst-port 80 in
ipfw delete 00100
ipfw add 00100 fwd 127.0.0.1,20559 tcp from any to 127.0.0.1 dst-port 80 in
@erichsu
erichsu / git-p4-integ
Last active December 21, 2015 03:08
Work with p4 integ by git repo. Setup: git config git-p4.int-branch <your branch map> Usage: git p4 integ
#P4USER=
#P4PORT=
#P4CLIENT=
### Git functions
function git_branch {
ref=$(git symbolic-ref HEAD 2> /dev/null) || return;
echo "("${ref#refs/heads/}") ";
}
function git_p4_integ {
BRANCH=$1