Skip to content

Instantly share code, notes, and snippets.

View laserpants's full-sized avatar

Heikki Johannes Hildén laserpants

View GitHub Profile
@laserpants
laserpants / Main.hs
Created May 1, 2020 14:27
Recursion schemes
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE FlexibleInstances #-}
module Main where
import Prelude hiding (length, filter, succ, foldl, foldr, sum, head, reverse)
import qualified Prelude
-------------------------------------------------------------------------------
newtype Fix f = Fx { unFix :: f (Fix f) }
@laserpants
laserpants / systemd_check.sh
Created July 15, 2018 11:57
Check if system is using systemd
#!/bin/bash
ps -p 1 -o comm=
# see https://www.home-assistant.io/docs/autostart/systemd/
@laserpants
laserpants / Category.hs
Created February 1, 2018 10:14
Haskell category
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE UnicodeSyntax #-}
module Category where
class Category (c :: k -> k -> *) where
id :: c x x
(.) :: c y z -> c x y -> c x z
instance Category (->) where
@laserpants
laserpants / keymap.cson
Created November 20, 2017 21:16
Keymap binding to toggle IDE-Haskell output pane in Atom editor
'atom-workspace':
'ctrl-shift-0': 'ide-haskell:toggle-output'
module Main
import Prelude.Functor
total ap : Applicative f => f (a -> b) -> f a -> f b
ap = (<*>)
total maybeAdd1 : Num a => Maybe a -> Maybe a -> Maybe a
maybeAdd1 x y = do x' <- x
y' <- y
@laserpants
laserpants / Main.hs
Last active October 19, 2017 06:46
Haskell ternary operator.
module Main where
(.?.) :: Bool -> (a, a) -> a
(.?.) True = fst
(.?.) False = snd
infixl 3 .?.
(>:<) :: a -> b -> (a, b)
(>:<) = (,)
@laserpants
laserpants / WebSocketService.java
Last active January 20, 2016 09:44
WebSocket service class.
package org.farmradio.fessbox;
import android.app.Service;
import android.content.Intent;
import android.os.Binder;
import android.os.IBinder;
import android.support.annotation.Nullable;
import android.util.Log;
import de.tavendo.autobahn.WebSocketConnection;
@laserpants
laserpants / WebSocketMessageListener.java
Created January 20, 2016 09:32
WebSocketMessageListener interface.
package org.farmradio.fessbox;
public interface WebSocketMessageListener {
void onMessage(String message);
}
@laserpants
laserpants / list_view_item.xml
Last active January 20, 2016 09:30
ListView layout for FessBox channel list adapter items.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_weight="1"
@laserpants
laserpants / gist:9f3a77c1d24c0ca23cd3
Created August 20, 2015 22:05
React-bootstrap paging component for Griddle
const BootstrapPager = React.createClass({
getDefaultProps() {
return {
currentPage : 0,
maxPage : 0,
maxButtons : 10
}
},
handleSelect(event, selectedEvent) {
let page = selectedEvent.eventKey