Skip to content

Instantly share code, notes, and snippets.

View lene's full-sized avatar

Lene Preuss lene

View GitHub Profile
@lene
lene / assertThrows.scala
Last active September 16, 2023 19:17
Scala: assertThrows in Junit5 and hand-rolled
def throwingFunction(): Unit = throw RuntimeError()
// own implementation of assertThrows
def assertThrows[E](f: => Unit)(implicit eType:ClassTag[E]): Unit =
try f
catch
case _: E => return
case e: Any => Assertions.fail(s"Expected ${eType.runtimeClass.getName} got ${e.getClass}")
Assertions.fail(s"Expected ${eType.runtimeClass.getName}")
@lene
lene / attributes.scala
Last active October 3, 2022 18:26
Scala: print names and types of all attributes of an unknown object
UNKNOWN_OBJECT.getClass.getDeclaredFields.foreach(v => println(s"${v.getName}: $v"))
@lene
lene / sync.fish
Last active September 8, 2022 22:05
Sync Music dir to Google Drive
sudo apt install google-drive-ocamlfuse # to mount google drive as a pseudo fs
sudo apt install athena-jot # for generating the list of {A..Z} in fish shell on the fly
sudo apt install parallel # to control running jobs in parallel
# set up google drive, see https://github.com/astrada/google-drive-ocamlfuse/wiki/Authorization
google-drive-ocamlfuse
# mount google drive
set DRIVE_DIR GoogleDrive
google-drive-ocamlfuse ~/$DRIVE_DIR/
@lene
lene / tox265.fish
Last active August 30, 2022 11:38
re-encode videos to H.265, specifying source and target container format (fish shell)
set FROM_EXT mp4
set TO_EXT mkv
set ABR 128k
set CRF 22
for i in *.$FROM_EXT
set BASENAME (basename $i .$FROM_EXT)
set DIRNAME (dirname $i)
nice -n 19 time ffmpeg -i "$DIRNAME/$BASENAME.$FROM_EXT" -vcodec libx265 -crf $CRF -ac 2 -c:a libmp3lame -b:a $ABR output.$TO_EXT; and \
mv output.$TO_EXT "$DIRNAME/$BASENAME.$TO_EXT"; and \
rm "$i"
@lene
lene / subparser.py
Last active July 13, 2020 10:43
argparse subparser easy use
def command(args):
pass
parser = argparse.ArgumentParser()
subparser = parser.add_subparsers(title="subcommands")
command_parser = subparser.add_parser("command")
command_parser.set_defaults(func=command)
command_parser.add_argument("--dummy", help="some arg to the subcommand")
args = parser.parse_args()
@lene
lene / here.js
Last active March 20, 2018 14:26
Add this at the end of here.js to request and display a Park and Ride route
var mobility = new H.Mobility({
map: map,
app_id: '{YOUR_APP_ID}', // <-- ENTER YOUR APP ID HERE
app_code: '{YOUR_APP_CODE}', // <-- ENTER YOUR APP CODE HERE
});
var ui = mobility.createDefaultUI();
mobility.route({
dep: {YOUR_START_POINT}, // <-- ENTER YOUR START POINT HERE
@lene
lene / response.json
Last active March 20, 2018 14:27
HERE Intermodal Routing API response (shortened example)
{
"Res": {
"Connections": {
"Connection": [
{
"@duration": "PT2H3M33S",
"@transfers": "2",
"Sections": {
"Sec": [
{
@lene
lene / request.sh
Last active March 20, 2018 14:28
Anatomy of a request to the HERE Intermodal Routing API
http://mobility.api.here.com/v1/route
?app_id={YOUR_APP_ID}
&app_code={YOUR_APP_CODE}
&profile=parkandride
&dep={YOUR_START_POINT}
&arr=41.884238,-87.638862
&time=2018-03-20T07:30:00
@lene
lene / tools.js
Last active March 19, 2018 13:15
Requesting and rendering a route from the HERE Intermodal Routing API
(function(NS) {
var APP_ID = '{YOUR_APP_ID}', // // <-- ENTER YOUR APP ID HERE
APP_CODE = '{YOUR_APP_CODE}'; // <-- ENTER YOUR APP CODE HERE
function Mobility(options) {
this.map = options.map;
}
Mobility.prototype = {
@lene
lene / here.js
Created March 8, 2018 11:29
Creating a map using the HERE Maps Javascript API
var platform = new H.service.Platform({
useCIT: true,
app_id: '{YOUR_APP_ID}', // // <-- ENTER YOUR APP ID HERE
app_code: '{YOUR_APP_CODE}', // <-- ENTER YOUR APP CODE HERE
});
var maptypes = platform.createDefaultLayers();
var map = new H.Map(document.getElementById('map'), maptypes.terrain.map, {
zoom: 9,
center: { lat: 41.884238, lng: -87.638862 }