Skip to content

Instantly share code, notes, and snippets.

View calaveraInfo's full-sized avatar

František Řezáč calaveraInfo

View GitHub Profile
@calaveraInfo
calaveraInfo / ncatproxy.sh
Last active February 8, 2024 08:35
How to create extremely simple (http) reverse proxy using netcat (nmap flavor) and a named pipe
mkfifo reply
ncat -kl 8765 < reply | ncat 127.0.0.1 4567 > reply # listens on port 8765 and redirects to localhost:4567. Runs until C-c.
rm reply # cleanup after end
@calaveraInfo
calaveraInfo / README.md
Last active August 11, 2023 09:46
Example of how to split single XML document to separate files using XSLT 2 and other advanced features

About

It is possible to create multiple output files as a result of XSL processing in XSLT 2 with tag xsl:result-document. This is usefull for example when some large database is available as a single XML document from which we need to extract only certain parts and/or modify it. This particular example takes export of accounts from the Waveset Identity Management system, filters them, modifies them and saves them in a separate file per account. This principle might be however usefull in many other cases.

This work is largely based on an example from IBM developer works

@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 January 27, 2021 05:29
Simple tool that redirects it's standard input to input buffer of a terminal (i.e. fake input to some terminal)

About

It is possible to redirect some input to TTY device by standard IO redirection.

echo ahoj > /dev/tty1

Such redirection will however end in the output buffer of the TTY device so the characters will be ghosts - visible on the terminal, but not effective. It is, in fact, not possible by standard tools to redirect input to terminal as if it is a real input from keyboard.

@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 / 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