Skip to content

Instantly share code, notes, and snippets.

View klaeufer's full-sized avatar
:octocat:

Konstantin Läufer klaeufer

:octocat:
View GitHub Profile
@klaeufer
klaeufer / tlatex.sh
Last active April 28, 2024 23:42
Converts a TLA+ source to a LaTeX snippet containing only the resulting tlatex environment
#!/bin/bash
# Copyright 2024 Konstantin Läufer <laufer AT cs.luc.edu>
#
# 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
#
@klaeufer
klaeufer / catfacts.json
Last active April 18, 2024 22:43
LUC COMP 141 Materials
[
{
"breed": "Abyssinian",
"country": "Ethiopia",
"origin": "Natural\/Standard",
"coat": "Short",
"pattern": "Ticked"
},
{
"breed": "Aegean",
@klaeufer
klaeufer / freedns.sh
Created February 16, 2024 18:30
Update FreeDNS entry to private IP address on Linux - run manually, on startup, or in cron
#!/bin/bash
PRIVATE_IP=$(ip addr show wlp0s20f3 | grep 'inet ' | awk '{print $2}' | cut -f1 -d'/')
curl https://freedns.afraid.org/dynamic/update.php?MY_FREEDNS_API_KEY\&address=$PRIVATE_IP
// see also https://www.implicitdef.com/2015/11/19/comparing-scala-http-client-libraries.html
// task: use the prime checker webservice
// https://github.com/LoyolaChicagoCode/primenumbers-spray-scala
// to count the number of primes within a given range
/* instructions: create a build.sbt file in your project root folder containing the following lines:
scalaVersion := "3.3.1"
@klaeufer
klaeufer / http2ssh.sh
Created December 16, 2022 15:55
GitHub Classroom: replace HTTP access tokens with ssh
gsed -i 's/https:\/\/x-access-token:.*@github.com\//git@github.com:/' ./*/.git/config
import scala.util.Random
import java.util.concurrent.locks.ReentrantLock
def dinner(number: Int, delayInMs: Int) =
val forks = Array.fill(number)(new ReentrantLock)
// warning: running each philosopher in their own explicit Java thread
def phil(i: Int) = new Thread {
override def run(): Unit =
@klaeufer
klaeufer / IOboundTasks.scala
Last active November 29, 2022 22:57
I/O-bound tasks for experimenting in the Scala REPL
def p(s: String) =
for (i <- 1 to 10) {
Thread.sleep(500)
println(i + ": " + s)
}
// running two tasks sequentially
// about 20 seconds by design
val t0 = System.currentTimeMillis
p("a")
@klaeufer
klaeufer / KLSigPipeFun.scala
Created September 11, 2022 22:37 — forked from gkthiruvathukal/KLSigPipeFun.scala
Tinkering with Konstantin's example
object KLSigPipeFun {
def main(args: Array[String]) = {
val lines = scala.io.Source.stdin.getLines()
val lineNumbers = Iterator.from(1)
val numberedLines = lineNumbers.zip(lines)
val okLines = numberedLines takeWhile { _ => !scala.sys.process.stdout.checkError() }
val outLines = okLines map { case (number, line) => println(number + ":" + line) }
println(outLines.length + " lines counted")
}
}
@klaeufer
klaeufer / README.md
Last active March 21, 2022 17:55
Loyola COMP 271 GitHub account creation

Loyola COMP 271: GitHub-Based Project Workflow

Individual activity

Collaborate with your classmates on a conceptual level but do not share code. Submit individually.

Learning Objectives

  • Get started with Git source code management
@klaeufer
klaeufer / HOWTO.md
Last active March 21, 2022 16:56
How to copy a GitHub Java project into your own workspace

How to copy a GitHub Java project into your own workspace

This brief howto discusses several ways to copy a GitHub Java project into your own workspace so you can edit, compile, and run/test it.

Method 1 (highly discouraged)

This method is highly discouraged because it is tedious and error-prone.

  1. Create a new project in your development environment, such as IntelliJ IDEA.
  2. For each file in the GitHub project you are copying, create a file in your new project, then copy and paste the contents of the original file to your local file.