Skip to content

Instantly share code, notes, and snippets.

Jaakko Pallari jkpl

Block or report user

Report or block jkpl

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View deploy.md
#!/bin/sh
#
# This script deploys the given manifest,
# tracks the deployment, and rolls back on failure.
#
# First execute this with "myapp.yaml" and then try it with "myapp.failing.yaml"
#
MANIFEST_PATH=$1
DEPLOYMENT_NAME=myapp
@jkpl
jkpl / Main.scala
Created Jan 8, 2018
Dropwizard Graphite demo for Scala
View Main.scala
package dwgraphitedemo
import java.lang.management.ManagementFactory
import java.util.concurrent.TimeUnit
import com.codahale.metrics.graphite.{Graphite, GraphiteReporter}
import com.codahale.metrics.SharedMetricRegistries
import com.codahale.metrics.jvm._
import com.twitter.finagle.http.{Request, Response, Status}
import com.twitter.finagle.{Http, Service}
@jkpl
jkpl / article.md
Last active Nov 12, 2018
Error handling pitfalls in Scala
View article.md

Error handling pitfalls in Scala

There are multiple strategies for error handling in Scala.

Errors can be represented as [exceptions][], which is a common way of dealing with errors in languages such as Java. However, exceptions are invisible to the type system, which can make them challenging to deal with. It's easy to leave out the necessary error handling, which can result in unfortunate runtime errors.

@jkpl
jkpl / altfin.keylayout
Created Feb 25, 2017
My old keyboard layout for OS X (Ukelele format)
View altfin.keylayout
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE keyboard PUBLIC "" "file://localhost/System/Library/DTDs/KeyboardLayout.dtd">
<!--Last edited by Ukelele version 2.2.4 on 2013-02-08 at 22:01 (UTC+2.00)-->
<keyboard group="0" id="5591" name="AltFin" maxout="1">
<layouts>
<layout first="0" last="17" modifiers="f4" mapSet="16c"/>
<layout first="18" last="18" modifiers="f4" mapSet="984"/>
<layout first="21" last="23" modifiers="f4" mapSet="984"/>
<layout first="30" last="30" modifiers="f4" mapSet="984"/>
<layout first="194" last="194" modifiers="f4" mapSet="984"/>
@jkpl
jkpl / csv2keepass.py
Created Feb 25, 2017
Convert CSV to KeepassX XML format
View csv2keepass.py
import sys
entry_t = """<entry>
<title>{title}</title>
<username>{username}</username>
<password>{password}</password>
<notes>{info}</notes>
</entry>"""
pwfile_t = """<!DOCTYPE KEEPASSX_DATABASE>
@jkpl
jkpl / check_rules.sh
Created Feb 25, 2017
Check window class and name (rules) in Xorg
View check_rules.sh
#!/bin/sh
xprop |awk '
/^WM_CLASS/{sub(/.* =/, "instance:"); sub(/,/, "\nclass:"); print}
/^WM_NAME/{sub(/.* =/, "title:"); print}'
@jkpl
jkpl / article.md
Last active Jul 14, 2017
HTML search and replace in Clojure
View article.md

HTML search and replace in Clojure

In Clojure, data structures are mostly built from a handful of core data structures such as lists, vectors, maps, and sets. This means that most data structures can leverage all of the generic data transformation and querying functions built for the core data structures instead of having to rebuild the same functionality for each data structure. This feature in combination with Clojure's rich standard library makes Clojure very attractive for solving data munching problems from other domains.

In this article, I'm going to demonstrate these capabilities for solving HTML transformations using Clojure. First, I'm going to describe how HTML can be represented in Clojure. With this representation in mind, I'll demonstrate how we can transform HTML documents in Clojure. Finally, I'll tie the transformations together with the HTML parsing and formatting to produce a complete solution.

@jkpl
jkpl / article.org
Last active Nov 13, 2018
Enforcing invariants in Scala datatypes
View article.org

Enforcing invariants in Scala datatypes

Scala provides many tools to help us build programs with less runtime errors. Instead of relying on nulls, the recommended practice is to use the Option type. Instead of throwing exceptions, Try and Either types are used for representing potential error scenarios. What’s common with these features is that they’re used for capturing runtime features in the type system, thus lifting the runtime scenario handling to the compilation phase: your program doesn’t compile until you’ve explicitly handled nulls, exceptions, and other runtime features in your code.

In his “Strategic Scala Style” blog post series,

@jkpl
jkpl / writing_tech_articles.md
Last active May 14, 2019
Writing tech articles
View writing_tech_articles.md

Writing tech articles

This is a description of how I write tech articles for various blogs. Hopefully someone else will find this useful as well.

Create a Gist for the article

When I begin writing a new article, I create a new [GitHub Gist][gist] for the article files. The Gist contains a file for the article text and code examples related to the article.

@jkpl
jkpl / Main.scala
Last active May 1, 2019
Ways to pattern match generic types in Scala
View Main.scala
object Main extends App {
AvoidLosingGenericType.run()
AvoidMatchingOnGenericTypeParams.run()
TypeableExample.run()
TypeTagExample.run()
}
class Funky[A, B](val foo: A, val bar: B) {
override def toString: String = s"Funky($foo, $bar)"
}
You can’t perform that action at this time.