Skip to content

Instantly share code, notes, and snippets.

View shapr's full-sized avatar
🏃
VENTRE À TERRE

Shae Erisson shapr

🏃
VENTRE À TERRE
View GitHub Profile
"""
Pablo buys popsicles for his friends.
The store sells single popsicles for$1 each, 3-popsicle boxes for$2, and 5-popsicle boxes for$3.
What is the greatest number of popsicles that Pablo can buy with$8?
"""
from z3 import *
box1pop, box3pop, box5pop =Ints('box1pop box3pop box5pop')
pop_total=Int('pop_total')
cost_total=Int('cost_total')
@shapr
shapr / haskell-stuff.el
Created May 30, 2019 20:04
parts of my emacs config specific to haskell, with use-package prelude
;; Added by Package.el. This must come before configurations of
;; installed packages. Don't delete this line. If you don't want it,
;; just comment it out by adding a semicolon to the start of the line.
;; You may delete these explanatory comments.
(package-initialize)
;; make sure use-package is installed
(require 'package)
(add-to-list 'package-archives
'("melpa" . "https://melpa.org/packages/")
#+name: layout
#+RESULTS: layout-calc
| q | w | e | r | t | y | u | i | o | p |
| | a | s | d | f | g | h | j | k | |
| | z | x | c | v | b | n | m | | |
#+name: layout-calc
#+BEGIN_SRC emacs-lisp :var table=layout
(message table)
#+END_SRC
@shapr
shapr / Day3.hs
Created December 3, 2018 19:10
parser for day3 2018
{-# LANGUAGE OverloadedStrings #-}
module Main where
import Data.Text (Text)
import qualified Data.Text as T
import qualified Data.Text.IO as TIO
import Data.Attoparsec.Text
main :: IO ()
main = do input <- TIO.readFile "input3.txt"
[alias]
# Checkout a pull request branch on an upstream project. It
# handles PRs that get rebased as well.
#
# git pr 3
pr = "!f() { git checkout master; git branch -D pr/$1 || true; git fetch origin refs/pull/$1/head:pr/$1 && git checkout pr/$1; }; f"
dpr = "!f() { git checkout develop; git branch -D pr/$1 || true; git fetch upstream refs/pull/$1/head:pr/$1 && git checkout pr/$1; }; f"
pur = "!f() { git checkout master; git branch -D pr/$1 || true; git fetch upstream refs/pull/$1/head:pr/$1 && git checkout pr/$1; }; f"
@shapr
shapr / try.sh
Last active January 16, 2020 19:07
wrapper for long running commands
# for long running commands
function try () {
tally $* && fin || die; # cargo install tally, replacement for time
}
function play_sound () {
aplay -N -q $HOME/.bin/$1.au
}
function fin () {
@shapr
shapr / Day16a.hs
Created October 11, 2018 17:54
advent of code 2017 , solution for part 1 of day 16
{-# LANGUAGE OverloadedStrings #-}
module Main where
import Control.Applicative
import Data.Attoparsec.Text hiding (take)
import Data.Maybe
import Data.Monoid
import qualified Data.Sequence as S
import qualified Data.Text.IO as TIO
main :: IO ()
@shapr
shapr / tm.org
Last active October 4, 2018 17:05
transactional memory lightning talk
  • dining philosophers problem - many threads accessing the same memory lead to problems like deadlock / livelock
  • locks? hard to think about, don’t compose, priority inversion
    • thread-safe hash table doesn’t mean you can atomically move an entry from one hash table to another
  • transactions in memory! ACI from ACID (memory isn’t durable)
  • transactional memory does compose!
  • but wait, rolling back a transaction can get really expensive, how is this a benefit?
    • only allowed to perform operations that can be rolled back / undone
    • Haskell already does this in the type system, non-issue there
  • optimistic concurrency
    • no work completed while waiting for a lock
@shapr
shapr / the error
Created September 8, 2018 22:24
shapr nixos-rebuild switch
[root@nixos:~]# nixos-rebuild switch
building Nix...
building the system configuration...
Warning: do not know how to make this configuration bootable; please enable a boot loader.
activating the configuration...
setting up /etc...
setting up tmpfiles
# Edit this configuration file to define what should be installed on
# your system. Help is available in the configuration.nix(5) man page
# and in the NixOS manual (accessible by running ‘nixos-help’).
{ config, pkgs, ... }:
{
imports =
[ # Include the results of the hardware scan.
./hardware-configuration.nix