Skip to content

Instantly share code, notes, and snippets.

View tuphamphuong's full-sized avatar
🎯
Focusing

Tu Pham (Tony) tuphamphuong

🎯
Focusing
View GitHub Profile
@tuphamphuong
tuphamphuong / InMemoryCache.java
Last active October 21, 2015 16:00
In Memory Cache in Java
import org.apache.commons.collections.MapIterator;
import org.apache.commons.collections.map.LRUMap;
import java.util.ArrayList;
/**
* Created by Tu Pham Phuong - phamptu@gmail.com on 6/30/15.
*/
public class InMemoryCache<K, T> {
@tuphamphuong
tuphamphuong / fabfile.py
Created July 22, 2015 08:08
A sample of complete fabric deploy file
from config import config
__author__ = 'Tu Pham Phuong'
__create_date__ = '4/24/15'
from fabric.api import *
deploy_dir = '/home/tupp/code/api'
def development():
@tuphamphuong
tuphamphuong / AkkaScheduler.java
Last active October 21, 2015 16:00
Simple Akka scheduler by new thread
Akka.system().scheduler().schedule(
Duration.create(0, TimeUnit.MILLISECONDS),
Duration.create(5, TimeUnit.MILLISECONDS), //Frequency 5 minutes
new Runnable() {
public void run() {
Logger.debug("Run from Akka scheduler");
}
},
Akka.system().dispatcher()
);
@tuphamphuong
tuphamphuong / CheckNull.java
Last active October 21, 2015 15:59
Another way to check null in Java
public boolean equals(Object o){
if (!(o instanceof MyObject))
return false;
...
}
@tuphamphuong
tuphamphuong / FactoryMethod.java
Created October 21, 2015 15:58
Simple factory method in Java
public static TemplateService createTemplateService() {
return new TemplateService();
}
@tuphamphuong
tuphamphuong / BasicJUnit.java
Created January 12, 2016 13:47
Basic JUnit
package controllers;
import org.junit.*;
import static org.junit.Assert.*;
/**
* Created by Tu Pham Phuong - phamptu@gmail.com on 1/11/16.
*/
public class BasicTest {
@BeforeClass
@tuphamphuong
tuphamphuong / TestGuavaCache.java
Created January 13, 2016 02:23
Unit test Guava cache
import com.google.common.cache.*;
import org.junit.Test;
import java.util.HashMap;
import java.util.Map;
import static org.fest.assertions.Assertions.assertThat;
/**
* Created by Tu Pham Phuong - phamptu@gmail.com on 7/2/15.
@tuphamphuong
tuphamphuong / EnclosedTest.java
Created January 13, 2016 07:29
JUnit Enclosed test
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.*;
import org.junit.experimental.runners.Enclosed;
import org.junit.runner.RunWith;
/**
* Created by Tu Pham Phuong - phamptu@gmail.com on 1/13/16.
*/
@RunWith(Enclosed.class)
@tuphamphuong
tuphamphuong / Fix supervisor sock no such file
Created July 12, 2016 07:38
Fix supervisor unix:///var/run/supervisor.sock no such file
sudo touch /var/run/supervisor.sock
sudo chmod 777 /var/run/supervisor.sock
sudo service supervisor restart
@tuphamphuong
tuphamphuong / mysql-country-list.sql
Created August 13, 2016 09:14
Mysql country list
CREATE TABLE `country` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`country_code` varchar(2) NOT NULL,
`country_name` varchar(100) NOT NULL,
PRIMARY KEY (`id`),
KEY `cc` (`country_code`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO `country` (`id`, `country_code`, `country_name`)
VALUES