Skip to content

Instantly share code, notes, and snippets.

@amaya382
amaya382 / Fraction.cs
Last active August 29, 2015 14:01
第2回c#講習会演習の一部(サンプル)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication4
{
class Fraction
{
@amaya382
amaya382 / loan.scala
Last active August 29, 2015 14:11
loan pattern
class Loan[T <: {def close()}] private(resources: T) {
def map[U](func: T => U): Option[U] =
try {
Option(func(resources))
} catch {
case ex: Throwable =>
ex.printStackTrace()
None
} finally {
if (resources != null)
@amaya382
amaya382 / Benchmark.scala
Last active July 7, 2016 20:09
Scalaのベンチマーク用スニペット
def timeOf(action: => Unit, noTimes: Int = 10, multiplier: Int = 1): Double = {
import java.util.concurrent.TimeUnit
val runtime = Runtime.getRuntime
val result = (1 to noTimes + 1) map { _ =>
val startTime = System.nanoTime
var i = 0
while (i < multiplier) {
action
i += 1
}
@amaya382
amaya382 / compareImmutableWithMutable.scala
Last active August 29, 2015 14:11
immutable なコレクション(immutable.List)と mutable なコレクションの(mutable.ListBuffer) append 性能比較
def append2Immutable(noTimes: Long): Unit = {
@scala.annotation.tailrec
def go(l: List[Int], i: Long = 0): List[Int] = {
if (i > noTimes) l
else go(l :+ 0, i + 1)
}
go(List())
}
def append2Mutable(noTimes: Long): Unit = {
@amaya382
amaya382 / encode.sh
Last active August 29, 2015 14:12
chinachu encode
#!/bin/bash
log=/home/chinachu/chinachu/log/encode
echo -----start encoding @$(date +%Y/%m/%d/%H:%M:%S)----- >> $log
start=$(date +%s)
echo $1 >> $log
ffmpeg -i $1 -vcodec libx264 -acodec libfdk_aac -tune animation ${1%.*}.mp4 2>&1 | grep "^[^f]" >> $log
@amaya382
amaya382 / c87.md
Last active February 7, 2024 16:10
SublimeTextで作るお手軽Markdown文章作成環境

これはC87で頒布した部誌「OhUCC!」に寄稿した記事に若干の追記をしたものです.


SublimeTextで作るお手軽Markdown文章作成環境

0. Markdownって?

Markdownとはいわゆるマークアップ言語です. Markdownの簡単な規則に則るだけで整ったHTMLが作成できます. また, 現在ではHTMLだけではなく, LaTeXやPDFなどにも変換するアプリが提供されているため大変汎用的です. ちなみにこの文章もすべてMarkdownで書いています.

1. 最終目標

@amaya382
amaya382 / rewrite_gitinfo.sh
Last active August 29, 2015 14:13
過去のcommitのユーザ名とメールアドレスを一括書き換え
git filter-branch -f --commit-filter '
if [ "$GIT_AUTHOR_EMAIL" = "{old email}" ];
then
GIT_AUTHOR_NAME="{new name}"
GIT_AUTHOR_EMAIL="{new email}"
GIT_COMMITTER_NAME="{new name}"
GIT_COMMITTER_EMAIL="{new email}"
git commit-tree "$@"
else
git commit-tree "$@"
@amaya382
amaya382 / Option.cs
Last active January 7, 2019 05:47
実用重視のOptionMonad"""モドキ""" in C#
//直和を表現しきれない点を気にしたら負け
public interface IOption<out T> : IEnumerable<T>
{
bool HasValue { get; }//== this.Any()
}
sealed public class Some<T> : IOption<T>
{
private readonly T val;
public bool HasValue { get { return true; } }
@amaya382
amaya382 / keyboard.md
Last active August 29, 2015 14:16
MINILA Air US赤軸ベースに青軸とクリア軸を混ぜてついでにキー配置も弄ってみた

MINILA Air US赤軸ベース青クリア混合にしてみた記録

こんな感じでキー軸を加工して,

こんな感じに配線しなおして,

package com.chatwork.quiz.collection
import com.chatwork.quiz.{MySome, MyNone, MyOption}
import scala.annotation.tailrec
sealed trait MyList[+A] {
// Easy