Skip to content

Instantly share code, notes, and snippets.

View patrickfav's full-sized avatar
🐿️
Nam nam nam

Patrick Favre patrickfav

🐿️
Nam nam nam
View GitHub Profile
@patrickfav
patrickfav / encoding_info.txt
Last active February 26, 2023 18:40
Overview of Many Popular Binary-to-Text Encodings and their properties.
## Binary
┌─────────────────┬──────────────────────────────────────────────────────────────────┐
│ Efficiency │ 12.5 % (1 bit/char), 1 bit segments │
│ 32/64/128 bit │ 1-32/1-64/1-128 chars │
│ Padding │ false │
│ Const. Out. Len.│ false │
│ Suited for │ number encoding, debugging │
│ Alphabet │ 01 │
│ Known Usages │ none │
@patrickfav
patrickfav / sigma-js-angular-app.js
Last active February 25, 2023 13:12
Simple Sigma.js AngularJs Directive: Since I did not find any angularjs directive for angularjs I created a little simple of my own. This is by no means a ready-for-all solutions, but all the features I needed at the time; it is easily extended to your needs and maybe sometimes somebody will do a full-blown directive for sigma.js Tested: angular…
/*
* Copyright 2017 Patrick Favre-Bulle
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@patrickfav
patrickfav / gsap-404-typed-message-using-splittext.markdown
Created October 23, 2020 20:44
GSAP 404 typed message using SplitText
@patrickfav
patrickfav / RandomOrgUtil.java
Last active August 18, 2020 17:44
Random.org Signed Response Verification (Java)
/*
Copyright 2017 Patrick Favre-Bulle
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
@patrickfav
patrickfav / EncodingBenchmark.java
Last active April 27, 2019 16:23
Simple JMH Benchmark to test Hex vs Base64 Encoding Performance
import at.favre.lib.bytes.Bytes;
import org.openjdk.jmh.annotations.*;
import org.openjdk.jmh.infra.Blackhole;
import java.util.concurrent.TimeUnit;
@SuppressWarnings("CheckStyle")
@State(Scope.Thread)
@Fork(1)
@Warmup(iterations = 2, time = 4)
@patrickfav
patrickfav / IdMaskExample1.java
Created April 24, 2019 18:14
Id Mask 64-Bit Integer Example for Medium Article
byte[] key = Bytes.random(16).array();
long id = ...
IdMask<Long> idMask = IdMasks.forLongIds(Config.builder(key).build());
String maskedId = idMask.mask(id);
//example: NPSBolhMyabUBdTyanrbqT8
long originalId = idMask.unmask(maskedId);
@patrickfav
patrickfav / MultipleOrientationSlidingDrawer.java
Created August 20, 2013 16:56
My solution for a Sliding Drawer that can come from Top: I extracted SlidingTray from this lib http://aniqroid.sileria.com/doc/api/ (by Ahmed Shakil) and refactored it a bit since it had some quirks needed to be used within this lib. It consists of 1 class and you have to add atts in your attrs.xml. Other than that it has pretty much the same us…
package your.app;
/*
* Copyright (c) 2001 - 2012 Sileria, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
@patrickfav
patrickfav / BcryptMemoryLeakTest.java
Last active March 29, 2019 22:38
Very simple test for probable Memory Leak in Bcrypt Library
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
public class Tester {
public static String[] pws = {"ZeDRJ:_tu:", "ZeDRJ:_tu1", "ZeDRJ:_tu2", "ZeDRJ:_tu3", "ZeDRJ:_tu4", "ZeD1", "ZeDRJu1", "ZeDRJ:_tu19881", "98asfhj", "adasd", "()=H)d"};
public static Random r = new Random();
public static List<BCrypt.Verifyer> verifyers = new ArrayList<>();
public static boolean introduceMemoryLeak = false;
@patrickfav
patrickfav / ImageUtil.java
Last active October 3, 2017 20:11
StackOverflow Question 36029295
/*
* Copyright 2017 Patrick Favre-Bulle
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software