Skip to content

Instantly share code, notes, and snippets.

@rednaxelafx
rednaxelafx / Bar$$$Lambda$101.class.javap
Last active June 11, 2020 07:35
Example comparison of inner-class anonfunc in Scala 2.11 vs indylambda in Scala 2.12, and how that affects Apache Spark's ClosureCleaner
# LMF class generated at runtime, dumped via
# <Scala 2.12.2>/bin/scala -cp . -Djdk.internal.lambda.dumpProxyClasses=dumpclasses Bar
$ javap -verbose -private -c -s -l 'Bar$$$Lambda$101.class'
Classfile /private/tmp/dumpclasses/Bar$$$Lambda$101.class
Last modified Apr 30, 2020; size 695 bytes
MD5 checksum 419f2634b1acdf7f40ba0bb7c22eabf4
final class Bar$$$Lambda$101 implements scala.runtime.java8.JFunction0$mcV$sp,scala.Serializable
minor version: 0
major version: 52
@jdegoes
jdegoes / fpmax.scala
Created July 13, 2018 03:18
FP to the Max — Code Examples
package fpmax
import scala.util.Try
import scala.io.StdIn.readLine
object App0 {
def main: Unit = {
println("What is your name?")
val name = readLine()
@andreas-schroeder
andreas-schroeder / Akka_streams_backpressure_gauge.md
Last active July 8, 2020 23:03
Measuring Akka Streams Backpressure

Akka Streams Backpressure Gauge

Measures if there is backpressure on an Akka Stream at the given stage.

Motivation

When an Akka Stream doesn't perform as intended, it is difficult to tell where the bottleneck is, since all stages operate at the same rate (see e.g. here ).

So when things are not fast as expected, this pressure gauge can help you to narrow down on the slow stage. Imagine

@sadikovi
sadikovi / udf.scala
Created July 28, 2017 00:03
Spark SQL UDF for StructType
import org.apache.spark.sql._
import org.apache.spark.sql.types._
import org.apache.spark.sql.expressions._
val df = Seq(
("str", 1, 0.2)
).toDF("a", "b", "c").
withColumn("struct", struct($"a", $"b", $"c"))
// UDF for struct
@klpx
klpx / splitEither.scala
Last active June 18, 2019 16:25
Akka Streams. Graph for Split Either[L,R] to L and R flows
/**
Copy left Alexander Hasselbach
Usage:
val E = b.add(splitEither[Throwable,Int])
val parsed = b.add(Flow[Either[Throwable,Int]])
val valids = b.add(Flow[Int])
val invalids = b.add(Flow[Throwable])
@FlatMapIO
FlatMapIO / faker.d.ts
Last active January 14, 2016 09:58
faker.js.d.ts
declare module '//cdnjs.cloudflare.com/ajax/libs/Faker/3.0.1/locales/zh_CN/faker.zh_CN.min.js' {
export = Faker;
}
declare namespace Faker {
namespace address {
function zipCode(format?:string);
@adamw
adamw / log.scala
Last active May 10, 2021 09:33
Logging request duration, path, status code using Akka HTTP
val rejectionHandler = RejectionHandler.default
def logDuration(inner: Route): Route = { ctx =>
val start = System.currentTimeMillis()
// handling rejections here so that we get proper status codes
val innerRejectionsHandled = handleRejections(rejectionHandler)(inner)
mapResponse { resp =>
val d = System.currentTimeMillis() - start
logger.info(s"[${resp.status.intValue()}] ${ctx.request.method.name} ${ctx.request.uri} took: ${d}ms")
resp
}(innerRejectionsHandled)(ctx)
package com.gtan.turing
import akka.shapeless.HNil
import org.parboiled2._
import scala.util.Try
/**
* Created by zhang on 2015/7/14.
*/

计算一组Range所覆盖的不重复整数的个数,求 < O(n*n) 的算法。

def cover(rs: Range*):Int = ???


assert(cover(0 to 4, 1 to 5) == 6)
assert(cover(0 to 4, 1 to 3) == 5)
assert(cover(0 to 4, 6 to 7) == 7)
assert(cover(0 to 4, 6 to 7, 2 to 6) == 8)
@craigminihan
craigminihan / gist:b23c06afd9073ec32e0c
Last active September 21, 2023 12:47
Build GCC 4.9.2 for C/C++ on CentOS 7
sudo yum install libmpc-devel mpfr-devel gmp-devel
cd ~/Downloads
curl ftp://ftp.mirrorservice.org/sites/sourceware.org/pub/gcc/releases/gcc-4.9.2/gcc-4.9.2.tar.bz2 -O
tar xvfj gcc-4.9.2.tar.bz2
cd gcc-4.9.2
./configure --disable-multilib --enable-languages=c,c++
make -j 4
make install