Skip to content

Instantly share code, notes, and snippets.

@futtetennista
futtetennista / type_classes.worksheet.sc
Created July 31, 2022 19:18
Type classes in Scala 3
trait Semigroup[T]:
def mappend(x: T, y: T): T
trait Monoid[T] extends Semigroup[T]:
def empty: T
object Semigroup:
given sumIntSemigroup: Semigroup[Int] with
override def mappend(x: Int, y: Int): Int = x + y
@futtetennista
futtetennista / kindle2anki.sh
Last active June 15, 2019 12:32
Export Kindle highlights to Anki
#!/usr/bin/env bash
set -euox pipefail
# Go to https://read.amazon.com/notebook and export your highlights as JSON using https://readwise.io/bookcision
#
# Install http://ankiweb.net/ and the https://foosoft.net/projects/anki-connect/index.html extension. Create a simple front-only card in anki, e.g.
# Card template: {{Front}}
# Styling:
# .card {
@futtetennista
futtetennista / FreeFSM.hs
Last active November 1, 2023 10:56
Free FSM! An implementation of finite state machines as in https://wickstrom.tech/finite-state-machines/2017/11/19/finite-state-machines-part-2.html using Free monads
#!/usr/bin/env stack
-- stack script --resolver lts-9.14 --package free
{-# LANGUAGE GADTs, DeriveFunctor #-}
type CartItem =
String
type CreditCard =
String

Keybase proof

I hereby claim:

  • I am futtetennista on github.
  • I am futtetennista (https://keybase.io/futtetennista) on keybase.
  • I have a public key ASB-391E1CLq7CqRsAvsqmW3Tnlm8PmcSh6_w4MaOZueego

To claim this, I am signing this object:

@futtetennista
futtetennista / RESOURCES.md
Last active May 25, 2017 14:44
Primer: Writing efficient code in a lazy language (Hamburg Haskell Meetup 2016-05-24)
@futtetennista
futtetennista / ThreadPoolIdlingResource.java
Last active October 12, 2016 23:53
Code taken from Espresso's AsyncTaskPoolMonitor and adapter to be used as an idling resource for any ThreadPoolExecutor
/*
* Copyright (C) 2013 Google, 2014 Stefano Dacchille
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
public class CustomUncaughtExceptionHandlerProxy implements Thread.UncaughtExceptionHandler {
private static CustomUncaughtExceptionHandlerProxy proxy;
private final boolean enabled;
private Thread.UncaughtExceptionHandler customUncaughtExceptionHandler;
private CustomUncaughtExceptionHandlerProxy(CustomApplication application) {
enabled = !application.inDevMode();
@futtetennista
futtetennista / IgnitedActivity
Created October 11, 2012 21:07
Qype Location Manager
@Override
public boolean onIgnitedLocationChanged(Location location) {
return locationManager.onNewLocation(this, location, lastSearchedLocation);
}
private class EndlessOnPageChangeListener implements OnPageChangeListener {
private static final int NO_PAGE = -1;
int loadingPage = NO_PAGE;
@Override
public void onPageSelected(int currentPage) {
// we're not on the loading element
if (loadingPage != currentPage) {
loadingPage = NO_PAGE;
currentAdapter.setLoadingData(false);
@IgnitedLocationActivity
public class IgnitedLocationSampleActivity extends MapActivity {
// MUST BE OVERRIDDEN OR IGNITION LOCATION WON'T WORK!
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
...
}
// MUST BE OVERRIDDEN OR IGNITION LOCATION WON'T WORK!