Skip to content

Instantly share code, notes, and snippets.

View i-van's full-sized avatar
🇺🇦

Ivan Nosov i-van

🇺🇦
View GitHub Profile
function createStore(reducer) {
let state;
let listeners = [];
const getState = () => state;
const dispatch = (action) => {
state = reducer(state, action);
listeners.forEach(listener => listener());
};
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
@i-van
i-van / express.js
Last active December 14, 2017 09:43
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();
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) => {
type Animal interface {
Speak() string
}
type Dog struct {
}
func (d Dog) Speak() string {
return "Woof!"
}
{
"languages": {
"JavaScript": {
"functionName": "findArrayQuadruplet"
},
"Python": {
"functionName": "find_array_quadruplet"
},
"Ruby": {
"functionName": "find_array_quadruplet"
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;
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
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));
import { snakeCase } from 'lodash';
export interface IWebSocketMessage {
command: string;
data: string;
}
export class WebSocketClient {
private client: WebSocket;