Skip to content

Instantly share code, notes, and snippets.

Avatar
🌜

Jaakko Pallari jkpl

🌜
View GitHub Profile
@jkpl
jkpl / Main.scala
Last active Jan 26, 2023
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)"
}
@jkpl
jkpl / writing_tech_articles.md
Last active Jan 9, 2023
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 / utpl_download.sh
Created Oct 22, 2011
Script that downloads Youtube playlist and extracts the audio from the downloaded clips.
View utpl_download.sh
#!/bin/bash
## URL
# The URL to the Youtube playlist
URL="http://www.youtube.com/playlist?list=PL60BA016CD6B147F8"
## DESTPATH
# The path where to to download the music to
DESTPATH="$HOME/Music/awesome_new_music"
@jkpl
jkpl / article.org
Last active Nov 9, 2022
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,

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 / U.S. International wo dead keys.keylayout
Created Mar 9, 2022
U.S. International w/o dead keys keyboard layout for Mac
View U.S. International wo dead keys.keylayout
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE keyboard PUBLIC "" "file://localhost/System/Library/DTDs/KeyboardLayout.dtd">
<!--Last edited by Ukelele version 2.0.1 on 2010-08-26 at 17:40 (GMT+02:00)-->
<keyboard group="0" id="2" name="U.S. International w/o dead keys" maxout="1">
<layouts>
<layout first="0" last="17" modifiers="f4" mapSet="16c"/>
<layout first="18" last="18" modifiers="f4" mapSet="994"/>
<layout first="21" last="23" modifiers="f4" mapSet="994"/>
<layout first="30" last="30" modifiers="f4" mapSet="994"/>
<layout first="194" last="194" modifiers="f4" mapSet="994"/>
@jkpl
jkpl / article.md
Last active May 28, 2021
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.

View toggle_hyperv.ps1
param (
[Parameter(Mandatory=$false)]
[switch]$Disable
)
$script:regKeyPath = "HKLM\SYSTEM\CurrentControlSet\Control\DeviceGuard\Scenarios\HypervisorEnforcedCodeIntegrity"
If ($Disable) {
Write-Host "Disabling HyperV"
bcdedit /set hypervisorlaunchtype off
@jkpl
jkpl / article.md
Last active Mar 18, 2021
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 / eap-ttls-pap
Created Feb 1, 2013
Wicd template for Eduroam networks (this should work on Univesity of Jyväskylä's jyu-student and jyu-staff networks).
View eap-ttls-pap
name = EAP-TTLS-PAP
author = jkpl
version = 1
require identity *Identity password *Password
optional ca_cert *Path_to_CA_cert anon_identity *Anonymous_Identity
protected password *Password
-----
ctrl_interface=/var/run/wpa_supplicant
network={
ssid="$_ESSID"