Skip to content

Instantly share code, notes, and snippets.

View libetl's full-sized avatar

LiBe libetl

View GitHub Profile
@libetl
libetl / fakemoment.ts
Created November 30, 2019 20:18
Fake moment.js
const moment = function moment(textValue: string | number, format: string) {
const timeOfTheDay = /^([0-9]{1,2}):([0-9]{1,2})$/.exec((textValue || "").trim())
const onlyTime = timeOfTheDay && new Date()
if (onlyTime && timeOfTheDay) onlyTime.setHours(parseInt(timeOfTheDay[1]), parseInt(timeOfTheDay[2]))
const date = !textValue ? new Date() :
!isNaN(textValue as number) ? new Date(textValue) :
!(textValue as string).trim() ? new Date() :
onlyTime ? onlyTime : new Date(textValue)
return {
date,
@libetl
libetl / CreditCardNumberChecker.ts
Created November 10, 2019 19:52
CreditCardNumberChecker.ts
type CardType = 'MasterCard' | 'Visa' | 'American Express' |
'JCB' | 'Diners Club' | 'Discover' | 'unknown'
type MajorIndustryIdentifier =
'ISO/TC 68' | 'Airlines' | 'Travel and entertainment and banking/financial' |
'Banking and financial' | 'Merchandising and banking/financial' |
'Petroleum' | 'Healthcare and telecommunications' | 'National assignment' |
'unknown'
type CreditCardGuessedInformation = {
@libetl
libetl / Router.kt
Last active December 30, 2020 18:17
Router
package org.toilelibre.libe
import java.lang.reflect.Method
import kotlin.math.pow
import kotlin.reflect.KFunction
import kotlin.reflect.full.companionObject
import kotlin.reflect.full.companionObjectInstance
import kotlin.reflect.full.declaredFunctions
import kotlin.reflect.full.memberProperties
@libetl
libetl / XmlToMap.java
Last active February 28, 2024 23:06
XmlToMap (Java + Kotlin)
package xmltomap;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Deque;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
@libetl
libetl / RestTemplateInjector.kt
Last active October 31, 2018 20:33
RestTemplateInjector
package com.myservice.infra.testinterceptor
import com.fasterxml.jackson.databind.ObjectMapper
import org.springframework.http.HttpRequest
import org.springframework.http.HttpStatus
import org.springframework.http.client.ClientHttpRequestExecution
import org.springframework.http.client.ClientHttpRequestInterceptor
import org.springframework.http.client.ClientHttpResponse
import org.springframework.mock.http.client.MockClientHttpResponse
import java.io.File
@libetl
libetl / KotlinBuilderTest.kt
Created October 17, 2018 21:49
simplest kotlin builder
fun main(args: Array<String>) {
val choosenMenu = menu {
fish
chips
hamburger
}
println(choosenMenu)
}
@libetl
libetl / package.json
Created March 2, 2018 19:16
yamlChecker
{
"name": "yamlchecker",
"version": "0.0.1",
"private": true,
"dependencies": {
"yamljs": "latest"
},
"devDependencies": {
"webpack": "latest"
}
@libetl
libetl / readGtfsDumps.js
Last active March 1, 2018 20:41
gtfsServer
const {get} = require('axios')
const unzip = require('yauzl')
const eventStream = require('event-stream')
const keys = {
agency: ['agency_id'],
stops: ['stop_id'],
calendar: ['service_id'],
calendar_dates: ['date', 'service_id'],
routes: ['route_id'],
@libetl
libetl / react-button.js
Created December 28, 2017 10:10
react-button.js
import React from 'react'
import {
Animated, Image, IsNative, LoadPicture, Text, TouchableOpacity, TouchableWithoutFeedback, View} from 'react-native'
export default class RoundButton extends React.Component {
constructor(props) {
super(props)
this.state = {width: `${100/props.nbButtons}%`, height: `${100/props.nbButtons}%`,
fadeAnim: new Animated.Value(0), longPressHeight: 0}
this.measureButton = this.measureButton.bind(this)
@libetl
libetl / benchmark.js
Last active November 29, 2017 21:34
Benchmark.js
const benchmark = ({theContestants, howManyTimes, forThisWork, barSettings, asText, logInConsole, seedInit}) => {
const timestamp = () => {
const hrTime = process.hrtime();
return hrTime[0] * 1000000 + hrTime[1] / 1000
}
const asNumbers = (name, duration) => `[${name.padStart(20)}]: ${`${(duration).toFixed(5)}`.padStart(15)} µs, ${`${((duration) / 1000).toFixed(0)}`.padStart(5)} ms, ${`${((duration) / 1000000).toFixed(2)}`.padStart(5)} s`
const asBar = (between0And1, histogramDisplay = barSettings) => {
const peak = between0And1 * histogramDisplay.width
const interval = histogramDisplay.width / histogramDisplay.gradient.length