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 / convert_cmyk.bat
Last active August 29, 2015 14:16
Windows Batch Imagemagick png to pdf wrapped cmyk-jpeg: pass path as paramter like so: .\convert_cmyk.bat C:\my-path-to-pngs\
@echo off
echo This script converts png files to cmyk colorspaced jpgs wrapped in pdf for latex
echo Start converting...
echo.
for %%f in (%~1*) do if /i %%~xf==.png (
echo Converting %%f to cmyk jpeg compressed %%~nf.pdf
convert %%f +profile "*" -profile "path/to/rgb.icc" -profile "path/to/cmyk.icc" -strip -sampling-factor 1x1 -quality 95 -compress JPEG %%~pf\%%~nf.pdf
)
@patrickfav
patrickfav / KeyStoreHelper.java
Created September 21, 2016 10:24 — forked from alphamu/KeyStoreHelper.java
Using Android KeyStore to generate a password. The code create a public/private key pair and uses the base64 encoded form of the certificate to as the password. The code modified the KeystoreHelper class from AOSP demo projects.
/*
* Copyright 2013 The Android Open Source Project
*
* 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 / AndroidManifest.xml
Created January 30, 2017 21:17
Example for how to reproduce the restart bug in Seismic
<?xml version="1.0" encoding="utf-8"?>
<manifest package="com.company.seismicbug"
xmlns:android="http://schemas.android.com/apk/res/android">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
@patrickfav
patrickfav / gist:d3ea9bfcb1669389f0bb52240bace1f3
Created March 3, 2017 22:50
Read out all Security Provider
MessageDigest digest = null;
try {
digest = MessageDigest.getInstance("SHA-256");
byte[] hash = digest.digest("hallo".getBytes(Charset.forName("UTF-8")));
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
Provider[] providers = Security.getProviders();
for (Provider provider : providers) {
@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
@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 / 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 / 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 / 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)