Skip to content

Instantly share code, notes, and snippets.

@androidfred
androidfred / haskell_stack_and_intellij_idea_ide_setup_tutorial_how_to_get_started.md
Last active August 8, 2024 07:24
Haskell, Stack and Intellij IDEA IDE setup tutorial how to get started

Haskell, Stack and Intellij IDEA IDE setup tutorial how to get started

Upon completion you will have a sane, productive Haskell environment adhering to best practices.

Basics

  • Haskell is a programming language.
  • Stack is tool for Haskell projects. (similar tools for other languages include Maven, Gradle, npm, RubyGems etc)
  • Intellij IDEA IDE is a popular IDE.

Install required libraries

sudo apt-get install libtinfo-dev libghc-zlib-dev libghc-zlib-bindings-dev

@androidfred
androidfred / anti_tests.md
Last active March 3, 2021 02:08
Anti-tests

Test your tests

Summary: test interfaces, not implementations

Tests that pass when something is actually broken, and fail when things actually do work, are worse than useless- they are positively harmful.

The requirement

Let's say we've been tasked with returning 400 when GET /users/<userId> is called with a negative userId.

The test

The requirement can be turned into a test that hits the endpoint with a negative userId and checks that a 400 is returned:

@androidfred
androidfred / javafx.md
Last active October 27, 2021 03:21
java.lang.ClassNotFoundException: javafx.util.Pair

java.lang.ClassNotFoundException: javafx.util.Pair happens because javafx.util.Pair and other classes from javafx.util are not included in OpenJDK. Options for resolving:

Switch class

Map.Entry<K, V> from java.util is similar to javafx.util.Pair.

Install java-openjfx

Install java-openjfx through your package manager. (or whatever means you used to install Java on your machine) Note that java-openjfx is compatible with OpenJDK8, not previous versions.

After installing java-openjfx, you may have to add it manually to your IDE SDK classpath. Eg in IntelliJ, you may have to go to Project Structure | SDKs | <select your SDK> | Classpath | + (the Classpath +, not the SDKs +) | and add /usr/lib/jvm/java-8-openjdk/jre/lib/ext/jfxrt.jar (which should be there now that java-openjfx has been installed) | OK

@androidfred
androidfred / advanced_anki_deck_editing.md
Last active April 27, 2024 04:25
Advanced Anki deck editing made simple (ish)

Advanced Anki deck editing made simple (ish)

Anki is a great open source flashcard app that can be used to learn anything.

This Gist is a full end to end example of how to:

  • export Anki decks from Anki
  • import Anki decks into MySQL
  • edit Anki decks using MySQL
  • export Anki decks from MySQL
@androidfred
androidfred / lambdas_functions_functors_monads.md
Last active May 17, 2024 15:42
Lambdas, Functions, Functors and Monads

Lambdas, Functions, Functors and Monads

Intro

If you've been exposed to lambdas (whether in Java or Kotlin), you already know at least the basics of what lambdas are, the syntax for using them, that they're more succinct than instantiating anonymous classes etc etc.

Rather than talking about that, I figured we would talk about functions and lambdas on a higher level.

I think most of us are familiar with map and, having used it quite a bit, have an intuitive understanding of what any given call to map will do.

Does anyone know a bit more about map, what it is and where it came from?

@androidfred
androidfred / kotlin_dsl.md
Last active February 27, 2021 01:26
Kotlin DSLs

Kotlin in Action: DSLs

General purpose programming language

  • imperative (sequence of stateful, ordered steps that describe how to do something)
  • wide scope
  • Java, Bash etc
  • potential for "runtime errors"

DSL (Domain Specific Language)

  • declarative (describes what something is, not how to do it)
@androidfred
androidfred / kotlin_arrow.md
Last active December 7, 2023 17:42
Kotlin Arrow

Kotlin Arrow

A lot of Kotlin features can be traced back to functional programming languages, eg

  • Heavy use of immutability-by-default and map, filter etc functions
  • Type inference
  • Data classes (which enable pattern matching)
  • Null safety and dealing with the absence of values

However, Kotlin is missing many incredibly useful data types that are ubiquitous in functional programming languages, eg Either, Try etc.

@androidfred
androidfred / help.md
Last active May 24, 2023 20:10
How to ask for help or report a problem

How to ask for help or report a problem

I've been in tech 10 years now, and it never ceases to amaze me how bad even professional techies are at asking for help or reporting a problem.

How many times have you reached out to someone, or been reached out by someone else, something like this? (to be clear, I'm guilty as charged of this)

"I can't do x"

"y is broken"

@androidfred
androidfred / how_to_run_long_running_script_jobs.md
Created February 25, 2021 05:04
How to run long running script jobs

How to run long running scripts, jobs

Running long running script jobs is tricky because:

  • running them from your local machine, interruptions will result from loss of internet or VPN connectivity, or from your local machine going to sleep, running out of power etc etc
  • running them from jumpboxes 1) interruptions will result from the session timeout 2) even if you send the script job to run in background, interruptions will still result from jumpbox churn (jumpbox machines are often churned all the time for security reasons) 3) jumpbox urls are often just load balancers, there's no guarantee that, even after sending a script job to run in background on a jumpbox, and you later ssh to jumpbox again, you will end up on the same machine (so you'll never be able to find, let alone terminate the process if there's a problem etc)
  • in general, long running script jobs require using commands we don't use all that often (like nohup), making sure we keep track of and are able to kill the process if required, m
@androidfred
androidfred / database_pointers.md
Created May 31, 2021 02:43
Database pointers

Database pointers

I used to think creating and managing a db and a schema for a given service was easy, and that I knew all about how to do it... but I was wrong! There are actually quite a few things that need to be kept in mind in order to avoid easily preventable issues when working with databases and how they interact with your code and tests - this post will cover a bunch. Parts of it is pretty technology specific (eg AWS RDS and MySQL specific), but much of it is universally applicable for all db technologies so well worth reading even if you use something else.

I hope you will find it helpful - and that you will comment and point out any errors or things you think are missing that are worth mentioning!

Creating and managing databases

At Expedia, AWS RDS is commonly used. One of the main points of AWS RDS is to make creating and managing databases easy, but there are actually still a surprising amount of complexity and potential pitfalls that should be kept in mind when using RDS, much of which i