Skip to content

Instantly share code, notes, and snippets.

View joshrotenberg's full-sized avatar
🐢

Josh Rotenberg joshrotenberg

🐢
View GitHub Profile
@joshrotenberg
joshrotenberg / sequenceUntil.hs
Created January 15, 2014 20:31
From http://hackage.haskell.org/package/hylolib-1.4.0/docs/src/HyLo-Util.html, modified slightly to not return the final item in the list
sequenceUntil :: Monad m => (a -> Bool) -> [m a] -> m [a]
sequenceUntil _ [] = return []
sequenceUntil p (m:ms) = do a <- m
if p a
then return $ init [a]
else do as <- sequenceUntil p ms
return (a:as)
@joshrotenberg
joshrotenberg / webmachine.hrl
Last active December 30, 2015 13:09
macro expand result when include-lib'ing in LFE
> (macroexpand '(include-lib "webmachine/include/webmachine.hrl"))
(progn
(defrecord wm_reqdata
method
scheme
version
peer
sock
wm_state
disp_path
-module(function_options).
-export([my_fn/1, my_fn/2]).
-include_lib("eunit/include/eunit.hrl").
%% we'll populate a record with all of our interesting pieces. this also allows the specification of
%% defaults for things the user may not provide. required_arg will hold our required param, so we'll
%% leave them undefined. anything that starts with opt, however may or may not be supplied
(defproject builder-post "0.1.0")
import Data.Aeson
@joshrotenberg
joshrotenberg / .gitignore
Last active December 17, 2015 20:18
Gists for a blog post about Haskell, http-streams and Aeson: http://joshrotenberg.com/haskell/2013/05/28/http-streams-and-aeson/
.hsenv/
hsenv.log
*.hi
*.o
@joshrotenberg
joshrotenberg / gist:5518496
Created May 4, 2013 19:36
tl;dr searchBatch call
Joshs-MacBook-Air:~ josh$ curl https://api.tldr.io/tldrs/s":["http://www.taigeair.com/why-gmail-2013-sucks-terribad-user-experience.html"]}' -v
* About to connect() to api.tldr.io port 443 (#0)
* Trying 178.79.181.8...
* connected
* Connected to api.tldr.io (178.79.181.8) port 443 (#0)
* SSLv3, TLS handshake, Client hello (1):
* SSLv3, TLS handshake, Server hello (2):
* SSLv3, TLS handshake, CERT (11):
* SSLv3, TLS handshake, Server key exchange (12):
* SSLv3, TLS handshake, Server finished (14):
fizzBuzz :: (Integral a, Show a) => a -> String
fizzBuzz n
| n `mod` 3 == 0 && n `mod` 5 == 0 = "FizzBuzz"
| n `mod` 3 == 0 = "Fizz"
| n `mod` 5 == 0 = "Buzz"
| otherwise = show n
-- [fizzBuzz x | x <- [1..100]]
doubleMe x = x + x
@joshrotenberg
joshrotenberg / korma_h2_raw.clj
Created November 20, 2012 02:17
see if raw/exec-raw works with korma and h2
(use 'korma.core 'korma.db)
(defdb mydb {:classname "org.hd.Driver" :protocol "file" :subprotocol "h2" :subname "./tmp/mydb"})