Skip to content

Instantly share code, notes, and snippets.

View nuboat's full-sized avatar

Peerapat CC nuboat

View GitHub Profile
@nuboat
nuboat / Expecte.rb
Created April 26, 2014 15:17
MapReduce.rb
{1=>[1,1],
3=>[1,1,1,1],
5=>[1,1,1]
7=>[1,1],
2=>[1,1,1]}
@nuboat
nuboat / InstallCert.java
Last active August 29, 2015 14:02
InstallCert
package com.thjug.tools.sslcert;
import javax.net.ssl.*;
import java.io.*;
import java.security.KeyStore;
import java.security.MessageDigest;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
/**
@nuboat
nuboat / HIndex.scala
Last active August 29, 2015 14:17
Thailandoi Programming Contest #2, March
case class HIndex(publishs: List[Int]) {
val checklist = 0.to(publishs.max).sortWith(_ > _)
def calc(): Int = checklist.find(c => rule1(c) && rule2(c)).get
private def refer(c: Int): List[Int] = publishs.filter(_ >= c).toList
private def rule1(c: Int): Boolean = refer(c).size >= c
@nuboat
nuboat / TwoSum.scala
Last active August 29, 2015 14:21
ปัญหา 2-SUM
object TwoSum {
def sum(n: Int, sorted: ArrayBuffer[Int]): Boolean = sorted.par.find(x => isMatch(x, n, sorted)).isDefined
def isMatch(x: Int, n: Int, sorted: ArrayBuffer[Int]): Boolean = sorted.find( y => (x + y) == n).isDefined
}
@nuboat
nuboat / Currency.java
Created June 3, 2015 16:51
Thai Currency
/*
* (c) nuboat.net 2012
*/
package net.nuboat.currency;
/**
*
* @author nuboat
*/
import java.util.StringTokenizer;
@nuboat
nuboat / LocalCache.java
Created June 4, 2015 02:55
Cache with AOP
package intercept;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface LocalCache {
...
def groupJobLevel(): List[GroupJobLevel] = {
val cache = Cache.get("GROUPJOBLEVEL")
if (cache.isDefined) {
return cache.get.asInstanceOf[List[GroupJobLevel]]
}
val result = queryGroupJobLevel()
if (result != null) {
Cache.set("GROUPJOBLEVEL", result)
@nuboat
nuboat / ApiSpec.scala
Last active August 29, 2015 14:23
Spec of Section in Parsley
import org.scalatest.{FlatSpec, Matchers}
import play.api.test.Helpers._
import play.api.test._
class ApiSpec extends FlatSpec with Matchers {
"GET /api/get/:username" should
"return json result" in new WithApplication {
val home = route(FakeRequest(GET, "/api/get/nb")).get
spring.datasource.url=jdbc:postgresql://localhost/training
spring.datasource.username=postgres
spring.datasource.password=
spring.datasource.driverClassName=org.postgresql.Driver
@nuboat
nuboat / application.properties
Last active August 29, 2015 14:27
SpringJdbc
server.port = 9090
spring.thymeleaf.cache = false
spring.datasource.url=jdbc:oracle:thin://@10.202.100.151:1521/AAAA
spring.datasource.username=xxx
spring.datasource.password=xxx
spring.datasource.driverClassName=oracle.jdbc.OracleDriver