Skip to content

Instantly share code, notes, and snippets.

@jonjack
jonjack / scala-for-comprehension-with-futures.md
Last active September 14, 2018 09:21
Scala for comprehension with Futures

Some ideas I gathered from various places for working with Futures in for comprehensions.

Import what we need for all the examples.

import scala.concurrent.{Await, Future}
import scala.concurrent.duration._
import scala.concurrent.ExecutionContext.Implicits.global

scala.collection.Searching provides binary search but you need an Indexed sequence (eg. Array), not a Linear sequence (eg. List). Search will still work on the List but you get linear O(n) behaviour rather than O(Log n).

case class Employee (id: Int, name: String, age: Int)

val emp1 = Employee(1, "Jane Doe", 45)
val emp2 = Employee(2, "Jon Doe", 54)
val emp3 = Employee(3, "Tera Patrick", 38)
val emp4 = Employee(4, "Jenna Jameson", 36)
val emp5 = Employee(5, "Aurora Snow", 34) // not added
@jonjack
jonjack / add-update-refresh-github-access-token-on-mac.md
Last active May 1, 2024 02:05
Adding & Updating GitHub Access Token on Mac

Using an Access Token for the first time

Follow the instructions on Github to Create an Access Token in Github

Configure Git to use the osxkeychain

By default, git credentials are not cached so you need to tell Git if you want to avoid having to provide them each time Github requires you to authenticate. On Mac, Git comes with an “osxkeychain” mode, which caches credentials in the secure keychain that’s attached to your system account.

You can tell Git you want to store credentials in the osxkeychain by running the following:-

Assumes High Sierra+

CMD + SHIFT + .      - shows all files/folders in Finder a window

Check whats available

brew search maven
==> Formulae
maven                maven-completion     maven-shell          maven@3.0            maven@3.1            maven@3.2            maven@3.3

Install MySQL

See what formula are available.

brew search mysql
==> Formulae
@jonjack
jonjack / install-java-om-mac-with-brew-&-jenv.md
Last active May 23, 2021 08:38
Install Java on Mac OSX via Home-brew

Notes on installing multiple versions Java on Mac OSX using Homebrew and Jenv.

Install Homebrew

Homebrew is a superb tool for Mac for managing the installation of software. It's core command is brew and it calls packages of software formula. If you are intrigued then you can check out the list of Formula in the brew Github repository.

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
@jonjack
jonjack / EcTest.scala
Created August 20, 2018 23:29
Demo of specifying an explicit Execution Context to a method to override a default implicit one.
object EcTest extends App {
import scala.concurrent.Future
import scala.concurrent.ExecutionContext
import java.util.concurrent.Executors
val default = scala.concurrent.ExecutionContext.Implicits.global
def test(comp: String)(implicit exc: ExecutionContext = default): Future[String] = Future {
@jonjack
jonjack / GitHub.Color.Scheme.for.IntelliJ.icls
Created September 25, 2017 08:19
GitHub Color Scheme for IntelliJ
<scheme name="GitHub.Color.Scheme.for.IntelliJ" version="142" parent_scheme="Default">
<option name="FONT_SCALE" value="1.0" />
<metaInfo>
<property name="created">2017-09-15T15:53:07</property>
<property name="ide">Idea</property>
<property name="ideVersion">2017.2.4.0.0</property>
<property name="modified">2017-09-25T09:19:23</property>
<property name="originalScheme">GitHub</property>
</metaInfo>
<option name="LINE_SPACING" value="1.1" />
@jonjack
jonjack / create-sbt-project.sh
Last active October 6, 2017 08:37
Create a skeleton SBT project for Scala. Tested on OSX only.
#!/bin/sh
VERSION="0.1-SNAPSHOT"
SCALA_VERSION="2.12.3"
echo "Do you wish to use the current directory for the project root? (y/n)?"
echo "Note: If (n) then the project will be created in a sub-directory of the current one."
read answer