Skip to content

Instantly share code, notes, and snippets.

(defn map-every-nth [f coll n]
(map-indexed #(if (zero? (mod (inc %1) n)) (f %2) %2) coll))
(defn convert-to-number-seq [num-string]
(map #(Integer/parseInt %) (re-seq #"\d" num-string)))
(defn double-every-second-digit [coll]
(map-every-nth #(* 2 %) (reverse coll) 2))
; (deftest large-addition
; (is (= (wordy/evaluate "What is 123 plus 45678?") 45801)))
; (deftest addition-and-multiplication
; (is (= (wordy/evaluate "What is -3 plus 7 multiplied by -2?") -8)))
(ns wordy (:use clojure.string))
(defn remove-question-mark [query]
(clojure.string/join "" (drop-last query)))
; (deftest large-addition
; (is (= (wordy/evaluate "What is 123 plus 45678?") 45801)))
; (deftest addition-and-multiplication
; (is (= (wordy/evaluate "What is -3 plus 7 multiplied by -2?") -8)))
(ns wordy (:use clojure.string))
(defn remove-question-mark [query]
(clojure.string/join "" (drop-last query)))
(require '[clojure.string :as str])
(defn remove-punc [s]
(clojure.string/replace s #"[.!?\\-]" ""))
(defn split-to-words [s]
(clojure.string/split s #" "))
(defn sort-by-alpha [coll]
(sort-by clojure.string/lower-case coll)) ; call lower-case in the comparator (x y)
class School
attr_accessor :classes
def initialize
@classes = 7.times.map do |i|
{
grade: i + 1,
students: []
}
end
(def school (reduce (fn [acc g] (assoc acc g { :grade g :students [] })) {} (range 1 8)))
(defn add-student [name grade school]
(assoc-in
school [grade :students]
(vec (sort (conj (:students (get school grade)) name)))))
(defn add-students [school [name grade]]
(add-student name grade school))
BOX_MAP = [
[0, 1, 2, 9, 10, 11, 18, 19, 20],
[3, 4, 5, 12, 13, 14, 21, 22, 23],
[6, 7, 8, 15, 16, 17, 24, 25, 26],
[27, 28, 29, 36, 37, 38, 45, 46, 47],
[30, 31, 32, 39, 40, 41, 48, 49, 50],
[33, 34, 35, 42, 43, 44, 51, 52, 53],
[54, 55, 56, 63, 64, 65, 72, 73, 74],
crumbs := func(c *leaf.Compiler) {
c.TemplateFuncs["Breadcrumbs"] = func(d leaf.Document) template.HTML {
var links []string
var link string
var anchor string
crumbs := strings.Split(d.Anchor, string(os.PathSeparator))
for idx, _ := range crumbs {
if idx == 0 {
package main
import (
"fmt"
"log"
"sort"
"net/http"
"time"
"github.com/radovskyb/watcher"
"github.com/jarsbe/leaf"
@jackcallister
jackcallister / script.rb
Created July 29, 2019 10:14
Rudimentary site compiler
require 'erb'
require 'tilt'
paths = Dir.glob('content/**/*').select{ |e| File.file? e }
paths.each do |path|
content = Tilt.new(path)
layout = Tilt.new('layouts/index.erb')
output = layout.render { content.render }