Skip to content

Instantly share code, notes, and snippets.

View calaveraInfo's full-sized avatar

František Řezáč calaveraInfo

View GitHub Profile
@calaveraInfo
calaveraInfo / CovarianceTest.java
Last active November 29, 2019 10:16
Wildcards in "indirect" or "second level" generics.
package x;
/**
* <p>
* Wildcards in "indirect" or "second level" generics.
* <p>
* {@link #list} contains generic items.
* {@link #testWildcard()} and {@link #testGeneric()} wants to work with that items
* and shouldn't care about it's generic type <i>as long as it's the same type through the
* whole method<i>. How to express that correctly (if it's possible at all)?
@calaveraInfo
calaveraInfo / Index.java
Created November 21, 2019 08:59
Intermittently mutable data concept
public interface Index() {
/*
* @return mutable copy of indexes contained in this instance.
*/
MutableIndex beginMutation();
/*
* Example usage of indexes for data retrieval.
*/
PrimaryKey findBySomeAttributeValue(String value);
@calaveraInfo
calaveraInfo / Sandbox.java
Created August 23, 2019 11:55
Floating point hell
import java.math.BigDecimal;
import org.junit.jupiter.api.Test;
public class Sandbox {
@Test
public void testFloat() {
double raw = 21.05d;
double computed = 21.025d+0.025d;
double rounded = Math.round((21.025d+0.025d) * 1000d) / 1000d;
System.out.println(raw);
@calaveraInfo
calaveraInfo / GenericPolymorphicFunctionTest.java
Last active August 22, 2019 20:19
Generic polymorphic function
package cz.cez.trading.algo.core;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.Test;
public class GenericPolymorphicFunctionTest {
@Test
public void testPolymorphicFunction() {
@calaveraInfo
calaveraInfo / log
Created August 23, 2018 11:26
CZ eID smartcard init fail
0x7f3ef3603700 10:30:07.180 [opensc-tool] sc.c:259:sc_detect_card_presence: called
0x7f3ef3603700 10:30:07.180 [opensc-tool] reader-pcsc.c:397:pcsc_detect_card_presence: called
0x7f3ef3603700 10:30:07.180 [opensc-tool] reader-pcsc.c:303:refresh_attributes: Gemalto PC Twin Reader (6C5795CE) 01 00 check
0x7f3ef3603700 10:30:07.181 [opensc-tool] reader-pcsc.c:323:refresh_attributes: returning with: 0 (Success)
0x7f3ef3603700 10:30:07.181 [opensc-tool] reader-pcsc.c:402:pcsc_detect_card_presence: returning with: 1
0x7f3ef3603700 10:30:07.181 [opensc-tool] sc.c:264:sc_detect_card_presence: returning with: 1
Using reader with a card: Gemalto PC Twin Reader (6C5795CE) 01 00
0x7f3ef3603700 10:30:07.181 [opensc-tool] sc.c:259:sc_detect_card_presence: called
0x7f3ef3603700 10:30:07.181 [opensc-tool] reader-pcsc.c:397:pcsc_detect_card_presence: called
0x7f3ef3603700 10:30:07.181 [opensc-tool] reader-pcsc.c:303:refresh_attributes: Gemalto PC Twin Reader (6C5795CE) 01 00 check
@calaveraInfo
calaveraInfo / README.md
Last active March 26, 2022 08:32
Backup shell script using rsync

About

This is simplified version of script I'm using for doing my backups. I have prepared it only recently because manual invocation of rsync was enough for me. But as the number of separately rsynced folders increased I was forced to introduce some automation and I had to solve some interesting problems along the way.

Persistent SSH connection

Normally a separate SSH connection is established for each rsync invocation. That may become irritating if, for some reason, establishing an SSH connection requires

@calaveraInfo
calaveraInfo / README.md
Last active December 14, 2017 12:52
Bookmarklet helper for adding global Ajax callbacks manualy from console.
@calaveraInfo
calaveraInfo / signature.txt
Created September 19, 2017 07:33
Cory Doctorow email signature
For avoidance of doubt: This email does not constitute permission to add
me to your mailing list.
READ CAREFULLY. By reading this email, you agree, on behalf of your
employer, to release me from all obligations and waivers arising from
any and all NON-NEGOTIATED agreements, licenses, terms-of-service,
shrinkwrap, clickwrap, browsewrap, confidentiality, non-disclosure,
non-compete and acceptable use policies ("BOGUS AGREEMENTS") that I have
entered into with your employer, its partners, licensors, agents and
assigns, in perpetuity, without prejudice to my ongoing rights and
@calaveraInfo
calaveraInfo / cardtest.sh
Created September 13, 2017 12:00
Shell script that repeats simple smart card operations many times. May be used to measure smart card performance or reliability.
#!/bin/bash
# pkcs15-tool --list-keys
# Private RSA Key [Digital Signature]: ID: 11
TEMPFILE=`mktemp`
# reading PIN into environment variable is NOT safe, DO NOT use on shared computer.
# read is built-in, manual can be shown with
# help read
read -e -s -p "PIN: " PIN
@calaveraInfo
calaveraInfo / dmenu.sh
Created September 4, 2017 15:56
Dmenu parameters I like
echo -e "Hello\nHi\nGood morning\nGood afternoon\nGood evening" | dmenu -i -p "Greeting:" -b -l 5 -fn "-*-terminal-*-*-*-*-18-*-*-*-*-*-*-*" -nf green