This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Either type in Groovy as a special implementation of the generic sum type | |
// see: Phil Wadler at LambdaWorld 2016: youtu.be/V10hzjgoklA | |
import java.util.function.* | |
import groovy.transform.* | |
interface Either<A,B> { | |
public <C> C match (Function <A,C> leftCase, Function <B,C> rightCase) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100+ different js counter apps... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Please save all your work in https://jsfiddle.net/ | |
// Return the link to your work | |
// Answer five out of the seven questions | |
// Use test data when provided, however your functions should work with any similiarly structured data | |
// Use any additional libraries you like | |
// 1: Refactor this function to make it scalable. | |
var goto = function(evt, where, project, scenario, item, id){ | |
if (evt && evt.stopPropagation){ evt.stopPropagation(); } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var promises = []; | |
var cnt = 0; | |
function makePromises() { | |
console.log('make', Date.now()) | |
promises.length = 0; // clear array | |
promises.push(new Promise((resolve, reject) => setTimeout(resolve, 1000, `Everything OK in Promise ${cnt++}`))); | |
promises.push(new Promise((resolve, reject) => setTimeout(resolve, 2000, `Everything OK in Promise ${cnt++}`))); | |
promises.push(new Promise((resolve, reject) => reject(new Error(`Something went wrong in Promise ${cnt++}`)))); | |
return promises; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require('http').globalAgent.maxSockets = 10 | |
setInterval(main, (5 * 60 * 1000) - 6) // rinse-and-repeat every 5 minutes | |
main() // kick start! | |
function main () { | |
const req = require('request-promise') | |
const co = require('co') | |
const oO = require('eyes').inspector({maxLength: 99999}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
:root { | |
--ease-in-quad: cubic-bezier(.55, .085, .68, .53); | |
--ease-in-cubic: cubic-bezier(.550, .055, .675, .19); | |
--ease-in-quart: cubic-bezier(.895, .03, .685, .22); | |
--ease-in-quint: cubic-bezier(.755, .05, .855, .06); | |
--ease-in-expo: cubic-bezier(.95, .05, .795, .035); | |
--ease-in-circ: cubic-bezier(.6, .04, .98, .335); | |
--ease-out-quad: cubic-bezier(.25, .46, .45, .94); | |
--ease-out-cubic: cubic-bezier(.215, .61, .355, 1); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const nsTime = (hrtime) => hrtime[0] * 1e9 + hrtime[1]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Change a method reference into a closure that takes the delegate as the first parameter | |
import org.codehaus.groovy.runtime.MethodClosure | |
def uncurry(MethodClosure c) { | |
{a, ...b -> a."$c.method"(*b) } | |
} | |
// So uncurrying Number.plus gives us a closure that will take {x, y -> x.plus(y)} | |
def plus = uncurry(Number.&plus) | |
assert plus(1, 2) == 3 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import groovy.json.* | |
import groovy.transform.Immutable | |
enum Fruit { | |
Orange, | |
Apple | |
} | |
enum Car { | |
Ford('slow'), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Closure bind | |
List.metaClass.rightShiftUnsigned = { return bind(delegate, it) } | |
List.metaClass.call = { return [delegate, ''] } | |
Closure squrt = { Double x -> | |
if (x < 0.0d) return [] | |
if (x == 0.0d) return [0.0] | |
return [Math.pow(x, 0.5), -Math.pow(x, 0.5)] | |
} |