Skip to content

Instantly share code, notes, and snippets.

@daimatz
daimatz / test.scala
Created October 9, 2013 11:02
リフレクションで動的にインスタンスを生成する何か
import scala.reflect.runtime.{universe => ru}
import ru._
case class Hoge(id: Int, title: String)
class Fuga[T: TypeTag](orig: T) {
val mirror = ru.runtimeMirror(Thread.currentThread.getContextClassLoader)
val clazz = mirror.runtimeClass(typeOf[T])
val fields = clazz.getDeclaredFields
@daimatz
daimatz / Sudoku.scala
Created September 30, 2013 09:28
適当に書いた数独 (Scala)
object Sudoku {
val N = 9
val ROOM = Math.sqrt(N).asInstanceOf[Int]
type Coord = (Int, Int)
def nextCoord(coord: Coord): Coord = {
if (coord._2 == N - 1) {
return if (coord._1 == N-1) (0, 0) else (coord._1 + 1, 0)
} else {
@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;
import Control.Monad (when)
import System.IO (hFlush, stdout)
-- main = f
main = g
f :: IO ()
f = do
x <- getLine
when (x /= "q") $ do
#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);
}
@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)
@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 / 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 / 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 / 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.