Skip to content

Instantly share code, notes, and snippets.

View fwrq41251's full-sized avatar

winry fwrq41251

View GitHub Profile
@fwrq41251
fwrq41251 / ShiroRedisCache.java
Last active February 19, 2016 01:53
shiro cache impl in redis.
import java.util.Collection;
import java.util.List;
import java.util.Set;
import org.apache.shiro.cache.Cache;
import org.apache.shiro.cache.CacheException;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.SetOperations;
public class ShiroRedisCache<K, V> implements Cache<K, V> {
@fwrq41251
fwrq41251 / start.sh
Created February 29, 2016 05:54
start and stop java application from shell.
#!/bin/sh
SERVICE_NAME=MyService
PATH_TO_JAR=/usr/local/MyProject/MyJar.jar
PID_PATH_NAME=/tmp/MyService-pid
case $1 in
start)
echo "Starting $SERVICE_NAME ..."
if [ ! -f $PID_PATH_NAME ]; then
nohup java -jar $PATH_TO_JAR /tmp 2>> /dev/null >> /dev/null &
echo $! > $PID_PATH_NAME
import java.util.function.Consumer;
import java.util.function.Function;
public class Currying {
public static void main(String[] args) {
MyFileHelper.using(new MyFile("my-file")).accept(myFile -> myFile.print());
}
@fwrq41251
fwrq41251 / EmbeddedVelocityLayoutView.java
Created August 8, 2016 07:41
spring boot with velocity layout view.
package com.ifp.config;
import org.apache.velocity.Template;
import org.apache.velocity.context.Context;
import org.apache.velocity.exception.ResourceNotFoundException;
import org.springframework.boot.web.servlet.view.velocity.EmbeddedVelocityToolboxView;
import org.springframework.core.NestedIOException;
import javax.servlet.http.HttpServletResponse;
import java.io.StringWriter;
import scala.collection.mutable.ListBuffer
/**
* Created by User on 10/28/2016.
*/
object LongestAbsoluteFilePath {
class Node(val name: String, val depth: Int) {
val nodeType: NodeType.Value = getNodeType(name)
object Permutations {
def permutations[A](s: Set[A]): List[List[A]] = {
if (s.size == 1) List(s.toList)
else s.flatMap(x => permutations(s - x).map(p => List(x) ::: p)).toList
}
def main(args: Array[String]): Unit = {
println(permutations(Set(1, 2, 3)).mkString("\n"))
}
@fwrq41251
fwrq41251 / UniquePairs.scala
Created November 9, 2016 03:13
SICP exercise 2.40.
import scala.collection.mutable.ListBuffer
/**
* Created by User on 11/9/2016.
*/
object UniquePairs {
def uniquePairs(n: Int): List[List[Int]] = {
(1 to n).flatMap(i => (1 until i).map(j => List(i, j))).toList
}
@fwrq41251
fwrq41251 / Aggcow.scala
Last active December 13, 2016 10:00
SPOJ Aggressive cows
package com.winry
/**
* Created by User on 12/13/2016.
*/
object Aggcow {
def maxDistance(stalls: List[Int], cow: Int): Int = {
stalls.sorted
package com.aemobile.pool;
/**
* Created by winry on 2019/7/19.
*/
public class SimpleConnection implements Connection {
private String server;
public SimpleConnection(String server) {
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Predicate;
import java.util.regex.Matcher;
import java.util.regex.Pattern;