Skip to content

Instantly share code, notes, and snippets.

@taylorleese
taylorleese / WPF - Bindable PasswordBox
Created July 8, 2010 17:23
WPF - Bindable PasswordBox
using System.Windows;
using System.Windows.Controls;
namespace CustomControl
{
public class BindablePasswordBox : Decorator
{
/// <summary>
/// The password dependency property.
/// </summary>
@taylorleese
taylorleese / Scala - Fibonacci
Created October 5, 2010 21:19
Scala - Fibonacci
def fib(n: Int): Long = n match {
case _ if n <= 1 => n
case _ => fib(n-1) + fib(n-2)
}
@taylorleese
taylorleese / student.py
Created January 12, 2011 17:43
Facebook Hacker Cup Qualification Round - Studious Student
import sys
# Facebook Hacker Cup Qualification Round - Studious Student
# http://www.facebook.com/hackercup/problems.php?round=4
def lex_compare(x, y):
if x.startswith(y) and x != y:
return lex_compare(x[len(y):], y)
if y.startswith(x) and y != x:
@taylorleese
taylorleese / dance.py
Created January 16, 2011 07:00
Facebook Hacker Cup Online Round 1a - After the Dance Battle
import sys
# Facebook Hacker Cup Online Round 1a - After the Dance Battle
# http://www.facebook.com/hackercup/problems.php?round=144428782277390
def dijkstra(graph, start, end):
dist = {}
previous = {}
for v in graph.keys():
@taylorleese
taylorleese / firstlast.py
Created January 20, 2011 04:32
Facebook Hacker Cup Online Round 1a - First or Last
import sys
from fractions import Fraction
# Facebook Hacker Cup Online Round 1a - First or Last
# http://www.facebook.com/hackercup/problems.php?round=144428782277390
def main():
with open(sys.argv[1]) as fp:
input = fp.read().split()
@taylorleese
taylorleese / Spiral.java
Created March 19, 2011 08:14
Print matrix in spiral order.
public class Spiral {
public static void main(String[] args) {
int row = Integer.parseInt(args[0]);
int col = Integer.parseInt(args[1]);
int[][] matrix = new int[row][col];
for (int i = 0; i < row; i++) {
for (int j = 0; j < col; j++) {
matrix[i][j] = i * col + j + 1;
@taylorleese
taylorleese / FizzBuzz.scala
Created March 19, 2011 23:51
Scala FizzBuzz.
object FizzBuzz {
def main(args: Array[String]) {
for (i <- 1 to 100) {
(i % 3, i % 5) match {
case (0, 0) => println("FizzBuzz")
case (0, _) => println("Fizz")
case (_, 0) => println("Buzz")
case _ => println(i)
}
}
@taylorleese
taylorleese / LoggingSugar.scala
Created November 17, 2011 07:54
Cleaner Logging
package sugar
import org.slf4j.{Logger, LoggerFactory}
trait LoggingSugar {
/**
* This is just a convenience method so you can type:
*
* getLogger[Foo]
@taylorleese
taylorleese / pom.xml
Created January 20, 2012 09:08
Example POM - StackMob Custom Code SDK
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.yourdomain</groupId>
<artifactId>yourdomain</artifactId>
<packaging>jar</packaging>
<name>YourName</name>
@taylorleese
taylorleese / gist:2870713
Created June 4, 2012 20:35
Airbrake Example IO
def notifySync(notice: AirbrakeNotice): Validation[Throwable, Int] = {
notify(prepareRequest(notice)).unsafePerformIO
}
def notify(xml: NodeSeq): IO[Validation[Throwable, Int]] = {
sendNotification(xml).map(_.success[Throwable]).except(_.fail[Int].pure[IO])
}
def sendNotification(xml: NodeSeq): IO[Int] = io {
. . .