Skip to content

Instantly share code, notes, and snippets.

View mourjo's full-sized avatar
👋

Mourjo Sen mourjo

👋
View GitHub Profile
@mourjo
mourjo / ec.sh
Created July 26, 2023 11:35
Run emacs from CLI on Mac
#!/bin/sh
/Applications/Emacs.app/Contents/MacOS/bin/emacsclient -n "$@"
@mourjo
mourjo / elixir_kubernetes_notes.org
Created March 3, 2022 10:51
Notes of basic definitions (getting started with Elixir and K8s)
@mourjo
mourjo / workerdemo.js
Last active February 9, 2022 11:20
Concurrent Node.js workers
import * as nodeWorker from 'worker_threads';
function sleep(ms) {
return new Promise((resolve) => {
setTimeout(resolve, ms);
});
}
async function doSomething(name) {
console.log(`${Date.now()}: Worker ${name} working ...`);
await sleep(Math.floor(10000));
@mourjo
mourjo / primes.clj
Created January 15, 2022 12:21
Clojure - Lazy vs non lazy sequence of primes
(defn prime?
[x]
(not-any? (fn [factor] (zero? (mod x factor)))
(range 2 (dec x))))
(defn eager-primes
([n] (eager-primes n 2 []))
([n curr xs]
(if (= n (count xs))
@mourjo
mourjo / apple_health_stats.js
Created January 1, 2022 05:59
Poor person's Apple Health stats for distance run in a year
import fs, { readFileSync } from 'fs';
import readline from 'readline';
const YEAR = '2021';
function infer(row) {
const ts = row.match(/startDate=".*?"/g)[0].match(/.?.?.?.?-.?.?-.?.? .?.?:.?.?:.?.? .?.?.?.?.?/)[0]
const dt = ts.substring(0, 10)
if (dt.startsWith(YEAR)) {
const unit = row.match(/unit=".*?"/)[0].match(/".?.?"/)[0].substring(1, 3)
@mourjo
mourjo / docker-compose.yml
Last active April 13, 2024 21:23
Docker compose for a minimal Kibana + Elasticsearch locally
version: '2.2'
services:
es01:
image: docker.elastic.co/elasticsearch/elasticsearch:7.15.1
container_name: es01
environment:
- node.name=es01
- cluster.name=es-docker-cluster
- discovery.type=single-node
- bootstrap.memory_lock=true
@mourjo
mourjo / plank.clj
Last active September 1, 2020 12:15
An inverted index like Elasticsearch for term filter lookups only
(ns plank.core
(:import (java.util.regex Pattern)))
; Problem Statement: Write code to solve this problem
; Given a set of news articles find articles that match the search query from a user.
; Assume that the search query is a single word.
;
; Each article has this structure: Id,Headline,Content
; Articles cannot be updated
@mourjo
mourjo / with-local-redefs.clj
Last active October 10, 2023 13:25 — forked from gfredericks/with-local-redefs.clj
thread-local version of with-redefs
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Commentary ;;
;; ;;
;; The goal for writing this started with the idea to have tests run in ;;
;; parallel using the leiningen plugin eftest ;;
;; https://github.com/weavejester/eftest. ;;
;; ;;
;; With tests using with-redefs, it was not possible to run them in ;;
;; parallel if they were changing the root binding of the same ;;
;; vars. Here, we are binding the root of the var to one function that ;;
@mourjo
mourjo / klotski.ml
Created December 11, 2018 16:34
Solving the klotski puzzle in OCaml
(* For the original problem statement, check http://mourjo.me/klotski_problem.pdf *)
exception NotFound
type 'e rel = 'e -> 'e list
type 'e prop = 'e -> bool
type ('a, 'set) set_operations = {
empty : 'set; (* The empty set. *)
mem : 'a -> 'set -> bool; (* [mem x s = true] iff [x] is in [s]. *)
@mourjo
mourjo / Queue.java
Last active July 10, 2017 06:36
Array backed queue
package arraybackedqueue;
import java.util.LinkedList;
import java.util.Random;
public class Queue {
private int head;
private int tail;
private int data[];