Skip to content

Instantly share code, notes, and snippets.

@kmizu
kmizu / GetEnumerationClassInfo.scala.repl
Created January 11, 2012 16:00
Get runtime type information of a Enumeration's subclass from a Value's instance.
Welcome to Scala version 2.9.1.final (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_26).
Type in expressions to have them evaluated.
Type :help for more information.
scala> object W extends Enumeration { val A = Value }
defined module W
scala> val V: Enumeration#Value = W.A
V: Enumeration#Value = A
@doryokujin
doryokujin / 0.basics.sql
Created July 22, 2012 09:04
退会に関する分析
-- 0.1 ログインインターバルの分布 --
-- 当日入会->辞めた人もインターバルは1となるので1回以上プレイしている人に限定 --
td query -w -d your_app -f csv -o dist_of_login_interval.csv "
SELECT ROUND((datediff(latest_login, registered_day)+1)/login_times) AS login_interval, COUNT(*) AS cnt
FROM
(
SELECT v['uid'] AS uid, from_unixtime(MAX(time),'yyyy-MM-dd' ) AS latest_login
FROM login
GROUP BY v['uid']
) t1

Make it real

Ideas are cheap. Make a prototype, sketch a CLI session, draw a wireframe. Discuss around concrete examples, not hand-waving abstractions. Don't say you did something, provide a URL that proves it.

Ship it

Nothing is real until it's being used by a real user. This doesn't mean you make a prototype in the morning and blog about it in the evening. It means you find one person you believe your product will help and try to get them to use it.

Do it with style

@JoshRosen
JoshRosen / SnappyBenchmark.scala
Created April 9, 2015 02:10
Exploring whether changes to snappy-java have resulted in worse compression in newer versions
import java.io._
import org.xerial.snappy.SnappyOutputStream
object Main {
def main(args: Array[String]) {
val blockSize = sys.env.getOrElse("BLOCK_SIZE", "32768").toInt
val resetFrequency = sys.env.getOrElse("RESET_FREQUENCY", "100").toInt
val byteArrayOutputstream = new ByteArrayOutputStream()
@apangin
apangin / HotSpot JVM intrinsics
Last active July 20, 2024 10:43
HotSpot JVM intrinsics
_hashCode java/lang/Object.hashCode()I
_getClass java/lang/Object.getClass()Ljava/lang/Class;
_clone java/lang/Object.clone()Ljava/lang/Object;
_dabs java/lang/Math.abs(D)D
_dsin java/lang/Math.sin(D)D
_dcos java/lang/Math.cos(D)D
_dtan java/lang/Math.tan(D)D
_datan2 java/lang/Math.atan2(DD)D
_dsqrt java/lang/Math.sqrt(D)D
_dlog java/lang/Math.log(D)D
@JoshRosen
JoshRosen / scala-lambda-serialization-with-lifted-local-defs.md
Last active June 12, 2021 16:35
Serialization of Scala closures that contain local defs

Serialization of Scala closures that contain local defs

Several Apache Spark APIs rely on the ability to serialize Scala closures. Closures may reference non-Serializable objects, preventing them from being serialized. In some cases (SI-1419 and others), however, these references are unnecessary and can be nulled out, allowing otherwise-unserializable closures to be serialized (in Spark, this nulling is performed by the ClosureCleaner).

Scala 2.12's use of Java 8 lambdas for implementing closures appears to have broken our ability to serialize closures which contain local defs. If we cannot resolve this problem, Spark will be unable to support Scala 2.12 and will be stuck on 2.10 and 2.11 forever.

As an example which illustrates this problem, the following closure has a nested localDef and is defined inside of a non-serializable class:

``

How to GPG as a Scala OSS Maintainer

tl;dr Generate a GPG key pair (exercising appropriate paranoia). Send it to key servers. Create a Keybase account with the public part of that key. Use your keypair to sign git tags and SBT artifacts.

GPG is probably one of the least understood day-to-day pieces of software in the modern developer's toolshed. It's certainly the least understood of the important pieces of software (literally no one cares that you can't remember grep's regex variant), and this is a testament to the mightily terrible user interface it exposes to its otherwise extremely simple functionality. It's almost like cryptographers think that part of the security comes from the fact that bad guys can't figure it out any more than the good guys can.

Anyway, GPG is important for open source in particular because of one specific feature of public/private key cryptography: signing. Any published software should be signed by the developer (or company) who published it. Ideally, consu

@takezoe
takezoe / scala_kansai_summit_2017_slides.md
Last active November 11, 2018 06:35
Scala関西Summit 2017のスライド #scala_ks
@gakuzzzz
gakuzzzz / design_pattern_in_scala.md
Last active February 12, 2024 02:05
Design Patterns in Scala (ScalaMatsuri 2018 Unconfoerence)

Design Patterns in Scala

Scala でよく見るパターン

Type-Safe Builder

Javaで多引数のコンストラクタを避けるために使われる Builder パターンは、Scala では名前付き引数呼び出しが使えるので必要ありません。

Builderパターンに制約を加えて条件に合わない場合、コンパイルエラーにしたい。

@gvolpe
gvolpe / di-in-fp.md
Last active July 14, 2024 23:25
Dependency Injection in Functional Programming

Dependency Injection in Functional Programming

There exist several DI frameworks / libraries in the Scala ecosystem. But the more functional code you write the more you'll realize there's no need to use any of them.

A few of the most claimed benefits are the following:

  • Dependency Injection.
  • Life cycle management.
  • Dependency graph rewriting.