Skip to content

Instantly share code, notes, and snippets.

def sayHello(any: Any): Try[String] = {
Try {
any match {
case x: String => "Hello"
case _ => throw new Exception("Huh!")
}
}
} //> sayHello: (any: Any)scala.util.Try[String]
def letMeSayHello = {
@phucnh
phucnh / pyreactor.py
Last active August 29, 2015 14:07 — forked from ejconlon/pyreactor.py
#!/usr/bin/env python
"""
Translated from the example in
Deprecating the Observer Pattern (Maier, Rompf, Odersky)
http://lamp.epfl.ch/~imaier/pub/DeprecatingObserversTR2010.pdf
Their Scala example:
Reactor.once { self =>
// step 1:
#!/bin/bash
#
# =========================================================================
# Copyright 2014 Rado Buransky, Dominion Marine Media
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
package com.cyberz.foxapi.dao
import scala.slick.jdbc.JdbcBackend._
/**
* Created by Yuto Suzuki on 15/03/06.
*/
object BaseTransaction {
/**
@phucnh
phucnh / auth.go
Last active August 29, 2015 14:23 — forked from tristanwietsma/auth.go
package main
import (
"encoding/base64"
"net/http"
"strings"
)
type handler func(w http.ResponseWriter, r *http.Request)
/**
* The MIT License (MIT)
*
* Copyright (c) 2013-2015 Andrew Snare, Age Mooij
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
@phucnh
phucnh / hmacsha1.scala
Last active August 29, 2015 14:26 — forked from ohac/hmacsha1.scala
HMAC-SHA1 for Scala
import javax.crypto.spec.SecretKeySpec
import javax.crypto.Mac
object A {
def main(args: Array[String]): Unit = {
val secret = new SecretKeySpec("the_secret".getBytes, "HmacSHA1")
val mac = Mac.getInstance("HmacSHA1")
mac.init(secret)
val result: Array[Byte] = mac.doFinal("foo".getBytes)
println(result.map(_.toString).mkString(","))
@phucnh
phucnh / type-bounds.scala
Last active August 29, 2015 14:27 — forked from retronym/type-bounds.scala
Tour of Scala Type Bounds
class A
class A2 extends A
class B
trait M[X]
//
// Upper Type Bound
//
def upperTypeBound[AA <: A](x: AA): A = x
Regex for matching ALL Japanese common & uncommon Kanji (4e00 – 9fcf) ~ The Big Kahuna!
([一-龯])
Regex for matching Hirgana or Katakana
([ぁ-んァ-ン])
Regex for matching Non-Hirgana or Non-Katakana
([^ぁ-んァ-ン])
Regex for matching Hirgana or Katakana or basic punctuation (、。’)
-- phpMyAdmin SQL Dump
-- version 3.5.1
-- http://www.phpmyadmin.net
--
-- Client: localhost
-- Généré le: Jeu 13 Juin 2013 à 07:19
-- Version du serveur: 5.5.24-log
-- Version de PHP: 5.4.3
SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";