# 49 methods for the price of one
# via @sferik
module Enumerable
# block & yield syntax
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defpackage #:cl-game-random | |
(:use #:cl) | |
(:export #:random-whole #:random-range | |
#:random-digit #:random-alpha | |
#:random-array-subscripts | |
#:random-char #:random-svref | |
#:random-nth #:random-elt | |
#:random-aref | |
#:sample | |
#:bias |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; Inspired by https://aphyr.com/posts/340-acing-the-technical-interview | |
(defun conz (head tail) | |
(lambda (_) (if _ head tail))) | |
(let ((subject (conz 1 (conz 2 nil)))) | |
(assert (= 1 (funcall subject t))) | |
(assert (= 2 (funcall (funcall subject nil) t)))) | |
(defun mth (lizt mth) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Exercise for implementing multi-dimesional arrays in Ruby | |
# TODO: | |
# Level 0: Implement `row_major_index` and `to_a`. | |
# Level 1: How could tests be improved? | |
# Level 2: How could the interface of ArrayN be extended? Made more idiomatic? | |
# Multi-dimensional array | |
class ArrayN |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CL-USER> | |
(defun 🔪🍳 (ingredients) | |
(case ingredients | |
(🌾 '🍚) | |
(🌽 '🍿) | |
(🐔 '🍗) | |
(🐄 '🍔) | |
(t '🍲))) | |
(defun 🗢🌱 (thing) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; Per https://twitter.com/wobher/status/726442806353399808 what I'm | |
;; trying to say, all too succinctly, is that structurally an | |
;; expression like "foo |> bar |> baz |> qux" or even | |
;; "foo.bar.baz.qux" is commonly considered syntax for a bunch of | |
;; nested calls: "qux(baz(bar(foo)))". However, in Lisp or any other | |
;; non-infix language, we can see that this need not be the case. | |
;; Lets define a `pipe' function; we'd like the following assertions | |
;; about it to be true: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Code.require_file "test_helper.exs", __DIR__ | |
defmodule DecompositionTest do | |
use ExUnit.Case, async: true | |
# "015D;0074;0302;;;" in Decomposition.txt | |
# "0073;0302;015D;" in Composition.txt | |
test "String.equivalent? (LATIN SMALL LETTER S WITH CIRCUMFLEX)" do | |
assert String.equivalent?("\u015D", "\u0073\u0302") # fails, but correct | |
assert String.equivalent?("\u015D", "\u0074\u0302") # passes, but incorrect |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Stream of consciousness development. Copy/Paste into pry or irb. | |
require 'stringio' | |
def stream_print(stream, object) | |
stream << object.to_str if object.respond_to?(:to_str) | |
stream | |
end | |
io = StringIO.new |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defpackage #:handy-math | |
(:use #:cl) | |
(:export #:onep #:twop | |
#:one-over #:1/ #:halve #:/2 #:integer-factor-p #:factorer | |
#:two-fold #:2* #:multiplier | |
#:^ #:2^ #:^2 | |
#:v*) | |
(:documentation "Handy Math | |
Simple, often used arithmatic operations.")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(require 'json) | |
(require 'url) | |
(require 'url-http) | |
;;; http utilities | |
(defun http-utils-response-json (url) | |
"Retrieve url and parse json response." | |
(with-current-buffer (url-retrieve-synchronously url t) |