Skip to content

Instantly share code, notes, and snippets.

View stevez's full-sized avatar

Steve Zhang stevez

  • Scotiabank
  • Markham, Ontario, Canada
View GitHub Profile
var assert = require("chai").assert;
var TennisGame = require("../src/TennisGame");
describe('Tennis Score', function() {
var tests = [
[0, 0, "Love-All"],
[1, 1, "Fifteen-All"],
[2, 2, "Thirty-All"],
@stevez
stevez / launch.json
Created June 4, 2016 01:55
Debug mocha config file for visual studio code
{
"version": "0.2.0",
"configurations": [
{
"name": "Debug mocha",
"type": "node",
"request": "launch",
"program": "${workspaceRoot}/node_modules/mocha/bin/_mocha",
"stopOnEntry": true,
"args": [],
@stevez
stevez / gist:991c8685d68fc8af476a
Created May 7, 2015 02:30
mock for loop using mockito
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.util.Collection;
import java.util.Iterator;
import org.junit.Before;
import org.junit.Test;
[1,2,3,4].intersect([2,4])
//===> [2, 4]
[1,2,3].subsequences()
//===> [[1], [1, 2, 3], [2], [2, 3], [1, 2], [3], [1, 3]]
letters = ['a', 'b', 'c']
numbers = [1, 2, 3]
combos = [letters, numbers].combinations()
//[[a, 1], [b, 1], [c, 1], [a, 2], [b, 2], [c, 2], [a, 3], [b, 3], [c, 3]]
[1,2,3].permutations()
//[[1, 2, 3], [3, 2, 1], [2, 1, 3], [3, 1, 2], [1, 3, 2], [2, 3, 1]]
import static org.junit.Assert.*;
import org.junit.Before
import org.junit.Test;
class TestScriptScrub {
private ScriptScrub scrub
@stevez
stevez / gist:b44d5fd4d0345fe19823
Created April 30, 2015 03:06
strip javascript
class ScriptScrub {
def scrub(text) {
def regex = ~/(<script.*>)([\s\S]+)(<\/script>)/
def result = text.replaceAll(regex, "")
result
}
}
@stevez
stevez / gist:8bdab52680053829c7d5
Created April 30, 2015 02:32
scala swap array using yield
val s = Array(1,2,3,4,5)
for ( i<-0 until s.length) yield {
if ( i%2 == 1) s(i-1)
else if(i == s.length-1) s(i)
else s(i+1)
}
//scala.collection.immutable.IndexedSeq[Int] = Vector(2, 1, 4, 3, 5)