Skip to content

Instantly share code, notes, and snippets.

View lispyclouds's full-sized avatar
💤
On a mission to civilise. One day.

Rahuλ Dé lispyclouds

💤
On a mission to civilise. One day.
View GitHub Profile
@lispyclouds
lispyclouds / monads.clj
Last active May 17, 2020 02:37
Monads, simple made easier
; A simple demo of monadic composition of side effects
; Program to take 3 nubers as input and print their sum.
(defn read-and-add!
[prev]
(print "Enter a number: ")
(+ prev (do (flush)
(Integer/parseInt (read-line)))))
(defn bind
@lispyclouds
lispyclouds / monads.kt
Last active May 7, 2019 18:46
Monads: Simple made Easy.
import java.util.Scanner
sealed class Maybe<out T>
data class Just<T>(val value: T) : Maybe<T>()
object None : Maybe<Nothing>() {
override fun toString() = "None"
}
@lispyclouds
lispyclouds / monads.py
Last active April 19, 2020 19:33
Monads: Simple made Easy.
from functools import reduce
class Maybe(object):
def __str__(self):
return "Maybe"
class Something(Maybe):
def __init__(self, value):
@lispyclouds
lispyclouds / repl.clj
Created November 7, 2018 10:09
REPL in REPL
; to define the loop macro
(defmacro loop_ [& body] `(while true ~@body))
; Create the REPL!
(-> (read) (eval) (println) (loop_))
@lispyclouds
lispyclouds / fib.py
Created October 15, 2018 11:47
Computing `limit` digits of the nth Fibonacci number in log(n)
#!/usr/bin/env python3
import sys
limit = 6
mod = 10 ** limit
def mat_mul(m1, m2):
@lispyclouds
lispyclouds / shell.clj
Last active July 24, 2018 09:37
Clojure function to tokenize shell commands.
;; Clojure translation of https://sourceforge.net/p/drjava/git_repo/ci/master/tree/drjava/src/edu/rice/cs/util/ArgumentTokenizer.java
;; Input: "sh -c \"while sleep 1; do echo \\\"${RANDOM}\\\"; done\""
;; Output: ["sh", "-c", "while sleep 1; do echo \"${RANDOM}\"; done"]
(defn shell-tokenize!
[^String command]
(let [[escaped?
current-arg
args
state] (loop [cmd command
@lispyclouds
lispyclouds / keybase.md
Created May 6, 2017 14:00
Keybase Proof

Keybase proof

I hereby claim:

  • I am lispyclouds on github.
  • I am rahulde (https://keybase.io/rahulde) on keybase.
  • I have a public key whose fingerprint is AC83 35A1 FC06 3D39 BB71 DBD7 D695 9EE4 51EA 8C21

To claim this, I am signing this object:

@lispyclouds
lispyclouds / stocks.clj
Last active September 5, 2016 16:27
Code to fetch the highest stock
(ns stocks.core
(:gen-class)
(:require [clj-http.client :as client])
(:require [cheshire.core :refer :all]))
(def url "http://dev.markitondemand.com/MODApis/Api/v2/Quote/json?symbol=%s")
(defn get-stock-value-of
[symbol]
(let [response (-> ((client/get (format url symbol)) :body)
@lispyclouds
lispyclouds / bikes.clj
Created August 25, 2016 14:53
The Bike Rental Code
(ns bikes.core
(:gen-class)
(:require [clj-time.core :as t]))
(defrecord Bike [model price id])
(defrecord Store [bikes currentRentals rentHistory])
(defrecord Rental [bikeId rentedOn returnedOn rent])
(defn find-rental-for-bike
[store bike]
@lispyclouds
lispyclouds / store.hs
Created August 25, 2016 04:20
Sattar_Fix
import Control.Monad.Trans.State
data Cycle = Cycle { brand :: String, id :: Int, price :: Int } deriving Show
data Store = Store { cycles :: [Cycle], rentals :: [Rental]} deriving Show
data Rental = Rental { cycle :: Cycle, rentedOn :: Int, returnedOn :: Maybe Int } deriving Show
cycles' :: [Cycle]
cycles' = [ Cycle "BSA" 1 10
, Cycle "BSA 2" 2 100
, Cycle "BSA 3" 3 200 ]