Skip to content

Instantly share code, notes, and snippets.

View wibisono's full-sized avatar

Adianto Wibisono wibisono

  • RIPE NCC
  • Amsterdam
View GitHub Profile
#!/usr/local/bin/amm
//Install ammonite.io and run amm checkroa.scala or if you +x you can run it as script.
import $ivy.`net.ripe.rpki:rpki-commons:1.8.0`
import net.ripe.rpki.commons.crypto.cms.roa.RoaCmsParser
import java.nio.file.{Files, Paths}
@main def main(args: String*){
if(args.length < 1){
#!/usr/local/bin/amm
//Install ammonite.io and run amm checkmft.scala or if you +x you can run it as script.
import $ivy.`net.ripe.rpki:rpki-commons:1.8.0`
import net.ripe.rpki.commons.crypto.cms.manifest.ManifestCmsParser
import java.nio.file.{Files, Paths}
@main def main(ar: String*){
val args = ar.toArray

Distance to nearest vowel

Write a function that takes a string as argument. Each character in the string will be a letter. The function should return a sequence containing the distances from each corresponding letter in the string to the nearest vowel in the string.

For example:

(nearest-vowels "aeiou") ;=> [0 0 0 0 0]  ;; if the letter is a vowel, the distance is 0
(nearest-vowels "babbb") ;=> [1 0 1 2 3]
(nearest-vowels "babbba") ;=> [1 0 1 2 1 0]

Distance to nearest vowel

Write a function that takes a string as argument. Each character in the string will be a letter. The function should return a sequence containing the distances from each corresponding letter in the string to the nearest vowel in the string.

For example:

(nearest-vowels "aeiou") ;=> [0 0 0 0 0]  ;; if the letter is a vowel, the distance is 0
(nearest-vowels "babbb") ;=> [1 0 1 2 3]
(nearest-vowels "babbba") ;=&gt; [1 0 1 2 1 0]
import scala.collection.mutable
import Board._
case class Board(table: Array[Int], r: Int, c: Int, parent: List[String] = List()) {
def cloneSwap(r: Int, c: Int, rr: Int, cc: Int) = {
val cTable = table.clone
cTable(r * 4 + c) = table(rr * 4 + cc)
cTable(rr * 4 + cc) = table(r * 4 + c)
cTable
}
def up() =
@wibisono
wibisono / scala-request.ipynb
Created July 20, 2018 18:54
Scala-request issue 1
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
cat <<EOF > temp.xml
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:ec.europa.eu:taxud:vies:services:checkVat:types">
<soapenv:Header/>
<soapenv:Body>
<urn:checkVat>
<urn:countryCode>COUNTRY_CODE</urn:countryCode>
<urn:vatNumber>VAT_NUMBER</urn:vatNumber>
</urn:checkVat>
</soapenv:Body>
</soapenv:Envelope>
import com.danielasfregola.twitter4s.TwitterStreamingClient
import com.danielasfregola.twitter4s.entities.{Tweet, User}
import org.joda.time.DateTime
import scala.collection.mutable
object HashtagAnalyser extends App {
def percent(cnt: Int, tot: Int) = cnt * 100.0 / tot
def computeStatistic(users: Set[User], tweetCount: Int) = {
// Inspiration : Existensial Types (Abstract type Member) Make OOP great again! Julien R. Foy
// https://www.youtube.com/watch?v=6j5kZj17aUw
// Compare this with the type class version : https://gist.github.com/wibisono/28d8808159e0c7103042d7c5c668edf7
sealed trait Animal
case class Dog(name : String) extends Animal
case class Cat(name : String) extends Animal
trait Speaking {
type A
def speak(creature : A) : String
@wibisono
wibisono / SpeakingCreature.scala
Last active March 23, 2018 09:32
Example speaking type class, rewrite from Simplified FP chapter Typeclass 101
// Base type
sealed trait Animal
case class Dog(name:String) extends Animal
case class Cat(name:String) extends Animal
// Type class
trait Speaking [A] {
def speak(creature : A) : String
}