Skip to content

Instantly share code, notes, and snippets.

object Main {
def main(args: Array[String]) = {
val data = testData()
val start1 = System.currentTimeMillis()
data.foreach(isValidIpFormat1)
val end1 = System.currentTimeMillis()
println("1: " + (end1 - start1))
val start2 = System.currentTimeMillis()
@daimatz
daimatz / Build.scala
Last active August 29, 2015 14:05
sbt assembly for Finatra application
import sbt._
import sbt.Keys._
import sbtassembly.Plugin.{MergeStrategy, assemblySettings, defaultMergeStrategy}
import sbtassembly.Plugin.AssemblyKeys.{assembly, mergeStrategy}
import sbtassembly.AssemblyUtils
object AppBuild extends Build {
lazy val app = Project(
id = "app",
base = file("app"),
@daimatz
daimatz / menuselect-isearch-case-insensitive.patch
Created February 27, 2012 20:23
zsh menuselect-isearch-case-insensitive
*** a/Src/Zle/complist.c 2012-02-28 05:00:40.000000000 +0900
--- b/Src/Zle/complist.c 2012-02-28 05:00:42.000000000 +0900
***************
*** 267,272 ****
--- 267,301 ----
static int lr_caplen, max_caplen;
+ /* This is case-insensitive strstr.
+ * If pattern exists in string, the function return 1.
@daimatz
daimatz / recentf-grep.el
Created October 25, 2012 20:54
grep string in recentf-list
(require 'anything-grep)
(defun recentf-grep (str)
(interactive "sSearch: ")
(let* ((files (mapconcat #'(lambda (x) (concat "'" x "'"))
(filter #'file-readable-p recentf-list) " "))
(command (concat "grep -i -nH -e " str " " files))
(pwd "/tmp")
(src (agrep-source (agrep-preprocess-command command) pwd)))
(setcdr (assoc 'name src) (format "grep %s in recentf-list" str))
(anything-grep-base (list src) (format " *recentf-grep:%s*" str))))
@daimatz
daimatz / shBrushHaskell.js
Last active October 12, 2015 04:18
SyntaxHighlighter 3.0 for Haskell
/**
* Haskell Brushe for SyntaxHighlighter 3.0
*/
SyntaxHighlighter.brushes.Haskell = function()
{
var constants = 'True False Nothing Just Left Right LT EQ GT';
var datatypes = 'Bool Maybe Either Ordering Char String Int Integer Float Double Rational ' +
'IO ReadS ShowS FilePath IOError Monad Functor Show Read' +
'Eq Ord Enum Bounded Num Real Integral Fractional Floating RealFrac RealFloat';
@daimatz
daimatz / Convert.hs
Created November 4, 2012 15:01
Data Convert Function using Template Haskell
{-# LANGUAGE TemplateHaskell #-}
import Language.Haskell.TH
import Control.Applicative ((<$>))
data Hoge = Hoge1 | Hoge2 | Hoge3 deriving (Eq, Show)
data Fuga = Fuga1 | Fuga2 deriving (Eq, Show)
-- runQ [| \t -> case t of "hoge1" -> Hoge1; "hoge2" -> Hoge2; "hoge3" -> Hoge3; _ -> error "Hoge" |]
@daimatz
daimatz / recursive.hs
Created December 4, 2012 17:29
Types and Programming Languages. Chapter 20. Recursive Types - 20.1. Examples
{-# LANGUAGE ScopedTypeVariables #-}
type Nat = Int
----------------------------------------
-- Lists
----------------------------------------
data NatList = Nil () | Cons (Nat, NatList)
deriving (Eq, Show)
#include <sys/param.h>
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv) {
if (argc != 2) {
printf("usage: %s <path>\n", argv[0]);
exit(1);
}
import Control.Monad (when)
import System.IO (hFlush, stdout)
-- main = f
main = g
f :: IO ()
f = do
x <- getLine
when (x /= "q") $ do
@daimatz
daimatz / sudoku.cpp
Last active December 23, 2015 15:19
適当に書いた数独
// compile: g++ -std=c++11 sudoku.cpp
#include <iostream>
#include <tuple>
#include <string>
#include <vector>
#include <array>
#include <cmath>
using namespace std;