This file contains 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
import java.io.Writer; | |
import java.util.HashMap; | |
import java.util.Map; | |
import java.util.Map.Entry; | |
import org.apache.commons.lang3.StringUtils; | |
import com.thoughtworks.xstream.XStream; | |
import com.thoughtworks.xstream.converters.Converter; |
This file contains 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
let prime () = | |
let infinity = Seq.initInfinite (fun i -> i + 1) |> Seq.filter (fun n -> n >= 2) |> Seq.cache | |
let rec inner (nums: seq<int>) = seq { | |
let i = Seq.item 0 nums | |
yield i | |
let next = nums |> Seq.filter (fun n -> n % i <> 0) |> inner | |
yield! next | |
} |
This file contains 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
open System | |
open System.Text | |
open System.IO | |
open System.Diagnostics | |
let newProcess = new Process() | |
newProcess.StartInfo.FileName <- "cmd.exe" | |
newProcess.StartInfo.CreateNoWindow <- true | |
newProcess.StartInfo.UseShellExecute <- false | |
newProcess.StartInfo.RedirectStandardInput <- true |
This file contains 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
import java.io.IOException; | |
import java.io.PrintStream; | |
import java.lang.reflect.Method; | |
import java.util.LinkedList; | |
import java.util.List; | |
import org.apache.commons.lang3.ArrayUtils; | |
import org.springframework.core.io.Resource; | |
import org.springframework.core.io.support.PathMatchingResourcePatternResolver; | |
import org.springframework.core.io.support.ResourcePatternResolver; |
This file contains 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
open System.Text | |
open System.IO | |
open System.IO.Compression | |
let iso8859_1 = Encoding.GetEncoding("ISO-8859-1"); | |
let compress (s:string) = | |
let sBytes = Encoding.UTF8.GetBytes(s) | |
use original = new MemoryStream(sBytes) | |
let oBytes = using(new MemoryStream())(fun out -> |
This file contains 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
public class StringCompressUtil { | |
private static final String DEFAULT_ENCODING = "UTF-8"; | |
public static String compress(final String str) throws IOException { | |
if (StringUtils.isEmpty(str)) { | |
return str; | |
} | |
String result; | |
try (final ByteArrayOutputStream out = new ByteArrayOutputStream()) { |
This file contains 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
package com.cc.graph.algorithm | |
import com.cc.graph.base.Graph | |
import scala.collection.mutable.ListBuffer | |
import scala.collection.mutable.HashMap | |
object NMI { | |
/** | |
* NMI(A,B)=2*H(A)/(H(A)+H(B)) |
This file contains 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
// a simple script | |
// batch download from http://www.andrew.cmu.edu/course/15-749/READINGS/optional/ | |
//extract file name | |
def getAllFiles(url:String):List[String] = { | |
import scala.io._ | |
val regex = """<a href="(.+?\.pdf)">""".r | |
val content = Source.fromURL(url).mkString | |
regex.findAllMatchIn(content).map(_.group(1)).toList | |
} |
This file contains 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
defmodule Wordcount do | |
@moduledoc "a simple wordcount program by fairjm" | |
@nodecount 3 | |
def start(file) do | |
s = self | |
spawn(fn -> count(file,s) end) | |
end | |
defp count(file,caller) do |
This file contains 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
import scala.collection.mutable.ListBuffer | |
import scala.collection.mutable.HashMap | |
import scala.annotation.tailrec | |
/* | |
** author fairjm | |
** https://projecteuler.net/problem=5 | |
*/ | |
object P5 { | |
def getPrimesLEQ(num:Int):List[Int] = { |