Skip to content

Instantly share code, notes, and snippets.

Avatar

vasani83 cvasani

View GitHub Profile
@cvasani
cvasani / Main.scala
Created May 25, 2019 — forked from jkpl/Main.scala
Ways to pattern match generic types in Scala
View Main.scala
object Main extends App {
AvoidLosingGenericType.run()
AvoidMatchingOnGenericTypeParams.run()
TypeableExample.run()
TypeTagExample.run()
}
class Funky[A, B](val foo: A, val bar: B) {
override def toString: String = s"Funky($foo, $bar)"
}
View rxjs_operators_by_example.md
@cvasani
cvasani / notes_programming_in_scala.md
Created May 14, 2019 — forked from jamesyang124/notes_programming_in_scala.md
Notes for programming in Scala 2nd edition.
View notes_programming_in_scala.md

#Note for Programming in Scala


##Chp.0 SBT & Scala Interpreter

  1. Call scala interpreter by sbt.

    // enter scala interpreter
@cvasani
cvasani / curl reference
Created Mar 3, 2019 — forked from afair/curl reference
Curl command reference with options sorted by category for easier usage than that man page.
View curl reference
==========================================
CURL COMMAND
==========================================
Format curl [options] [URL...]
Quick Ref:
curl -X POST http://example.com/ <= Method option and URL (Options come before or after URL)
-H "Authorization: <data>" <= Add HTTP Header (like Authorization)
@cvasani
cvasani / nqueen.scala
Created Aug 12, 2018 — forked from ornicar/nqueen.scala
solution to the n-queens problem based on "Programming in Scala"
View nqueen.scala
// Solves the n-queens problem for an arbitrary board size
// Run for a board size of ten: scala nqueen.scala 10
object Nqueen {
type Queen = (Int, Int)
type Solutions = List[List[Queen]]
def main(args: Array[String]) {
val size: Int = args match {
case Array() => sys.error("Provide a board size")
case Array(n) => n.toInt
@cvasani
cvasani / .block
Created Jul 11, 2018 — forked from mbostock/.block
Epicyclic Gearing
View .block
license: gpl-3.0
View OGG_Swingbench_Extract.md
View scala-cheatsheet.md

This cheat sheet originated from the forum, credits to Laurent Poulain. We copied it and changed or added a few things.

Evaluation Rules

  • Call by value: evaluates the function arguments before calling the function
  • Call by name: evaluates the function first, and then evaluates the arguments if need be
    def example = 2      // evaluated when called
    val example = 2      // evaluated immediately
@cvasani
cvasani / gist:6c74966f68fdb0e23e2e5c22b89fdba6
Created Nov 6, 2016 — forked from DavidWalz/gist:8538435
python: clopper pearson binomial confidence belt
View gist:6c74966f68fdb0e23e2e5c22b89fdba6
import scipy.stats
def clopper_pearson(k,n,alpha=0.32):
"""
http://en.wikipedia.org/wiki/Binomial_proportion_confidence_interval
alpha confidence intervals for a binomial distribution of k expected successes on n trials
Clopper Pearson intervals are a conservative estimate.
"""
lo = scipy.stats.beta.ppf(alpha/2, k, n-k+1)
hi = scipy.stats.beta.ppf(1 - alpha/2, k+1, n-k)
return lo, hi
@cvasani
cvasani / README.md
Created Nov 3, 2016 — forked from mbostock/README.md
Underscore’s Equivalents in D3
View README.md

Collections

each(array)

Underscore example:

_.each([1, 2, 3], function(num) { alert(num); });
You can’t perform that action at this time.