Skip to content

Instantly share code, notes, and snippets.

View joel113's full-sized avatar

Johannes Ehm joel113

View GitHub Profile
@joel113
joel113 / gist:7b36d41c87e70d006a2a4d082af8e084
Created September 16, 2023 16:32 — forked from jauderho/gist:6b7d42030e264a135450ecc0ba521bd8
HOWTO: Upgrade Raspberry Pi OS from bullseye to bookworm
sudo apt-get update && sudo apt-get dist-upgrade
sudo sed -i -e 's/bullseye/bookworm/g' /etc/apt/sources.list
sudo sed -i -e 's/bullseye/bookworm/g' /etc/apt/sources.list.d/raspi.list
sudo apt update
sudo apt -y full-upgrade
sudo apt -y autoremove
sudo apt -y clean
sudo reboot
#
# remove old config files after doing sanity checks
@joel113
joel113 / AdbCommands
Created May 29, 2022 11:10 — forked from ernestkamara/AdbCommands
Adb useful commands list
== Adb Server
adb kill-server
adb start-server
== Adb Reboot
adb reboot
adb reboot recovery
adb reboot-bootloader
== Shell
@joel113
joel113 / NumericMultiplication.scala
Created March 30, 2022 23:47
Numeric Multiplication with a Double and a factor
object NumericMultiplication {
def translate[T: Numeric](a: T, factor: T) = {
import Numeric.Implicits._
a * factor
}
def main(args: Array[String]) = {
val doubleValue = 3.33
val double: Double = translate[Double](doubleValue,1.394)
@joel113
joel113 / Client.java
Created February 15, 2022 19:48 — forked from ebarlas/Client.java
package test;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.SelectableChannel;
import java.nio.channels.SelectionKey;
import java.nio.channels.Selector;
import java.nio.channels.SocketChannel;
import java.util.Arrays;
@joel113
joel113 / forcomp.scala
Created October 8, 2021 20:59 — forked from linasm/forcomp.scala
Comprehending the For-Comphension talk, Vilnius, Nov 2018
sealed abstract class Perhaps[+A] {
def foreach(f: A => Unit): Unit
def map[B](f: A => B): Perhaps[B]
def flatMap[B](f: A => Perhaps[B]): Perhaps[B]
def withFilter(f: A => Boolean): Perhaps[A]
}
case class YesItIs[A](value: A) extends Perhaps[A] {
override def foreach(f: A => Unit): Unit = f(value)
override def map[B](f: A => B): Perhaps[B] = YesItIs(f(value))
@joel113
joel113 / KafkaInZioQueuesFibers.scala
Created August 29, 2021 14:23 — forked from mtsokol/KafkaInZioQueuesFibers.scala
Build your own Kafka in ZIO - Queues & Fibers
import zio._
import zio.random._
import zio.console._
import zio.duration._
object Main extends App {
override def run(args: List[String]) = program.exitCode
sealed trait Diagnostic
@joel113
joel113 / kinesis-get-records.sh
Created April 28, 2021 18:14 — forked from codemedic/kinesis-get-records.sh
Get records from a AWS Kinesis Data Stream. It allows you to start iterating from a time in the past.
#!/usr/bin/env bash
if ! aws_bin="$(which aws)" 2>/dev/null; then
echo "aws cli is missing; you can get it from https://aws.amazon.com/cli/"
exit 1
fi
if ! jq_bin="$(which jq)" 2>/dev/null; then
echo "jq is missing; you can get it from https://stedolan.github.io/jq/"
exit 1
val f: Future[List[String]] = Future {
session.getRecentPosts
}
// handle the result of both failed and successful future computations
f onComplete {
case Success(posts) => for (post <- posts) println(post)
case Failure(t) => println("An error has occurred: " + t.getMessage)
}
import scala.io.Source
import java.net.URL
import scala.util.Try
def parseURL(url: String): Try[URL] = Try(new URL(url))
def getURLContent(url: String): Try[Iterator[String]] =
for {
url <- parseURL(url)
connection <- Try(url.openConnection())
is <- Try(connection.getInputStream)
source = Source.fromInputStream(is)
def squareAndHalf(number: String): Try[Int] = {
Try(number.toInt).map(value => value*value).map(value => value/2)
}
val result = for (
v <- Try("5".toInt);
k <- Try("6".toInt);
z <- Try("9".toInt)
) yield( v + k + z)