Skip to content

Instantly share code, notes, and snippets.

View LukasForst's full-sized avatar

Lukas Forst LukasForst

View GitHub Profile
@LukasForst
LukasForst / Calculator.hs
Created May 28, 2018 18:38
Calculator in haskell for exam.
data Token = Mult | Add | Num Integer deriving (Show, Eq)
interp :: [Token] -> [Integer] -> Integer
interp ((Num x):tl) s = interp tl (x:s)
interp ((Add):tl) (a:b:ts) = interp tl (a + b : ts)
interp ((Mult):tl) (a:b:ts) = interp tl (a * b : ts)
interp _ s = head s
parse :: String -> Token
parse "*" = Mult
@LukasForst
LukasForst / commit-msg
Created April 16, 2019 14:46
Add Jira task number to your commit message
# Add git branch if relevant
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}
# Extact tracker abbreviation and ticket number (e.g. DS-123)
parse_git_tracker_and_ticket() {
parse_git_branch | grep -e '[A-Z]\+-[0-9]\+' -o
}
MESSAGE="$(cat $1)"
TICKET=`parse_git_tracker_and_ticket`
@LukasForst
LukasForst / functional.md
Last active June 2, 2019 10:28
Functional programming sum up for SZZ

Functional languages and their features

  • programming paradigm that treats computation as the evaluation of mathematical functions
  • aim to have no side effects -> this enables better parallelization and verification
  • output of a functions depends only on its inputs
  • no mutable data
  • generally speaking, they are less computationally efficient
  • ie - LISP is used in AutoCad or GImp

imperative programming

  • instructions to change the computer’s state
@LukasForst
LukasForst / pjv.md
Created June 2, 2019 13:38
6. Programování v jazyce JAVA: vlastnosti a koncepce jazyka. Principy objektového programování.

Programování v jazyce JAVA: vlastnosti a koncepce jazyka. Principy objektového programování.

Objektové programování

Objektově orientované programování (zkracováno na OOP) je metodika vývoje softwaru, založená na následujících myšlenkách, koncepci:

  1. Objekty – jednotlivé prvky modelované reality (jak data, tak související funkčnost) jsou v programu seskupeny do entit, nazývaných objekty. Objekty si pamatují svůj stav a navenek poskytují operace (přístupné jako metody pro volání).
  2. Abstrakce – programátor, potažmo program, který vytváří, může abstrahovat od některých detailů práce jednotlivých objektů. Každý objekt pracuje jako černá skříňka, která dokáže provádět určené činnosti a komunikovat s okolím, aniž by vyžadovala znalost způsobu, kterým vnitřně pracuje.
  3. Zapouzdření – zaručuje, že objekt nemůže přímo přistupovat k „vnitřnostem“ jiných objektů, což by mohlo vést k nekonzistenci. Každý objekt navenek zpřístupňuje rozhraní, pomocí kterého (a nijak jinak) se s objektem pracuje.
@LukasForst
LukasForst / line.kt
Last active November 25, 2019 09:11
One-Liner for coin change
fun main() {
val toChange = 132
val coins = listOf(50, 20, 10, 5, 2, 1).sortedDescending()
coins.fold(Pair(toChange, emptyList<Int>())) { (remaining, change), coin -> (remaining % coin) to (change + (remaining / coin)) }
.also { (remaining, change) ->
assert(0 == remaining)
print(change.zip(coins).joinToString(", ") { (change, coin) -> "$coin: ${change}x" })
}
}
@LukasForst
LukasForst / math_games.py
Last active January 8, 2020 11:51
Find all three digit numbers that does not contain 0, sum is 1617 and their product ends with 40. Also, no number can repeat and one number must be even and other one odd.
for i in range(912, 987):
for j in range(612, 698):
# contains zero
if((str(i) + str(j)).count('0')):
continue
# one must be even and one odd
if((i + j) % 2 == 0):
continue
try {
window.AudioContext = window.AudioContext || window.webkitAudioContext;
window.audioContext = new AudioContext();
} catch (e) {
alert('Web Audio API not supported.');
}
document.querySelector('button#control').addEventListener('click', function() {
audioContext.resume().then(() => {
console.log('Playback resumed successfully');
@LukasForst
LukasForst / backend_data.json
Created April 12, 2020 18:15
Speech2Text and LUIS data we gathered for the datavid.org with this beautiful command - `cat backend.logs | grep -Eo '\"{(.*)' | awk '{print substr($0, 2, length($0)-3)}' | sed 's/\\\"/\"/g' | jq > parsed.json`
This file has been truncated, but you can view the full file.
{
"id": "3b958811-ffc5-4812-b3d9-0ac494f0cb6d"
}
{
"id": "3b958811-ffc5-4812-b3d9-0ac494f0cb6d",
"age": null,
"comorbidities": [],
"complications": [],
"date_first_symptoms": null,
"disease_confirmation_date": null,
@LukasForst
LukasForst / kubernetes_commands.md
Created April 27, 2020 13:13 — forked from edsiper/kubernetes_commands.md
Kubernetes Useful Commands
@LukasForst
LukasForst / Config.java
Last active May 15, 2020 14:17
Logging to custom defined json with dropwizard
//
// Wire
// Copyright (C) 2016 Wire Swiss GmbH
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,