Skip to content

Instantly share code, notes, and snippets.

View machisuji's full-sized avatar

Markus Kahl machisuji

  • OpenProject GmbH
  • Cardiff, Wales, UK
View GitHub Profile
@machisuji
machisuji / aoc01.scala
Created December 1, 2021 10:23
Advent of Code - Day 1
def main(args: Array[String]): Unit = {
val data: Seq[Int] = io.Source.fromFile("input.txt").getLines.filter(_.nonEmpty).map(_.toInt).toSeq
def solution(xs: Seq[Int]): Int = xs.sliding(2, 1).count{case Seq(a, b) => b > a}
val part1 = solution(data)
val part2 = solution(data.sliding(3, 1).map(_.sum).toSeq)
println(s"Part 1: $part1")
println(s"Part 2: $part2")
}
@machisuji
machisuji / README.md
Created May 25, 2020 11:24
OpenProject: Testing translations via docker
  1. Get the current translations from the locales folder inside of the container.
docker run --name openroject -d --rm openproject/community:10

This will start the container from which you can copy the current files like this:

docker cp openproject:/app/config/locales ./
#!/usr/bin/env bash
function ruby_version {
if command -v ruby &> /dev/null; then
if [ -f ".ruby-version" ]; then
echo "ruby-$(ruby --version | cut -d " " -f 2) "
else
echo ""
fi
else
class AudioController
def playback
ssml = SSMD.to_ssml params.require(:ssmd)
result = Audio::Polly.say ssml, ssml: true, language: params[:language]
if result
send_data result.audio_stream.read, type: "audio/ogg", disposition: "inline"
else
render json: { errors: ["invalid SSML"] }, status: 400
end
##
# Synthesizes audio for the given text.
#
# @param text [String] The text to synthesize audio for.
# @param output [String|IO] (optional) Path to file to write or IO object to stream to.
# @return [SynthesizeSpeechOutput] A struct containing `audio_stream` (IO) and `content_type` (String).
def say(text, language: nil, output: nil, ssml: false)
client.synthesize_speech(
response_target: output,
output_format: "ogg_vorbis",
gem 'aws-sdk', '~> 2.9', '>= 2.9.14'
[root]
name = "foobar"
version = "0.1.0"
dependencies = [
"clap 2.19.0 (registry+https://github.com/rust-lang/crates.io-index)",
"cookie 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)",
"git2 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)",
"hoedown 5.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"hyper 0.9.12 (registry+https://github.com/rust-lang/crates.io-index)",
"iron 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",

Keybase proof

I hereby claim:

  • I am machisuji on github.
  • I am machisuji (https://keybase.io/machisuji) on keybase.
  • I have a public key whose fingerprint is 32E2 6FA6 DC83 142B DF35 C844 94AC 4D18 54C3 2FEA

To claim this, I am signing this object:

@machisuji
machisuji / params.scala
Last active September 3, 2015 23:57
optional parameters in Scala that are not a pain to write
import scala.language.implicitConversions
case class Optional[+T](value: Option[T])
val omit = Optional(None)
implicit def valueToOptional[T](value: T): Optional[T] = Optional(Some(value))
implicit def optionalToOption[T](opt: Optional[T]): Option[T] = opt.value
def add(a: Int, b: Optional[Int] = omit, c: Optional[Int] = omit): Int =
// improper use of a pattern match IMO
val negative = Constraint[Int] {
case i if i < 0 => Valid
_ => Invalid("Must be a negative number.")
}
// why not use if-else ?
val negative2 = Constraint[Int](i =>
if (i < 0) Valid
else Invalid("Must be a negative number."))