Skip to content

Instantly share code, notes, and snippets.

import com.github.akihiro4chawon.arm._
import scalaz._
import Scalaz._
object Main extends App {
import java.io._
// なんの変哲もない部分
def copyStream(is: InputStream, os: OutputStream, buffSize: Int) {
val buff = new Array[Byte](buffSize)
@akihiro4chawon
akihiro4chawon / _KenArrowLoopFib.scala
Created January 6, 2012 12:46
Ken が凄すぎる。。。
import com.github.okomok.ken
object ArrowLoopFib extends ken.Main {
import ken._
import List.{tail, zipWith}
import Tuple2.snd
val fibSeqFrom = locally {
// use Function Arrow in this environment
import Function.{app, loop, &&&:, ***:, <<<:, >>>:}
@gkossakowski
gkossakowski / fix-sbt-compiler-interface.sh
Created January 19, 2012 23:32
Fix sbt's compiler interface for 2.10.0-M1
#!/usr/bin/env bash
# This is very hacky remedy to following error people using sbt
# and 2.10.0-M1 release of Scala are going to see:
#
# API.scala:261: error: type mismatch;
# found : API.this.global.tpnme.NameType
# (which expands to) API.this.global.TypeName
# required: String
# sym.isLocalClass || sym.isAnonymousClass || sym.fullName.endsWith(LocalChild)
#
@jorgeortiz85
jorgeortiz85 / JavaConversionsEvil.scala
Created January 22, 2012 12:44 — forked from seanparsons/gist:1656555
scala.collection.JavaConversions is evil
import scala.collection.JavaConversions._
case class Foo(s: String)
val map: Map[Foo, String] =
Map(
Foo("a") -> "a",
Foo("b") -> "b")
val v = map.get("a") // should be a type error, actually returns null
sealed trait SList {
type Self <: SList
type Function[A]
def apply[A](f: Function[A]): A
def ::[A](a: A) = SCons(a, this.asInstanceOf[Self])
}
case object SNil extends SList {
type Self = SNil.type
type Function[A] = A
@milessabin
milessabin / gist:1819087
Created February 13, 2012 18:59
Access to companion object via implicit resolution
// See this mailing list thread for context:
// https://groups.google.com/d/topic/scala-language/ImqJuGylyi8/discussion
case class Companion[-C, T](t : T)
trait Publish[C, T] { self : T =>
implicit val companion = Companion[C, T](this)
}
trait StaticKey {
@tily
tily / aozora_sort.rb
Created March 9, 2012 16:44
青空文庫の長めの小説をソート
# coding:utf-8
# Usage: ruby aozora_sort.rb URL [--morph] > kokoro_sorted.txt
%w(kconv MeCab open-uri rubygems nokogiri).each{|x| require x}
def main(argv)
morph = argv[1] == '--morph'
text = Nokogiri::HTML.parse(open(argv[0]).read).xpath('/html/body').text
text.gsub!(/[\r\n\s ]/u, '')
arr = morph ? split_with_morph(text) : split_with_char(text)
arr.sort.each_with_index do |s, i|
@repeatedly
repeatedly / downloader.d
Last active October 1, 2015 23:18
D言語でいかにしておっぱい画像をダウンロードするか〜2013
// Written in the D programming language.
/**
* High peformance downloader
*
* Implemented according to <a href="http://yusukebe.com/archives/20120229/072808.html">this implementation</a>.
*
* Example:
* -----
* dmd -L-lcurl -run downloader.d
@cb372
cb372 / hide-promoted-tweets.user.js
Created March 24, 2012 08:06
A simple userscript to hide promoted tweets on twitter.com
// ==UserScript==
// @match http://twitter.com/*
// @match https://twitter.com/*
// ==/UserScript==
elems = document.getElementsByClassName('tweet')
for (var i=0; i<elems.length; i++) {
e = elems[i];
if (e.nodeName.toLowerCase() == 'div' &&
e.attributes['data-promoted'] &&
e.attributes['data-promoted'].value == "true") {
@purefn
purefn / gist:2284779
Created April 2, 2012 16:27
Encoding Product and Coproduct in Scala
type Product[F[_], G[_], A] = (F[A], G[A])
trait Prod[F[_], G[_]] {
type and[H[_]] = Prod[F, ({type λ[α] = Prod[G, H, α]})#λ]
type apply[A] = (F[A], G[A])
}
type product[F[_], G[_]] = Prod[F, G]
type Coproduct[F[_], G[_], A] = Either[F[A], G[A]]