This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| gcd a b = | |
| let r = a `mod` b | |
| in if r == 0 then b else gcd b r | |
| lcm a b = a * b / (gcd a b) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Handler mHandler; | |
| public void useHandler() { | |
| mHandler = new Handler(); | |
| mHandler.postDelayed(mRunnable, 1000); | |
| } | |
| private Runnable mRunnable = new Runnable() { | |
| @Override | |
| public void run() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| DisplayMetrics displayMetrics = new DisplayMetrics(); | |
| ((WindowManager) getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getMetrics(displayMetrics); | |
| int statusBarHeight; | |
| switch (displayMetrics.densityDpi) { | |
| case DisplayMetrics.DENSITY_HIGH: | |
| statusBarHeight = HIGH_DPI_STATUS_BAR_HEIGHT; | |
| break; | |
| case DisplayMetrics.DENSITY_MEDIUM: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // script to patch the classpath in a Welogic Server config.xml file | |
| import scala.xml._ | |
| import java.io._ | |
| def patchClassPath(configFile: String, edit: (String) => String) { | |
| // inner function to apply the passed in edit function to the classpath | |
| def patch(node: Node): Node = { | |
| def patchElem(elem: Elem): Elem = | |
| elem.copy(child = elem.child.map(patch(_))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // rock paper scissors in scala | |
| import scala.util.Random | |
| def rockPaperScissors(): String = { | |
| Random.nextDouble match { | |
| case d if d < 1.0 / 3 => "rock" | |
| case d if d < 2.0 / 3 => "paper" | |
| case _ => "scissors" | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import scala.io.Source.fromFile | |
| def parseProperties(filename: String): Map[String,String] = { | |
| val lines = fromFile(filename).getLines.toSeq | |
| val cleanLines = lines.map(_.trim).filter(!_.startsWith("#")).filter(_.contains("=")) | |
| cleanLines.map(line => { val Array(a,b) = line.split("=",2); (a.trim, b.trim)}).toMap | |
| } |