Skip to content

Instantly share code, notes, and snippets.

@kritzcreek
kritzcreek / random-numbers.md
Last active May 24, 2021 18:36
Collections of random numbers in PureScript

Generating collections of random numbers in PureScript

A problem that I've seen beginners run into in Haskell or PureScript a couple of times now is how to generate a List of random numbers. It's a common requirement for little games (which make for great first projects) to generate these, and it definitely seems to be a stumbling block.

Why are random numbers hard?

Randomness is considered a side effect in purely functional languages, which means that to generate them you usually need access to Eff/IO, which in turn means we need to deal with Monads. And while generating a single random number is usually pretty easy with do-notation, the typical intuition beginners have built when going from single values to a collection is to use map, but that fails.

Type-Directed-Search to the rescue

compiler-check: match-exact
resolver: ghc-8.0.1.20161117
setup-info:
ghc:
linux64:
8.0.1.20161117:
url: http://downloads.haskell.org/~ghc/8.0.2-rc1/ghc-8.0.1.20161117-x86_64-deb8-linux.tar.xz
content-length: 112047972
sha1: 6a6e4c9c53c71cc84b6966a9f61948542fd2f15a
macosx:
@rbranson
rbranson / leaving-hound.md
Created April 25, 2016 17:58
Stepping Down

Hey friends,

I wanted to let you know what's up with myself and Hound. I have left the company. There were fundamental conflicts among the founding team that were not reconcilable in any timeframe that would have made sense for an early-stage company.

Though it has certainly been a painful process, I still think the world of my co-founders, Charity and Christine. These are two immensely capable, hard-working, and genuinely caring people. I give my highest recommendation to anyone who would consider working with them in the future.

As for myself, I'll be spending the next few months spending time with friends and family as well as working on some side projects.

~ Rick

@alandipert
alandipert / ec2query.boot
Last active July 31, 2018 16:33
Example of querying AWS infrastructure with Amazonica and Datomic, in Clojure with Boot-clj
#!/usr/bin/env boot
;; or `BOOT_FILE=ec2query.boot boot repl' for interactive use
(set-env! :dependencies '[[amazonica "0.3.23"]
[com.datomic/datomic-free "0.9.5344"]])
(require '[amazonica.aws.ec2 :as ec2]
'[amazonica.core :refer [defcredential]]
'[boot.cli :refer [defclifn]]
'[boot.util :refer [info]]
@kofno
kofno / Main.purs
Last active October 7, 2015 19:03
module Main where
import Prelude
import Data.JSON
import Data.JSON.S3
import Node.FS.Async
import Node.Encoding
import Data.Either
import Control.Monad.Eff.Console
@bostonou
bostonou / cljs-line-reader.cljs
Last active August 29, 2015 14:21
Line by line reader in cljs
(ns cljs-line-reader.core
(:refer-clojure :exclude [flush])
(:require clojure.string
[cljs.core.async :refer [>!]])
(:require-macros [cljs.core.async.macros :refer [go]]))
(def fs (js/require "fs"))
(def stream (js/require "stream"))
(def ^:const eol (.-EOL (js/require "os"))) ;;eg "\n" or "\r\n"
@chrismdp
chrismdp / s3.sh
Last active September 13, 2024 12:53
Uploading to S3 in 18 lines of Shell (used to upload builds for http://soltrader.net)
# You don't need Fog in Ruby or some other library to upload to S3 -- shell works perfectly fine
# This is how I upload my new Sol Trader builds (http://soltrader.net)
# Based on a modified script from here: http://tmont.com/blargh/2014/1/uploading-to-s3-in-bash
S3KEY="my aws key"
S3SECRET="my aws secret" # pass these in
function putS3
{
path=$1