Skip to content

Instantly share code, notes, and snippets.

;;; Personal configuration -*- lexical-binding: t -*-
;; Save the contents of this file under ~/.emacs.d/init.el
;; Do not forget to use Emacs' built-in help system:
;; Use C-h C-h to get an overview of all help commands. All you
;; need to know about Emacs (what commands exist, what functions do,
;; what variables specify), the help system can provide.
;; Add the NonGNU ELPA package archive
(require 'package)
<h2>The Basics</h2>
<div class="basics">
<label>
<span>Character name: </span>
<input spellcheck="false" type="text" name="attr_character_name"/>
</label>
<label>
<span>Pronouns: </span>
<input spellcheck="false" type="text" name="attr_pronouns"/>

On NOT Using PostgreSQL Advisory Locks in Haskell

Recently two different administrative users of a Haskell app I maintain started a long-running background job at the same time. This resulted in some Bad Things happening which I would like to prevent in the future!

So I want a lock. This app runs on at least two servers at any given time, so it needs to be a distributed lock, and for Reasons (not relevant to this blogpost) I can't use our Redis cache. So the PostgreSQL database it is!

@emhoracek
emhoracek / adventday1.hs
Last active December 14, 2018 21:22
Advent of Code day 1
{-
After feeling like you've been falling for a few minutes, you look at the device's tiny screen.
"Error: Device must be calibrated before first use. Frequency drift detected. Cannot maintain
destination lock." Below the message, the device shows a sequence of changes in frequency
(your puzzle input). A value like +6 means the current frequency increases by 6; a value like
-3 means the current frequency decreases by 3.
For example, if the device displays frequency changes of +1, -2, +3, +1, then starting from
a frequency of zero, the following changes would occur:

Using PostgreSQL Advisory Locks in Haskell

Recently two different administrative users of a Haskell app I maintain started a long-running background job at the same time. This resulted in some Bad Things happening which I would like to prevent in the future!

So I want a lock. This app runs on at least two servers at any given time, so it needs to be a distributed lock, and for Reasons (not relevant to this blogpost) I can't use our Redis cache. So the PostgreSQL database it is!

Magazine
create_issue -> Draft
Subscriber
Subscribed
cancel -> Lapsed
renew -> Subscribed
Lapsed
renew -> Subscribed
Subscriber?
subscribed -> LastIssue?
@emhoracek
emhoracek / cart_app.rb
Created October 21, 2017 16:35
discounts
class Order < Struct.new(:line_items, :discount_name)
def discount
DiscountDatabase.find_by_name(discount_name)
end
def discounted_line_item_prices
line_items.map do |li|
li.discounted_total(discount)
end
end
@emhoracek
emhoracek / setdata.json
Created August 18, 2017 13:29
Magical Girl Pretty Sammy set data (formatted JSON)
{
"objs": [
{
"cells": [
{
"palette": 0,
"offset": {
"x": 0,
"y": 0
},
@emhoracek
emhoracek / percept.hs
Created May 8, 2017 20:32
perceptrons
module Perceptron where
import Prelude hiding (and)
data Perceptron =
Perceptron { inputs :: [Input]
, bias :: Int } deriving (Eq, Show)
data Input = Input { value :: Bool
, weight :: Int } deriving (Eq, Show)

Keybase proof

I hereby claim:

  • I am emhoracek on github.
  • I am horrorcheck (https://keybase.io/horrorcheck) on keybase.
  • I have a public key whose fingerprint is 8453 9205 8D53 6218 B02B C890 946A 8DC3 D3D7 A323

To claim this, I am signing this object: