Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View mather's full-sized avatar
🐻
friendly bear

Eisuke Kuwahata mather

🐻
friendly bear
View GitHub Profile
@mather
mather / ParserSample.scala
Created November 30, 2012 16:40
Parser Test
import scala.util.parsing.combinator.JavaTokenParsers
object ParserSample extends JavaTokenParsers {
/*
* RegexParserで定義されたメソッド。
* default(=true) だと行末の改行などが無視される。
*/
override def skipWhitespace = false
/*
@mather
mather / stat_test.c
Last active December 12, 2015 10:48
stat関数でできることをチェック。コマンドライン引数でファイルとかシンボリックリンクとか指定するとstatまたはlstatを呼び出してチェックできる。
CC = gcc
OPT = -O2 -Wall
BIN = stat_test
default: bin
bin: $(BIN)
stat_test: stat_test.o
$(CC) $(OPT) -o $@ $<
@mather
mather / tzset_test.c
Created February 12, 2013 10:36
tzsetで何が変わるのか
#include <stdio.h>
#include <time.h>
void print_time(const time_t t)
{
char buf[128];
size_t str_size = 0;
str_size = strftime(buf, 127, "%Y/%m/%d %H:%M:%S", localtime(&t));
buf[str_size] = 0;
@mather
mather / gist:4951569
Last active December 13, 2015 17:58
Futureを使ってみる。 Scala 2.10.0
import scala.concurrent._
/* futureを使うときにExecutionContextが必要。 */
implicit val execctx = ExecutionContext.global
/* futureはscala.concurrentパッケージに定義されているシンタックスシュガー */
val a = future { Thread sleep 100000 ; "hoge" }
/* 次のFutureの処理を合成 */
val b = a flatMap ( (str:String) => future { "fuga" + str } )
@mather
mather / amazon_shorten.user.js
Last active December 16, 2015 15:49
Amazonの商品URLを短くして商品名からリンクします。駄作なので改善案が欲しい。
// ==UserScript==
// @name Amazon Shorten URL Clipper
// @namespace https://gist.github.com/mather
// @version 0.4
// @updateURL https://gist.github.com/mather/5458140/raw/amazon_shorten.user.js
// @description Amazon商品のショートURLを作成して、商品名を含めたツイートボタンを作成します。
// @match http://www.amazon.co.jp/*
// @match http://www.amazon.com/*
// @copyright 2013+, mather
// ==/UserScript==
@mather
mather / gist:5771655
Last active December 18, 2015 10:49
SlickでTimestampのカラムをDateTimeとして扱うために、暗黙の変換(implicit conversion)を行う方法。 単なるメモなので、動作は保証出来ません。
/* util パッケージで宣言する場合 */
package object util {
import java.sql.Timestamp
import com.github.nscala_time.time.Imports.DateTime
import scala.slick.lifted.MappedTypeMapper
/* 結果値 Timestamp をアプリケーションでは DateTime に変換して使う */
implicit def dateTimeMapper = MappedTypeMapper.base[DateTime,Timestamp](
/* f: DateTime -> Timestamp */
dt => new Timestamp(dt.getMillis),
@mather
mather / fib_cycle.rb
Last active December 19, 2015 09:39
剰余環でフィボナッチ列を作ったらどんな周期が生まれるの?
# -*- encoding: utf-8 -*-
def fib_cycle(q,a,b)
fib = [a,b]
fib_array = [fib]
while true
fib = [fib[1], (fib[0] + fib[1]) % q]
if (index = fib_array.index(fib))
break
else

Untitled Slide

Welcome to Glide.

Glide is the easiest way to create useful slide for all of your Gists.

  • input key <- to go backward.
  • input key -> to go forward.

Publishing

@mather
mather / brew-subversion.patch
Created October 30, 2013 00:45
homebrew の subversion Formula に対する一時的な修正。
--- a/Library/Formula/subversion.rb
+++ b/Library/Formula/subversion.rb
@@ -2,8 +2,8 @@ require 'formula'
class Subversion < Formula
homepage 'http://subversion.apache.org/'
- url 'http://www.apache.org/dyn/closer.cgi?path=subversion/subversion-1.8.3.tar.bz2'
- mirror 'http://archive.apache.org/dist/subversion/subversion-1.8.3.tar.bz2'
+ #url 'http://www.apache.org/dyn/closer.cgi?path=subversion/subversion-1.8.3.tar.bz2'
+ url 'http://archive.apache.org/dist/subversion/subversion-1.8.3.tar.bz2'
@mather
mather / file0.py
Created November 26, 2013 02:20
fabricで鍵認証をセットする ref: http://qiita.com/mather314/items/d8db37ab6aaaaccdabba
from fabric.api import *
@task
def copy_id(file="~/.ssh/id_rsa.pub"):
"""Identityをauthorized_keysに追加する"""
put(file, "/tmp/id.pub")
try:
run("if [ ! -d ~/.ssh ]; then mkdir -p ~/.ssh; fi")
run("if [ ! -f ~/.ssh/authorized_keys ]; then cp /tmp/id.pub ~/.ssh/authorized_keys && chmod 0600 ~/.ssh/authorized_keys; fi")
run("cat ~/.ssh/authorized_keys /tmp/id.pub | sort -u > /tmp/uniq.authorized_keys")