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 / 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 / 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 / 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
@amaya382
amaya382 / cs.cs
Created April 14, 2015 11:08
既に定義済みのものを後からInterfaceとして公開する, 型チェック付きのダックタイピングっぽい感覚…?
public class Named : Person, IImplName { }
public interface IImplName
{
string Name { get; set; }
}
public class Person
{
public string Name { get; set; }
}
@amaya382
amaya382 / agg.zsh
Last active February 4, 2016 17:07
calculate avg without outliers(arg1: command, arg2: output file, arg3: regex for output, -i=--iters(opt): #iters, -o=--outliers(opt): #outliers, -a+=--additional-regex(opt,experimental): regex for additional target)
#!/bin/zsh
# TODO: impl for two or more additional regexs
zparseopts -D -A opts -- i: -iters:=i o: -outliers:=o p: -parallel=p a+: -additional-regex:=a
niters=5
noutliers=1
regexs=("$3")
local -A opts
if [[ -n "${opts[(i)-i]}" ]]; then
niters=${opts[-i]}
implicit class RichMutableMap[K, V](val m: scala.collection.mutable.Map[K, V]) extends AnyVal {
def upsert(key: K, insertValue: => V, updateValue: => V => V = null): scala.collection.mutable.Map[K, V] = {
if (m.contains(key) && updateValue != null)
m.update(key, updateValue(m(key)))
else
m.update(key, insertValue)
m
}
}