Skip to content

Instantly share code, notes, and snippets.

@kolja
kolja / fizzbuzz.js
Created January 20, 2023 11:57
JavaScript FizzBuzz
// first naive, straight-forward solution:
function divides(a,b) {
return a % b === 0;
}
for (i=1; i<20; i++) {
if (divides(i,3) && divides(i,5)) {
console.log("fizzbuzz");
} else if (divides(i,3)) {
@kolja
kolja / bookmark
Created June 28, 2020 08:36
babashka bookmark plugin for nnn
#!/usr/bin/env bb
; kolja (@01k) 2020
;
; usage:
;
; create a directory where you would like to keep your bookmarks.
; create an env variable NNN_BMDIR with the path to that directory (e.g. "~/.config/nnn/bookmarks")
; save this file in ~/.config/nnn/plugins as "bookmark" (for example)
;
@kolja
kolja / hack.css
Created April 8, 2020 11:12
aligning SVG bullet-image to <ul> list entries.
/* this is not the solution you are looking for. Move along */
ul {
list-style-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='30' height='40' viewBox='-1 -1 2 2'><circle transform='translate(0,-1.7)' r='1' /><circle transform='translate(0,0.95)' r='1' /></svg>");
line-height: 0.6rem;
}
@kolja
kolja / sub.cljs
Created January 25, 2020 14:33
Subtitle Editor
#!/usr/bin/env bash
"exec" "plk" "-Sdeps" "{:deps {org.clojure/tools.cli {:mvn/version \"0.4.2\"}}}" "-Ksf" "$0" "$@"
(ns subtitles.core
(:require
[planck.http :as http]
[planck.core :as core]
[clojure.tools.cli :refer [parse-opts]]
[clojure.string :as s]))
(def help "
@kolja
kolja / split.js
Created February 8, 2019 13:44
split Arrays into chunks with Javascript
const split = (arr, fn) => arr.reduce(([first, ...rest],el) =>
fn(el)
? first.length ? [[], first, ...rest] : [[], ...rest]
: first.length ? [[...first, el], ...rest] : [[el], ...rest]
, [[]]).reverse()
const a = [...Array(12).keys()]
split(a, x => !(x%5))
// [ [ 1, 2, 3, 4 ], [ 6, 7, 8, 9 ], [ 11 ] ]
@kolja
kolja / fashionworld.jpg
Last active February 7, 2019 13:49
Kolja's Fashion World
fashionworld.jpg
@kolja
kolja / primes.clj
Created November 9, 2017 18:21
calculate prime numbers and prime factors with clojure
(ns primes.core)
(defn- primes
"returns a lazy list of prime numbers via the sieve of eratosthenes"
([]
(primes (iterate inc 2)))
([[head & tail]]
(cons head
(lazy-seq (primes (remove #(and (not= % head)
(zero? (mod % head))) tail))))))
@kolja
kolja / balanced.cljs
Last active September 20, 2017 14:18
find out if a string with parens is balanced
#!/usr/local/bin/lumo
(ns balanced.core
(:require [lumo.core :refer [*command-line-args*]]
[clojure.string :refer [join]]))
(defn is-pair? [ch1 ch2]
(let [pairs {"(" ")"
"[" "]"
"{" "}"}]
(= (get pairs ch1) ch2)))
@kolja
kolja / sphere.cljs
Last active May 22, 2017 11:08
create a sphere from cubes
#!/usr/local/bin/lumo
(ns sphere.core
(:require [lumo.core :refer [*command-line-args*]]
[clojure.string :refer [join]]
[cljs.reader :refer [read-string]]))
(defn sqr [n] (* n n))
(defn sqrt [n] (.sqrt js/Math n))
(defn cbrt [n] (.cbrt js/Math n))
(defn abs [n] (.abs js/Math n))
// ==UserScript==
// @name aws-login
// @source
// @downloadURL
// @version 0.1.0
// @description login to AWS
// @author kolja
// @include *://signin.aws.amazon.com/saml
// @run-at document-idle
// @grant none