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
function createStore(reducer) { | |
let state; | |
let listeners = []; | |
const getState = () => state; | |
const dispatch = (action) => { | |
state = reducer(state, action); | |
listeners.forEach(listener => listener()); | |
}; |
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 Joi from 'joi'; | |
const schema = Joi.object({ | |
a: Joi.string().required(), | |
b: Joi.string().required(), | |
}); | |
const {error: error1} = Joi.validate(null, schema); // "value" must be an object | |
const {error: error2} = Joi.validate(undefined, schema); // null |
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 express = require('express'); | |
const app = express(); | |
const asyncError = (timeout = 500) => new Promise((res, rej) => { | |
setTimeout(() => rej(new Error('async error')), timeout); | |
}); | |
app.get('/', async () => { | |
await asyncError(); |
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 moment = require('moment-timezone'); | |
const daysAfter1 = (date, days) => { | |
const result = new Date(date); | |
result.setDate(result.getDate() + days); | |
return result; | |
}; | |
const daysAfter2 = (date, days) => { |
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
type Animal interface { | |
Speak() string | |
} | |
type Dog struct { | |
} | |
func (d Dog) Speak() string { | |
return "Woof!" | |
} |
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
{ | |
"languages": { | |
"JavaScript": { | |
"functionName": "findArrayQuadruplet" | |
}, | |
"Python": { | |
"functionName": "find_array_quadruplet" | |
}, | |
"Ruby": { | |
"functionName": "find_array_quadruplet" |
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
function Node(cost) { | |
this.cost = cost; | |
this.children = []; | |
} | |
function getCheapestCost(rootNode) { | |
var n = rootNode.children.length; | |
// initialize minCost to the largest integer in the system | |
var minCost = Number.MAX_SAFE_INTEGER; |
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
def isMatchHelper(text, pattern, textIndex, patternIndex): | |
if textIndex >= len(text): | |
if patternIndex >= len(pattern): | |
return True | |
elif (patternIndex+1 < len(pattern)) and (pattern[patternIndex+1] == '*'): | |
return isMatchHelper(text, pattern, textIndex, patternIndex + 2) | |
else: | |
return False | |
elif (patternIndex >= len(pattern)) and (textIndex < len(text)): | |
return False |
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 org.junit.Test; | |
import org.junit.Assert; | |
import org.junit.runners.JUnit4; | |
import java.util.Arrays; | |
public class SolutionTest { | |
@Test | |
public void testSomething1() { | |
int[] actual = Solution.arrayOfArrayProducts(new int[0]); | |
System.out.print("<ACTUAL::1::>" + Arrays.toString(actual)); |
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 { snakeCase } from 'lodash'; | |
export interface IWebSocketMessage { | |
command: string; | |
data: string; | |
} | |
export class WebSocketClient { | |
private client: WebSocket; |
NewerOlder