Skip to content

Instantly share code, notes, and snippets.

View stphung's full-sized avatar

Steven Phung stphung

  • Autodesk, Inc.
  • San Francisco, CA
View GitHub Profile
#!/bin/bash
# General Information
ID=319"%"2C888"%"2C247
IGN=stp@PG/r
RANK=170
TIMEZONE=-8
MEMO=100"%"25+LMeta
STARTER_ID=2
REGION=2
@stphung
stphung / Main.java
Created July 15, 2014 05:56
String Concatenation vs. StringBuffer
public class Main {
private static final int ITERATIONS = 100000;
public static void main(String[] args) {
long stringConcatTime = time(Main::stringConcat);
System.out.println("String concat time: " + stringConcatTime + " ms");
long stringBufferAppendTime = time(Main::stringBufferAppend);
System.out.println("StringBuffer append time: " + stringBufferAppendTime + " ms");
}
@stphung
stphung / XmlSchemaValidator.scala
Created November 29, 2012 19:29 — forked from ramn/XmlSchemaValidator.scala
XML Schema validator in Scala
import javax.xml.transform.stream.StreamSource
import javax.xml.validation.Schema
import javax.xml.validation.SchemaFactory
import javax.xml.validation.{Validator=>JValidator}
import org.xml.sax.SAXException
object Validator {
def main(args: Array[String]) {
require(args.size >= 2, "Params: xmlFile, xsdFile")
val result =
@stphung
stphung / Raid.scala
Created November 7, 2012 22:03
Raid Scheduler
object Role extends Enumeration {
type Role = Value
val Tank = Value("Tank")
val Heal = Value("Heal")
val Damage = Value("Damage")
}
import Role._
case class Character(name: String, roles: List[Role], score: Double)
@stphung
stphung / 2LeggedOAuth.scala
Created February 25, 2012 13:52
A function that demonstrates how to do 2-legged OAuth requests with Play 2.0
def doRequest(key: String, secret: String) {
val ck = ConsumerKey(key, secret)
val oauth = OAuth(ServiceInfo(null, null, null, ck))
val calc = OAuthCalculator(ck, RequestToken("", ""))
calc.setSendEmptyTokens(true)
WS.url(endpoint).sign(calc).get.map(response => {
println(response.json)
})
}
@stphung
stphung / beta.erb
Created October 31, 2011 21:50
A knife bootstrap template which uses the beta-install.sh at http://opscode.com/beta-install.sh
bash -c '
<%= "export http_proxy=\"#{knife_config[:bootstrap_proxy]}\"" if knife_config[:bootstrap_proxy] -%>
if [ ! -f /usr/bin/chef-client ]; then
wget <%= "--proxy=on " if knife_config[:bootstrap_proxy] %>http://opscode.com/beta-install.sh
sh beta-install.sh
fi
mkdir -p /etc/chef
@stphung
stphung / gist:1255440
Created October 1, 2011 00:49
It's Over Nine Thousand Control Structure - Crap Usage
itsOverNineThousand(15000) { () =>
println("I think this is over nine thousand, yeah! So.. I guess I'll return true.")
true
}
@stphung
stphung / gist:1255432
Created October 1, 2011 00:44
It's Over Nine Thousand Control Structure - The Good Version
def itsOverNineThousand(n: Int)(body: => Boolean) = {
if (n > 9000) {
body
}
}
@stphung
stphung / gist:1255428
Created October 1, 2011 00:43
It's Over Nine Thousand Control Structure - Good Usage
itsOverNineThousand(15000) {
println("I think this is over nine thousand, yeah! So.. I guess I'll return true.")
true
}
@stphung
stphung / gist:1255426
Created October 1, 2011 00:42
It's Over Nine Thousand Control Structure - The Crap Version
def itsOverNineThousand(n: Int)(f: () => Boolean) = {
if (n > 9000) {
f()
}
}