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
p4 fix -c changlist jobid
@erichsu
erichsu / git-p4 patch
Created July 4, 2013 07:16
[PATCH] git-p4: support exclusively locked files
def getP4OpenedType(file):
# Returns the perforce file type for the given file.
result = p4_read_pipe(["opened", wildcard_encode(file)])
match = re.match(".*\((.+)\)(?:.+)?\r?$", result)
if match:
return match.group(1)
else:
die("Could not determine file type for %s (result: '%s')" % (file, result))
@erichsu
erichsu / Launch AVD
Created July 30, 2013 03:21
Android develop
android list avd | grep Name:* | cut -d':' -f2 |xargs emulator -scale 0.5 -avd &
@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
@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 / 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)"

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

######################
# Options
######################
NULL=
REVEAL_ARCHIVE_IN_FINDER=false
FRAMEWORK_NAME="StreamingFramework"
#"${PROJECT_NAME}"
- (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)];
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;