This file contains 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
// Example usage: | |
// | |
// int[] numbers = {1, 2, 3, 4, 5, 6, 7}; | |
// int[][] chunks = chunkArray(numbers, 3); | |
// | |
// chunks now contains [ | |
// [1, 2, 3], | |
// [4, 5, 6], | |
// [7] | |
// ] |
This file contains 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 Cache(config) { | |
config = config || {}; | |
config.trim = config.trim || 600; | |
config.ttl = config.ttl || 3600; | |
var data = {}; | |
var self = this; | |
var now = function() { | |
return new Date().getTime() / 1000; |
This file contains 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
export type CamelCase<S extends string> = | |
S extends `${infer P1}_${infer P2}${infer P3}` | |
? `${Lowercase<P1>}${Uppercase<P2>}${CamelCase<P3>}` | |
: Lowercase<S>; | |
export type ObjectToCamel<T> = { | |
[K in keyof T as CamelCase<string & K>]: T[K] extends Record<string, any> | |
? KeysToCamelCase<T[K]> | |
: T[K]; | |
}; |
This file contains 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
interface Curry { | |
<T1, R>(func: (t1: T1) => R): CurriedFunction1<T1, R>; | |
<T1, T2, R>(func: (t1: T1, t2: T2) => R): CurriedFunction2<T1, T2, R>; | |
<T1, T2, T3, R>(func: (t1: T1, t2: T2, t3: T3) => R): CurriedFunction3< | |
T1, | |
T2, | |
T3, | |
R | |
>; | |
<T1, T2, T3, T4, R>( |
This file contains 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
/* eslint-disable no-restricted-syntax, no-console, no-await-in-loop */ | |
const { promises: fs } = require("fs"); | |
const { exec } = require("child_process"); | |
const TEST_COMMANDS = [ | |
"yarn check-types", | |
"yarn lint", | |
"yarn test", | |
"yarn build", | |
]; |
This file contains 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
// ONE implementation for everything | |
public static T[][] chunkArray<T>(T[] array, int chunkSize) { | |
int numOfChunks = (int)Math.Ceiling((double)array.Length / chunkSize); | |
T[][] output = new T[numOfChunks][]; | |
for(int i = 0; i < numOfChunks; ++i) { | |
int start = i * chunkSize; | |
int length = Math.Min(array.Length - start, chunkSize); | |
T[] temp = new T[length]; |
This file contains 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 { renderHook } from '@testing-library/react-hooks'; | |
import useFetch from '../useFetch'; | |
function mockSuccessfulFetch(data) { | |
global.fetch = jest.fn().mockResolvedValue({ | |
json: () => Promise.resolve(data), | |
}); | |
} | |
function mockErrorFetch(error) { |
This file contains 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 'date' | |
class Cache | |
Entry = Struct.new(:expiry, :value) | |
def initialize(opts={}) | |
@data = Hash.new | |
@opts = opts | |
end |
This file contains 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 isArray = function (a) { | |
return Array.isArray(a); | |
}; | |
const isObject = function (o) { | |
return o === Object(o) && !isArray(o) && typeof o !== 'function'; | |
}; | |
const toCamel = s => ( | |
s.replace(/([-_][a-z])/ig, $1 => $1.toUpperCase().replace(/[-_]/, '')) |
This file contains 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 toCamel = (s) => { | |
return s.replace(/([-_][a-z])/ig, ($1) => { | |
return $1.toUpperCase() | |
.replace('-', '') | |
.replace('_', ''); | |
}); | |
}; | |
const toSnake = (s) => { | |
return s.split(/(?=[A-Z])/).join('_').toLowerCase(); |
NewerOlder