Skip to content

Instantly share code, notes, and snippets.

View ahammel's full-sized avatar
😎
👉👉

Alex Hammel ahammel

😎
👉👉
View GitHub Profile
@ahammel
ahammel / a_semigroup.alp
Last active April 15, 2017 03:46
Alpaca type classes (sort of)
module semigroup
export_type semigroup
export concat
{- Semigroup: anything with an associative operation
Instead of a type class, we define a record type which specifies the
necessary fields.
client = boto3.client("autoscaling")
asg_paginator = client.paginator("describe_auto_scaling_groups")
used_launch_configs = set([
asg["LaunchConfigurationName"]
for page in asg_paginator.paginate()
for asg in page["AutoScalingGroups"]])
# what if somebody makes a buch of AGS at this point in the execution?
launch_config_paginator = client.paginator('describe_launch_configurations')
{-# OPTIONS_GHC -fno-warn-missing-signatures #-}
module Main where
import Control.Applicative
import Text.Printf
import Prelude hiding (and, or, flip)
True `nand` True = False
True `nand` False = True
False `nand` True = True
(defn divisible-by? [x y]
(zero? (mod x y)))
(defn relative-prime? [coll x]
(not-any? (partial divisible-by? x)
(take-while (partial not= x) coll)))
(defn generate-primes [n]
(let [src (range 3 n 2)
prime? (partial relative-prime? src)]
class Nothing(object):
"""Represents a failed computation.
"""
class TryChain(object):
"""Apply a series of functions to a value, keeping only the first one that
fails to throw a user-specified exception.
The foo system consists of a master process, a supervisor, and some worker
processes. The worker processes do a computationally expensive thing and send
the results to the master process, which then maybe asks the supervisor to
spawn more workers, depending on the result:
################ asks for workers... ####################
# foo_master # ------------------------> # foo_supervisor # --\
################ #################### |
^ | spawns....
@ahammel
ahammel / dire-multi-handler.clj
Last active August 29, 2015 13:56
Macro for a dire.clj handler which catches multiple exception types
(ns multi-handler
(:require [clojure.string :as string]
[dire.core :refer [with-handler!]]))
(defmacro with-multi-handler!
"Make handlers for every exception in a collection"
[handled exceptions body]
(cons 'do
(map
#(list 'with-handler! handled % body)
#include <prime_generator.h>
#include <iostream>
unsigned long PrimeGenerator::next()
{
unsigned long factor;
unsigned long next_composite;
if (next_candidate >= max_value) {
throw "Integer overfow!\n";