Skip to content

Instantly share code, notes, and snippets.

View vmencik's full-sized avatar

Vlastimil Menčík vmencik

View GitHub Profile
@vmencik
vmencik / PaginationNow.scala
Created February 23, 2013 10:07
Initialization of the Pagination instance before it is passed to a template.
object Pagination {
def apply[T](page: ListPage[T], pageSize: Int)(navi: Int => Call) =
new Pagination(page.totalCount, page.firstIndex, page.runover, pageSize)(navi)
}
package models
import play.api.mvc.Call
class Pagination(cnt: Int, pos: Int, val runover: Boolean, val pageSize: Int = 20,
val forwardCnt: Int = 4, val backwardCnt: Int = 4, val headCnt: Int = 3, val tailCnt: Int = 4,
val indexByPage: Boolean = false, val indexByPageIndex: Boolean = false, val independentVicinity: Boolean = false,
val consoleEnds: Boolean = false, val duplicateEnds: Boolean = false)(navi: Int => Call) {
outer =>
package models;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class PaginationData {
public static final String SPECIAL_RUNOVER = "runover";
@vmencik
vmencik / PaginationOrig.scala
Created February 23, 2013 09:18
Initialization of PaginationData before it is passed to a template
object Pagination {
def apply[T](page: ListPage[T], pageSize: Int)(navi: Int => Call): PaginationData = {
val pd = new PaginationData
pd.setPageSize(pageSize)
pd.setRunover(page.runover)
pd.configure(page.totalCount, page.firstIndex)
pd.setAddressAdapter(new PageAddressAdapter {
override def makePageAddress(offset: Int): Call = navi(offset)
})
@tailrec
def accumBits(remainingText: List[Char], accum: List[Int]): List[Int] =
if (remainingText.isEmpty) accum
else accumBits(remainingText.tail, accum ++ encodeChar(remainingText.head))
accumBits(text, List())
def factorial(n: Int): Int = {
@tailrec
def accumFactors(accumulator: Int, n: Int): Int =
if (n == 0) accumulator
else accumFactors(accumulator * n, n - 1)
accumFactors(1, n)
}
@tailrec
def gcd(a: Int, b: Int): Int =
if (b == 0) a else gcd(b, a % b)
def factorial(n: Int): Int =
if (n == 0) 1 else n * factorial(n - 1)
package cz.vmencik.sandbox.nullcheck;
interface AuthorizedUser {
User getUser();
}
interface User {
Group getGroup();
}