Skip to content

Instantly share code, notes, and snippets.

View todokr's full-sized avatar
😻
Focusing

Shunsuke Tadokoro todokr

😻
Focusing
View GitHub Profile
(set-language-environment "UTF-8")
;; --------------------------------------------------------------------------------------
;; package management
;; --------------------------------------------------------------------------------------
(require 'package)
;; (add-to-list 'package-archives '("melpa" . "http://melpa.org/packages/") t)
(add-to-list 'package-archives '("melpa-stable" . "http://stable.melpa.org/packages/") t)
(add-to-list 'package-archives '("marmalade" . "http://marmalade-repo.org/packages/"))
import java.io.BufferedReader;
import java.io.IOException;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Objects;
import java.util.Optional;
import emums.Method;
import exception.BadRequestException;
trait Food
trait Vegetable extends Food // 野菜
trait Onion extends Vegetable // 玉ねぎ
class TrashBin[-A]{ // 反変
def popTrash[B <: A]: B = ??? // 戻り値には上限境界
}
class UserHatesOnion {
def disposeOnionTo(b: TrashBin[Onion]) = ??? // 玉ねぎ専用のゴミ箱に玉ねぎを捨てるメソッド
@todokr
todokr / Cp51932.java
Created April 8, 2017 11:20
CP51932でエンコーディングされたテキストは`x-eucJP-Open`で扱う
public class Main {
public static void main(String[] args) throws IOException {
String cp51932hexString =
// NEC特殊文字
"ADA1" + // ①
"ADB5" + // Ⅰ
"ADC0" + // ㍉
"ADE2" + // №
"ADEA" + // ㈱
(.toUpperCase "hoge") ; "hoge.toUpperCase();
(.indexOf "hoge" "ge") ; "hoge".indexOf("ge");
(new String "Hello") ; new String("Hello");
(String. "Hello") ; new String("Hello");
(InetAddress/getByName "localhost") ; InetAddress.getByName("localhost")
(.getHostName host) ; host.getHostName();
; StringBuffer sb = new StringBuffer("Hello ");
; sb.append("world");
; sb.append("!!!!!");
"👨‍👩‍👧‍👧".replace("👩","👨");
@todokr
todokr / scalaz-validation.scala
Created November 30, 2016 01:03 — forked from manjuraj/scalaz-validation.scala
scalaz validation
//
// Validation[E, A] represents either:
// - Success[A]
// - Failure[E]
//
// Isomporphic to scala.Either[E, A] and scalaz.\/[E, A]
//
// Unlike \/[E, A], Validation is not a Monad, but an Applicative
// Functor. So if you want to use it as a Monad you can convert back
// and forth using the `validation` and `disjunction` method
@todokr
todokr / scalaz-disjunction.scala
Created November 30, 2016 01:01 — forked from manjuraj/scalaz-disjunction.scala
scalaz disjunction
//
// Disjunction - aka Scalaz Either
// \/[A, B] is an alternative to Either[A, B]
// -\/ is Left (usually represents failure by convention)
// \/- is Right (usually represents success by convention)
// Left or Right - which side of the Disjunction does the "-" appear?
//
// Prefer infix notation to express Disjunction Type v: String \/ Double
//
// References
import java.io.File
import com.github.tototoshi.csv.CSVWriter
object Mojibake extends App {
val f = new File("./mojibake-patterns.csv")
val writer = CSVWriter.open(f)
val targetString = "入れ替わってる〜!?"
val encodings = List("UTF-8", "EUC_JP", "Shift-JIS", "ISO-2022-JP")