Skip to content

Instantly share code, notes, and snippets.

@daimatz
daimatz / dictionary-app.el
Created September 20, 2011 01:43
Emacs Lisp Tips
;; Mac の Dictionary.app を、 Emacs の popwin.el から使う
;; dict.py is from http://sakito.jp/mac/dictionary.html
(defun dictionary ()
"dictionary.app"
(interactive)
(let ((word (if (and transient-mark-mode mark-active)
(buffer-substring-no-properties (region-beginning) (region-end))
(read-string "Dictionary: ")))
(cur-buffer (current-buffer))
(tmpbuf " * dict-process *"))
@daimatz
daimatz / mac.ahk
Last active February 28, 2022 00:20
Example of AutoHotkey. Mac like keybinds
;================================================================
;mac風キーバインド(Cmd+Q) など
; https://gist.github.com/daimatz/1385713
;================================================================
#InstallKeybdHook
#UseHook
;================================================================
;関数
@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;