Skip to content

Instantly share code, notes, and snippets.

View calaveraInfo's full-sized avatar

František Řezáč calaveraInfo

View GitHub Profile
@calaveraInfo
calaveraInfo / rotary-encoder.ino
Last active December 27, 2015 14:59
Use rotary encoder with Arduino Micro to increase/decrease a value and show that value on SSD1306 display. Based on https://learn.adafruit.com/pro-trinket-rotary-encoder/example-rotary-encoder-volume-control
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define OLED_DC 6
#define OLED_CS 7
#define OLED_RESET 8
#define PIN_ENCODER_A 4 //Micro pin 4 - encoder A
#define PIN_ENCODER_B 6
@calaveraInfo
calaveraInfo / Calavera_Fingerprint.cpp
Last active December 27, 2015 15:04
Adafruit fingerprint sensor with Arduino Micro
/***************************************************
This is a library for our optical Fingerprint sensor
Designed specifically to work with the Adafruit BMP085 Breakout
----> http://www.adafruit.com/products/751
These displays use TTL Serial to communicate, 2 pins are required to
interface
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
@calaveraInfo
calaveraInfo / ntag2xx_read.ino
Created January 23, 2016 19:01
Modified version of Adafruit ntag reader that outputs text from ntag to keyboard emulation.
/**************************************************************************/
/*!
@file readntag203.pde
@author KTOWN (Adafruit Industries)
@license BSD (see license.txt)
This example will wait for any NTAG203 or NTAG213 card or tag,
and will attempt to read from it.
This is an example sketch for the Adafruit PN532 NFC/RFID breakout boards
@calaveraInfo
calaveraInfo / optional.java
Last active February 21, 2017 12:18
Java 8 Optional: using map + null return value is allowed, no need to do flatMap + ofNullable. http://calavera.info/v3/blog/2016/11/17/nic.html
@Test
public void testOptional() {
assertEquals(Optional.of(
new AClass())
.map(AClass::getSomeObject)
.map(BClass::getSomeText)
.map(String::trim)
.orElse(""), "");
assertEquals(Optional.of(
new AClass(new BClass()))
@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 / ncatproxy.sh
Last active September 26, 2024 11:37
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 April 20, 2017 07:23
Very elementary grep-like tool. Can look just for a simple string in standard input, has no other parameters, but handles multiline log entries.

About

Standard grep has one weakness regarding the log files - it doesn't handle multiline log entries well. For example logs of Java programs are famous to have many lines of stack traces in a single log item. It is possible to use -A grep parameter but this adds lines also for log items that doesn't have any other lines in them resulting in showing log entries which doesn't contain the search term which is very confusing.

I was so frustrated greping through a log file once that I tried a more exotic approach using Lex and it turned out it's extremely easy with it. I realized that it's in fact raison d’être of lex and that it's very dumb not to use it in the first place.

@calaveraInfo
calaveraInfo / response.xml
Last active March 6, 2017 14:42
Testing some XML format for project
<?xml version="1.0" encoding="UTF-8"?>
<result>
<status>success</status>
<html xmlns="http://www.w3.org/1999/xhtml">
<a id="email">[email protected]</a>
<span id="filename">file.ext</span>
<table>
<thead>
<tr>
<th>Dodavatel</th>
@calaveraInfo
calaveraInfo / README.md
Last active April 20, 2017 07:25
Google apps script to forward email as html attachment (ie Email to Kindle integration)

About

@calaveraInfo
calaveraInfo / README.md
Created May 9, 2017 12:47
List of connections between physical reality and computation
  • Landauer's principle: There is a minimum energy needed to delete information because of the laws of thermodynamics.

  • Limits of Koomey's law: Because of Landauer's principle, for non-reversible computation there is a limit on number of computations per joule.

  • Margolus–Levitin theorem: Even reversible computing is constrained in number of computations per joule.

  • Bekenstein bound: Entropy in given finite space is limited.

  • Bremermann's limit: Implication of Bekenstein bound is that there is a limit on computational power of a computer.