Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View SneakyPeet's full-sized avatar
💭
Doing the Clojures

Pieter Koornhof SneakyPeet

💭
Doing the Clojures
View GitHub Profile
@SneakyPeet
SneakyPeet / parse.clj
Created April 3, 2019 08:16
Parse fnb and ynab exoport csv
(defn parse-fnb [path]
(let [fnb-csv-rows
(as-> (slurp (clojure.java.io/file path)) x
(clojure.string/split x #"\n")
(drop 6 x)
(map #(clojure.string/split % #", ") x))
header (->> fnb-csv-rows first (map keyword))
rows (->> fnb-csv-rows
rest
(map #(zipmap header %))
@SneakyPeet
SneakyPeet / date-select.cljs
Last active April 4, 2019 03:27
Clojurescript Date Selector
(ns date-select.core
(:require [rum.core :as rum]
[cljs-time.core :as time]))
(defn initial-date
([] (let [selected (time/now)]
{:year (time/year selected)
:month (time/month selected)
:day (time/day selected)}))
([year] (initial-date year 1 1))
@SneakyPeet
SneakyPeet / list_of_digits.clj
Last active March 26, 2019 14:54
List Of Digits
;;; https://purelyfunctional.tv/issues/purelyfunctional-tv-newsletter-319-tip-shebang-scripting-with-the-clojure-cli/?__s=qn1vfepzj2qsgce6ughs
(defn number-of-digits
"Calculates the number of digits in an integer"
[n]
(int (Math/ceil (Math/log10 (inc n)))))
(defn get-nth-digit
"Gets the nth digit (zero based) from integer x"
@SneakyPeet
SneakyPeet / rld.clj
Last active March 11, 2019 19:10
run length encode decode clojure puzzle from purelyfunctional.tv newsletter
(defn rle
([coll]
(rle [] coll))
([result coll]
(if (empty? coll)
coll
(lazy-seq
(let [current (first coll)
n (count (take-while #(= % current) coll))]
(cons [n current] (rle result (drop n coll))))))))
@SneakyPeet
SneakyPeet / rsa-id-number.cljc
Last active August 8, 2017 11:14
South African Id Number Validator
;; Validates an RSA Identity Number
;; compatible With Clojure and Clojurescript
;; Requires clj-time for clojure and cljs-time for clojurescript
;; Based on the validator by Evan Knowles
;; http://knowles.co.za/generating-south-african-id-numbers/
(ns rsa-id-number
(:require
[clojure.string :as string]
@SneakyPeet
SneakyPeet / excelSheetsToJsonRows.js
Created May 10, 2017 09:20
Get all rows from all sheets in a excel doc as json array
// Get all rows from all sheets in a excel doc as json array
// Assumes sheets have header rows
const XLSX = require('xlsx');
const jsonfile = require('jsonfile');
const R = require('ramda');
const getWorkbook = () => XLSX.readFile('./data/test.xlsx');
const pickSheetsByName = (workbook) => R.pick(workbook.SheetNames, workbook.Sheets);