Skip to content

Instantly share code, notes, and snippets.

@clementi
clementi / stuff.sml
Last active Mar 8, 2019
Standard ML Stuff
View stuff.sml
#!/usr/bin/env poly --script
fun rev xs =
let
fun revAcc acc xs =
case xs of
[] => acc
| (y :: ys) => revAcc (y :: acc) ys
in
revAcc [] xs
View stuff.idr
rev : List a -> List a
rev xs = revAcc [] xs where
revAcc : List a -> List a -> List a
revAcc acc [] = acc
revAcc acc (x :: xs) = revAcc (x :: acc) xs
even : Nat -> Bool
even Z = True
even (S k) = odd k where
odd Z = False
View pointfree-cli.rb
#!/usr/bin/env ruby
require 'json'
require 'net/http'
def success?(status_code)
status_code[0] == '2'
end
begin
@clementi
clementi / fizzbuzzhaskell.hs
Last active Feb 26, 2019
FizzBuzz in Haskell (one way to do it)
View fizzbuzzhaskell.hs
module Main where
import Control.Monad (forM_)
import System.Environment (getArgs)
printFizzBuzz :: Integral a => a -> IO ()
printFizzBuzz n
| n `mod` 3 == 0 && n `mod` 5 == 0 = putStrLn "FizzBuzz"
| n `mod` 3 == 0 = putStrLn "Fizz"
| n `mod` 5 == 0 = putStrLn "Buzz"
@clementi
clementi / Checkout.hs
Created Jan 8, 2019
State Machine with ADTs
View Checkout.hs
{-# LANGUAGE OverloadedStrings #-}
module Checkout ( Card(..)
, CartItem(..)
, calculatePrice
) where
import Data.List.NonEmpty
data Card = Card String String deriving (Eq, Show)
data CartItem = CartItem String Double deriving (Eq, Show)
@clementi
clementi / EmptyList.java
Last active Nov 2, 2018
Recursive Linked List in Java. Adapted from the Haskell solution at https://exercism.io/my/solutions/63511eb9ae984d599e05bc9c635c405f
View EmptyList.java
package com.tenfactorial.collections;
import java.util.ArrayList;
import java.util.List;
public class EmptyList<T> extends LinkedList<T> {
@Override
public T datum() {
return null;
@clementi
clementi / redir-chain.py
Last active Jul 9, 2018
Print out the redirection chain of a URL. Doesn't deal with loops.
View redir-chain.py
import requests
import sys
from colorama import init, Fore, Style
def main():
init() # colorama
if len(sys.argv) < 2:
@clementi
clementi / bogosort.py
Created Jul 6, 2018
Bogosort in Python
View bogosort.py
import random
def is_sorted(data):
for i in range(len(data) - 1):
if data[i] > data[i+1]:
return False
return True
@clementi
clementi / lspath.c
Created Jun 27, 2018
List the contents of the PATH environment variable
View lspath.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(void) {
char* path = getenv("PATH");
#ifdef _WIN32
char* sep = ";";
#else
@clementi
clementi / lspath.d
Last active Jun 26, 2018
List the contents of the PATH environment variable
View lspath.d
module main;
import std.stdio;
import std.algorithm.iteration : each, splitter;
import std.path : pathSeparator;
import std.process : environment;
int main(string[] args) {
environment.get("PATH")
.splitter(pathSeparator)
You can’t perform that action at this time.