Skip to content

Instantly share code, notes, and snippets.

@alexanderjamesking
alexanderjamesking / future exceptions.scala
Created August 25, 2016 13:09
Scala FutureExceptions Test Trait - getExceptionFromFuture
import org.scalatest.Assertions
import org.scalatest.concurrent.ScalaFutures
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.Future
trait FutureExceptions {
self: Assertions with ScalaFutures =>
def getExceptionFromFuture(future: Future[Any]): Throwable = {
sbt "issues/test:testOnly stepdefs.RunIssuesCucumber"
/**
* repeats a check until the check is true or the timeout is reached
* returns a promise that we can return to mocha
*/
function promisePoller(condition,
interval = 10,
timeout = 1000,
onTimeout = new Error("Timed out")) {
return new Promise(function (resolve, reject) {
function check() {
"test:alex": "mocha --watch 'modules/issues/test/unit/javascript/**/IssueDetailTest.js' --compilers js:babel-core/register --require ignore-styles --require ./modules/issues/test/unit/util/jsdom-setup",
@alexanderjamesking
alexanderjamesking / docker.sh
Created September 1, 2016 11:56
Docker SQL
Docker MySQL
docker run -p 3306:3306 --name local-mysql -e MYSQL_ROOT_PASSWORD=password -d mysql:latest --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
mysql -h $(docker-machine ip) -uroot -ppassword
killall ssh-agent gpg-agent
unset GPG_AGENT_INFO SSH_AGENT_PID SSH_AUTH_SOCK
eval $(gpg-agent --daemon --enable-ssh-support)
@alexanderjamesking
alexanderjamesking / functional-ruby.rb
Created February 2, 2017 09:01
Functional Ruby - using map to create a new array from an existing array
# Looping through an array to form a new array
# non functional (imperative) way
my_array = [1,2,3,4,5]
new_array = [] # requires us to create a structure then modify it using push
my_array.each { | element |
new_array.push("number " + element.to_s)
}
@alexanderjamesking
alexanderjamesking / hash.rb
Created February 2, 2017 09:23
Ruby - Array of hashes to keyed hash
students = [
{ name: "Bob", cohort: "Nov"},
{ name: "Barry", cohort: "Nov"},
{ name: "Anna", cohort: "Dec"},
{ name: "Igor", cohort: "Dec"},
{ name: "Natalia", cohort: "Feb"}
]
my_hash = {}
@alexanderjamesking
alexanderjamesking / 00_destructuring.md
Created March 20, 2017 10:44 — forked from john2x/00_destructuring.md
Clojure Destructuring Tutorial and Cheat Sheet

Clojure Destructuring Tutorial and Cheat Sheet

(Related blog post)

Simply put, destructuring in Clojure is a way extract values from a datastructure and bind them to symbols, without having to explicitly traverse the datstructure. It allows for elegant and concise Clojure code.

Vectors

package com.ajk;
import clojure.lang.IFn;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import static clojure.java.api.Clojure.read;
import static clojure.lang.RT.loadResourceScript;
import static clojure.lang.RT.var;