Skip to content

Instantly share code, notes, and snippets.

@miguno
miguno / README.md
Last active January 10, 2023 16:43 — forked from peterbartha/README.md
Convert Rust books to EPUB (incl. The Rust Programming Language)
View README.md

Convert Rust books to EPUB (incl. The Rust Programming Language)

The following steps work for all the HTML learning materials on the Learn Rust page:

  1. Click on the "Print this book" icon in the top right corner.
  2. "Cancel" print popup.
  3. Press F12 (on Firefox) to open the browser console. Or: Tools > Browser Tools > Web Developer Tools, then switch to Console tab.
  4. Copy, paste, and run the contents of ebookFormatPreparation.js into your browser's console.
  5. Save the modified HTML file.
@miguno
miguno / detectStdin.go
Last active March 26, 2022 21:40
Detect whether golang application is reading input from STDIN
View detectStdin.go
func isInputFromStdin() bool {
info, err := os.Stdin.Stat()
if err != nil {
log.Fatal(err)
}
if info.Mode()&os.ModeNamedPipe == 0 {
return false
} else {
return true
}
View gist:dc6e3c7dc39c0410042296663e4ee67a
physics/shield/bullet_hit_shield_07.wav
physics/shield/bullet_hit_shield_06.wav
physics/shield/bullet_hit_shield_05.wav
physics/shield/bullet_hit_shield_04.wav
physics/shield/bullet_hit_shield_03.wav
physics/shield/bullet_hit_shield_02.wav
physics/shield/bullet_hit_shield_01.wav
player/winter/snowball_throw_04.wav
player/winter/snowball_throw_03.wav
player/winter/snowball_throw_02.wav
@miguno
miguno / copartitioning.sql
Last active November 28, 2019 14:45
ksqlDB example: creates a new stream with changed number of partitions and a new field as event key (so that its data can be correctly co-partitioned for joining)
View copartitioning.sql
CREATE STREAM products ...;
CREATE STREAM products_repartitioned
WITH (PARTITIONS=42) AS
SELECT * FROM products
PARTITION BY product_id
EMIT CHANGES;
@miguno
miguno / increased-partitions.sql
Last active January 11, 2020 00:14
ksqlDB example: Create a new stream with the desired number of partitions.
View increased-partitions.sql
CREATE STREAM products ...;
CREATE STREAM products_repartitioned
WITH (PARTITIONS=30) AS
SELECT * FROM products
EMIT CHANGES;
@miguno
miguno / topic-as-table.java
Last active January 9, 2020 07:56
Kafka Streams Example: read topic as table
View topic-as-table.java
// Create KTable from Kafka topic.
KTable<String, String> table = builder.table("input-topic", Consumed.with(Serdes.String(), Serdes.String()));
@miguno
miguno / topic-as-table.sql
Last active January 9, 2020 07:56
ksqlDB example: read topic as table
View topic-as-table.sql
-- Create ksqlDB table from Kafka topic.
CREATE TABLE myTable (username VARCHAR, location VARCHAR)
WITH (KAFKA_TOPIC='input-topic', KEY='username', VALUE_FORMAT='...');
@miguno
miguno / topic-as-stream.sql
Last active January 9, 2020 07:37
ksqlDB example: read topic as stream
View topic-as-stream.sql
-- Create ksqlDB stream from Kafka topic.
CREATE STREAM myStream (username VARCHAR, location VARCHAR)
WITH (KAFKA_TOPIC='input-topic', VALUE_FORMAT='...');
@miguno
miguno / topic-as-stream.java
Last active January 9, 2020 07:38
Kafka Streams Example: read a topic as a stream
View topic-as-stream.java
// Create KStream from Kafka topic.
StreamsBuilder builder = new StreamsBuilder();
KStream<String, String> stream =
builder.stream("input-topic", Consumed.with(Serdes.String(), Serdes.String()));
@miguno
miguno / aggregation.java
Last active April 13, 2022 13:02
Kafka Streams Example: Continuously aggregating a stream into a table
View aggregation.java
// Continuously aggregating a KStream into a KTable.
KStream<String, String> locationUpdatesStream = ...;
KTable<String, Long> locationsPerUser
= locationUpdatesStream
.groupBy((k, v) -> v.username)
.count();