Skip to content

Instantly share code, notes, and snippets.

View batakpout's full-sized avatar
🎯
Focusing

aamir batakpout

🎯
Focusing
View GitHub Profile
@lefou
lefou / scala.nanorc
Last active November 18, 2021 05:06
Color theme for console editor nano, supporting Scala language.
## Nano color theme for Scala.
## 2013, 2018, Tobias Roeser
##
syntax "scala" "\.(scala|sbt|sc)$"
color green "\<(new|this|transient)\>"
color green "\<(catch|do|else|finally|for|if|match|return|switch|throw|try|val|var|while)\>"
color green "\<(def|abstract|class|extends|final|import|package|private|protected|public|trait|volatile)\>"
color green "(\{|\}|\(|\)|\;|\]|\[|`|\\|\$|<|>|!|=|&|\|)|\+|\-|\*|\/"
color red "@(\\.|[^(])*"
color yellow "\<(true|false|null)\>"
@kseada
kseada / BinarySearch.scala
Last active November 1, 2016 16:26
Showing alternative ways for implementing binary search in Scala: iterative, recursive and functional pattern matching.
def binarySearchIterative(list: Array[Int], target: Int): Int = {
var left = 0
var right = list.length-1
while (left<=right) {
val mid = left + (right-left)/2
if (list(mid)==target)
return mid
else if (list(mid)>target)
right = mid-1
else
@kendellfab
kendellfab / goto-sublime
Created August 1, 2013 20:53
Add mouse click `goto definition` in sublime text 3.
Linux - create "Default (Linux).sublime-mousemap" in ~/.config/sublime-text-3/Packages/User
Mac - create "Default (OSX).sublime-mousemap" in ~/Library/Application Support/Sublime Text 3/Packages/User
Win - create "Default (Windows).sublime-mousemap" in %appdata%\Sublime Text 3\Packages\User
[
{
"button": "button1",
"count": 1,
"modifiers": ["ctrl"],
"press_command": "drag_select",
@linasm
linasm / unapply.scala
Last active March 15, 2021 06:17
Output of live coding session "Scala pattern matching: apply the unapply"
import java.time.{LocalDate, LocalDateTime, LocalTime}
/*case */class FullName(val first: String, val last: String)
object FullName {
def apply(first: String, last: String): FullName =
new FullName(first, last)
def unapply(full: FullName): Some[(String, String)] =
Some((full.first, full.last))
@linasm
linasm / forcomp.scala
Last active October 8, 2021 20:59
Comprehending the For-Comphension talk, Vilnius, Nov 2018
sealed abstract class Perhaps[+A] {
def foreach(f: A => Unit): Unit
def map[B](f: A => B): Perhaps[B]
def flatMap[B](f: A => Perhaps[B]): Perhaps[B]
def withFilter(f: A => Boolean): Perhaps[A]
}
case class YesItIs[A](value: A) extends Perhaps[A] {
override def foreach(f: A => Unit): Unit = f(value)
override def map[B](f: A => B): Perhaps[B] = YesItIs(f(value))