Skip to content

Instantly share code, notes, and snippets.

View jsmesami's full-sized avatar

Ondřej Nejedlý jsmesami

  • Prague
View GitHub Profile
#!/usr/bin/env bash
LOCAL_BIN_DIR=~/.local/bin
BABASHKA_INSTALL=install
KONDO_INSTALL=install-clj-kondo
LSP_ARCHIVE=clojure-lsp-native-linux-amd64.zip
LSP_BIN=clojure-lsp
wget https://raw.githubusercontent.com/babashka/babashka/master/${BABASHKA_INSTALL}\
&& chmod +x ${BABASHKA_INSTALL}\

Run-length encode a sequence

Run-length encoding is a way to represent a sequence in a more compact form. Instead of saying :p :p :p, you say “3 :ps”. Write a function that takes a sequence and returns that sequence with run-length encoding.

For example:

(rle [:a :a :a :b :c :d :d :d :d])
;=> ([3 :a] [1 :b] [1 :c] [4 :d])

Keybase proof

I hereby claim:

  • I am jsmesami on github.
  • I am jsmesami (https://keybase.io/jsmesami) on keybase.
  • I have a public key ASDf5JhKnt4_50WifeQ3SYoW27auqq114NuWFx3EMOxlUQo

To claim this, I am signing this object:

@jsmesami
jsmesami / json_xhr.cljs
Last active March 4, 2018 18:23
Useful Re-frame event handler for doing JSON XHR
(ns net.json-xhr
(:require
[ajax.core :as ajax]
[day8.re-frame.http-fx]
[re-frame.core :refer [reg-event-fx trim-v]]
(defn default-success-fx
[db response]
{:db db}) ;; You can define some useful default effects here
@jsmesami
jsmesami / animate.cljs
Created March 4, 2018 11:38
A simple ClojureScript function for linear animation
;; Function takes two numeric values, `from` and `to` you wish to animate.
;; First argument is a callback function, which is called each keyframe and the current value is passed to it.
;; There are also optional keyword arguments you can use to alter duration and number of keyframes of the animation.
;; The `then` callback can be used after the animation finishes for cleanup etc.
(defn animate
([callback from to & {:keys [duration keyframes then]
:or {duration 1000
keyframes 30}}]
(let [distance (js/Math.abs (- to from))
@jsmesami
jsmesami / jquery.slides.js
Created January 21, 2012 17:52
Very lightweight configurable jQuery slider plugin
$.fn.slides = function(options) {
var opts = $.extend({}, $.fn.slides.defaults, options);
return this.each(function() {
var $container = $(this);
function switcher() {
$container.find('img').first().css(opts.CSShidden).detach()
.appendTo($container).animate(opts.CSSvisible, opts.duration, opts.easing);
}
setInterval(switcher, opts.interval);
@jsmesami
jsmesami / watcher.py
Created November 13, 2011 17:00
Watch for Coffeescript or Less files in your project tree and compile them on save.
#!/usr/bin/env python
import os, time
import optparse
import subprocess
def watch(watchpath, delay=1):
"""\
recursively iterates over files in a directory tree and watches for the ones that have been changed
returns an infinite iterator object containing filenames of changed files