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
class TalentsController < ApplicationController | |
PUBLICS = %w(screen presenter musical t_stage others) | |
layout :different_layout | |
# memory leak | |
def different_layout | |
if PUBLICS.tap { |a| a.concat(a.map { |s| s+'_preview' }) }.include?(action_name) | |
'talents' | |
else | |
'admin' |
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
class IndifferentMap[K >: String with Symbol ,V](original:Map[K,V]) extends collection.MapProxy[String, V] { | |
val beafed = original.map{ | |
case (k:Symbol,v) => k.name->v | |
case (k:String, v) => k->v | |
} | |
override def self = beafed | |
def apply(s:Symbol):V = apply(s.name) | |
} | |
val m = new IndifferentMap(Map("abc"->1)) |
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
function template($file, $templateid = 0, $tpldir = '', $gettplfile = 0, $primaltpl='') { | |
global $_G; | |
static $_init_style = false; | |
if($_init_style === false) { | |
C::app()->_init_style(); | |
$_init_style = true; | |
} | |
$oldfile = $file; | |
if(strpos($file, ':') !== false) { |
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
val target = util.Random.nextInt(100) | |
val scanner = new java.util.Scanner(System.in) | |
var times = 0 | |
def askAndCompare { | |
print("Guess a number: ") | |
val input = scanner.nextInt | |
times += 1 | |
if(input < target){ |
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
askAndCompare :: Int -> Int -> IO () | |
askAndCompare target level = do | |
putStr "Input your guess:" | |
hFlush stdout | |
input <- getLine | |
case compare (read input) target of | |
LT -> do putStrLn "Too small! Try again." | |
askAndCompare target (level + 1) | |
GT -> do putStrLn "Too Big! Try again." | |
askAndCompare target (level + 1) |
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
def maxseq(data: List[Int]): List[Int] = { | |
@annotation.tailrec | |
def maxAccum(remain: List[Int], found: List[Int], next: List[Int]): List[Int] = remain match { | |
case Nil => if(found.size == 1) Nil else found | |
case head :: tail => if(head > next.head) { | |
if(next.length == found.length) maxAccum(tail, head :: next, head :: next) | |
else maxAccum(tail, found, head :: next) | |
} | |
else maxAccum(tail, next, head :: Nil) | |
} |
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
(defn get-max-sub [h & t] | |
(let [max-sub (fn [[head & tail] found next] | |
(if head | |
(if (> head (last next)) | |
(let [next2 (conj next head)] | |
(if (= (count next) (count found)) | |
(recur tail next2 next2) | |
(recur tail found next2) | |
) | |
) |
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
object RichF { | |
implicit class RichF1[A, Z](val f: A => Z) extends AnyVal { | |
def map[Y](g: Z => Y): A => Y = | |
(a: A) => g(f(a)) | |
def flatMap[Y](g: Z => A => Y): A => Y = | |
(a: A) => g(f(a))(a) | |
} | |
implicit class RichF2[A, B, Z](val f: (A, B) => Z) extends AnyVal { | |
def map[Y](g: Z => Y): (A, B) => Y = |
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
sealed trait CompletionMagnet[T] { | |
type Result | |
def complete(v: T): Result | |
} | |
implicit def statudObjectHasACompletionMagnet[T : Marshaller](tupl: (StatusCode, T)) = new CompletionMagnet[(StatusCode, T)]{ | |
override type Result = Unit | |
override def complete(v: (StatusCode, T)) = ??? | |
} | |
implicit def httpResponseFutureHasACompletionMagnet(future: Future[HttpResponse]) = new CompletionMagnet[Future[HttpResponse]]{ |
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
private val _jqueryCssSelectRegex = """(^\S)+""".r | |
private val _matchChar = Set('*', '[', '^', '-') | |
def sel(exp: String, content: NodeSeq): CssSel = { | |
val selects = _jqueryCssSelectRegex.findAllMatchIn(exp).map(_.matched).toList | |
val (init, last) = | |
if (_matchChar.contains(selects.last.head)) | |
selects.dropRight(2) -> selects.takeRight(2).mkString(" ") | |
else |