Skip to content

Instantly share code, notes, and snippets.

View tatut's full-sized avatar

Tatu Tarvainen tatut

View GitHub Profile
@tatut
tatut / sort-natural.clj
Created January 27, 2022 06:11
A naive natural string sort
(defn sort-natural [names]
(sort-by
(fn [name]
(mapv (fn [s]
(if (every? #(Character/isDigit %) s)
(Long/parseLong s)
s))
(map second (re-seq #"(\d+|[^\d]+)" name))))
names))
;; (sort-natural ["mun dokkari 13.doc" "mun dokkari 2.doc"])
(ns day20
(:require [clojure.java.io :as io]))
(def input (-> "day20.txt" io/reader line-seq))
(def enhance-alg (vec (first input)))
(def initial-img
(into #{}
(mapcat identity)
(map-indexed
@tatut
tatut / aoc2021_day1.smalltalk
Created December 1, 2021 15:27
AoC2021, day1 using SmallTalk (using blocks, instead of OO)
testArray := #(199 200 208 210 200 207 240 269 260 263).
"day1 part 1"
part1 := [ :input |
| len prev incr |
incr := 0.
prev := input first.
len := input size.
2 to: len do: [ :i |
(prev < (input at: i)) ifTrue: [ incr := (incr + 1) ].
% clj -Sdeps "{:deps {juxt/crux-core {:mvn/version \"21.06-1.17.1-beta\"}}}"
Clojure 1.10.1
;; Require API and create noe
user=> (require '[crux.api :as crux])
nil
user=> (def crux (crux/start-node {})) ; start in-memory node
#'user/crux
;; Insert and query some data
@tatut
tatut / day2.sql
Last active December 2, 2020 14:20
adventofcode 2020, day 2 part 1
create table day2 (policy text, password text);
insert into day2 (policy,password)
values ('1-3 a','abcde'),
('1-3 b','cdefg'),
('2-9 c','ccccccccc');
CREATE OR REPLACE FUNCTION count_substring_matches(string TEXT, substr TEXT) RETURNS INTEGER AS $$
DECLARE
pos INTEGER;
c INTEGER;
Otetaan lista numeroita, jotka kuvaavat seinien korkeutta.
Jos kuva kaadetaan täyteen vettä, kuinka paljon jää seinien väliin.
esim. numerot: [2 5 1 2 3 4 7 3 6]
9 |
8 |
7 | #
6 | # #
5 | # # #
Write a short program that returns a sequence of numbers from 1 to 100.
- For each multiple of 3, return "Fizz" instead of the number.
- For each multiple of 5, return "Buzz" instead of the number.
- For numbers which are multiples of both 3 and 5, return "FizzBuzz" instead of the number.
@tatut
tatut / codebuild.cljs
Last active January 15, 2020 08:33
Planck cljs script to build codebuild project and follow the progress
#!/usr/bin/env planck
(require '[planck.shell :refer [sh]])
(require '[clojure.string :as str])
(require '[planck.core :as core])
(defn json-out [shell-result]
(-> shell-result
:out js/JSON.parse (js->clj :keywordize-keys true)))
@tatut
tatut / deadgrep-todo-fixme.el
Created March 1, 2019 18:12
TODO/FIXME search in project (for deadgrep)
(defun deadgrep-todo-fixme-buffers ()
(let ((buf (get-buffer-create "*deadgrep-todo-fixme-buffers*")))
(switch-to-buffer buf)
(setq deadgrep--search-type 'regexp)
(list buf)))
(defun deadgrep-todo-fixme ()
(interactive)
(advice-add 'deadgrep--buffers :override #'deadgrep-todo-fixme-buffers)
(deadgrep "(TODO)|(FIXME)")
@tatut
tatut / ec2.clj
Created April 20, 2018 18:32
Automatically generated clojure.spec definitions from AWS CloudFormation JSON spec
(ns aws.ec2
"AUTOGENERATED clojure.spec definitions"
(:require [clojure.spec.alpha]))
(clojure.spec.alpha/def
:aws.ec2/launch-template
(clojure.spec.alpha/keys
:req
[]
:opt