Skip to content

Instantly share code, notes, and snippets.

View libetl's full-sized avatar

LiBe libetl

View GitHub Profile
@libetl
libetl / my-commands.js
Last active February 28, 2017 20:34
pipeline
const pipeline = {
mapping: {},
respond: (regex, func) => {
this.mapping = this.mapping || {}
this.mapping[regex.source] = func
},
hear: (regex, func) => {
this.mapping = this.mapping || {}
this.mapping[regex.source] = func
},
@libetl
libetl / XmlInColorsConverter.java
Last active March 3, 2017 10:47
XmlInColorsConverter
import java.io.File;
import java.io.IOException;
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
public class XmlInColorsConverter {
private static final Pattern NAME = Pattern.compile("(?:([a-zA-Z][a-zA-Z0-9]+):)?([a-zA-Z][a-zA-Z0-9._]+)");
@libetl
libetl / webpack.config.js
Last active June 9, 2017 00:18
webpack2
/* imports */
const webpack = require('webpack')
const path = require('path')
const fs = require('fs')
const unzip = require('unzip2')/* imports */
const webpack = require('webpack')
const path = require('path')
const fs = require('fs')
const unzip = require('unzip2')
const mkdirp = require('mkdirp')
@libetl
libetl / IgnoreCertificateValidation.java
Created August 28, 2017 09:30
Disable RestTemplate certificate validation
package foo.bar.config;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.web.client.RestTemplate;
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
@libetl
libetl / PhoneParser.java
Last active August 31, 2017 07:48
How to parse a phone number with the google phone number util
import com.mycompany.mymodel.Phone;
import com.google.i18n.phonenumbers.NumberParseException;
import com.google.i18n.phonenumbers.PhoneNumberUtil;
import com.google.i18n.phonenumbers.Phonenumber;
import java.util.Locale;
import java.util.stream.Collectors;
import org.apache.commons.lang3.StringUtils;
import static com.mycompany.mymodel.Phone.phone;
@libetl
libetl / CrashesJavac.java
Created October 13, 2017 17:52
How to crash javac
public class TestExtendConsumer {
@FunctionalInterface public interface NumberConsumer<E extends Number> extends java.util.function.Consumer<E>{void accept(E number);}
private static <E extends Number> void extend(E number) {
System.out.println(number);
}
public static void main(String[] args) {
NumberConsumer numberConsumer = TestExtendConsumer::extend;
@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
@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 / 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 / package.json
Created March 2, 2018 19:16
yamlChecker
{
"name": "yamlchecker",
"version": "0.0.1",
"private": true,
"dependencies": {
"yamljs": "latest"
},
"devDependencies": {
"webpack": "latest"
}