Skip to content

Instantly share code, notes, and snippets.

View kapilreddy's full-sized avatar

Kapil Reddy kapilreddy

View GitHub Profile
@kapilreddy
kapilreddy / example.clj
Created October 21, 2013 15:04
core.match macro with fns.
;; Match with guard function
(match [{:a 2} {:b 3}]
[{:a (_ :guard even?)} _] 1)
;; Match-with-fn example for same
(match [{:a 2} {:b 3}]
[{:a even?} _] 1)
(defn divide-coll
"Divide collection of block heights into regions where water will be blocked.
ex.
[1 2 0 1 3 2 1 0 3] -> [[3 2 1 0 3] [2 0 1 3]]"
[c]
(let [regions (reduce (fn [coll i]
(cond
(seq coll) (let [[x & xs] coll
from (first x)
new-x (conj (vec x) i)]
@kapilreddy
kapilreddy / kafka-core-async.clj
Last active August 29, 2015 14:10
Core.async message consumer with safe shutdown
(ns core-async-kafka.core
(:require [clojure.core.async :refer [chan buffer go >!! <!! <! close! sliding-buffer]]))
(defn process-message
[msg status-chan]
(>!! status-chan :in-progress)
(Thread/sleep (rand-int 10000))
(println (format "Consumed %s message" msg))
(>!! status-chan :sucess))
@kapilreddy
kapilreddy / find-offsets.clj
Last active April 12, 2017 11:32
Kafka message offset finder
;; project.clj
;; [clj-time "0.6.0"]
;; [org.clojure/data.json "0.2.4"]
;; [clj-kafka "0.2.8-0.8.1.1"]
;; Utility to find offsets in a given Kafka topic for a given
;; cursor/point in time. The code assumes that each message has a
;; monotonically increasing number (ex. unix timestamp) associated with
;; it.
Kaioken
Initialize Kaioken
Message received -> Consume messages
Consume messages
Message received -> Consume messages
Enough messages received -> Bulk start
Bulk start
Data store - Success response -> Bulk success
Data store - Retriable error -> Bulk start
Kaioken
Initialize Kaioken
Message received -> Consume messages
Consume messages
Message received -> Consume messages
Enough messages received -> Bulk start
Bulk start
Bulk success -> Consume messages
Retriable error -> Bulk start
Non-recoverable error -> Exit
ABC
No previous messages
Open chat and Add message -> New Issue
New Issue
Agent sends message -> Issue in progress
User sends message -> New Issue
User deletes thread -> No previous messages
Issue in progress
Agent sends message -> Issue in progress
User sends message -> Issue in progress
@kapilreddy
kapilreddy / info.clj
Created November 18, 2018 04:55
Info middleware change to support protocol code navigation
(defn info
[{:keys [ns symbol class member] :as msg}]
(let [[ns symbol class member] (map u/as-sym [ns symbol class member])]
(if-let [cljs-env (cljs/grab-cljs-env msg)]
(info-cljs cljs-env symbol ns)
(let [var-info (cond (and ns symbol) (clj-info/info ns symbol)
(and class member) (clj-info/info-java class member)
:else (throw (Exception.
"Either \"symbol\", or (\"class\", \"member\") must be supplied")))
;; we have to use the resolved (real) namespace and name here
@kapilreddy
kapilreddy / shoot_a_short_2019.md
Last active January 21, 2019 10:55
Shoot a short workshop list of things/links/people
@kapilreddy
kapilreddy / emacs_text_movement.js
Last active August 15, 2021 18:57
Emulate Emacs text editing in browser
// ==UserScript==
(function () {
'use strict';
let nowPlayingClassName = 'now-playing-tracklist-row'
let buffer = [];
let bindings = [
{binding: ["control", "f"], action: moveForward},
{binding: ["control", "b"], action: moveForward}