Skip to content

Instantly share code, notes, and snippets.

View hindol's full-sized avatar

Hindol hindol

View GitHub Profile
@hindol
hindol / websocket.clj
Created June 12, 2020 18:06
Access WebSocket session in Pedestal
(defn ws-listener
[_request _response ws-map]
(proxy [WebSocketAdapter] []
(onWebSocketConnect [^Session ws-session]
(proxy-super onWebSocketConnect ws-session)
(when-let [f (:on-connect ws-map)]
(f ws-session)))
(onWebSocketClose [status-code reason]
(when-let [f (:on-close ws-map)]
(f (.getSession this) status-code reason)))
@hindol
hindol / Function.java
Last active October 7, 2022 19:15
Writing Azure Functions in Clojure
package com.github.hindol.clj_fn.core;
import clojure.lang.*;
import com.microsoft.azure.functions.*;
import com.microsoft.azure.functions.annotation.*;
public final class Function implements Functional, IType
{
public static final Object const__0;
@hindol
hindol / lazy-seq.clj
Created February 26, 2020 05:56
Clojure Lazy Sequences Explained
;; Let's say, we want a sequence of all the powers of a number.
(defn powers
([x] (powers x x))
([x p]
(cons p (powers x (* x p)))))
(powers 2)
;; => integer overflow
;; This throws an error because we cannot really calculate an infinite sequence.
@hindol
hindol / bag.clj
Last active March 13, 2020 11:27
Bag / MultiSet in Clojure (How to create a custom collection in Clojure)
(ns com.github.hindol.euler.collections
(:import
(clojure.lang IPersistentCollection
IPersistentSet
Seqable)))
(deftype Bag [^clojure.lang.IPersistentMap m
^long n]
IPersistentSet
(get [this k]
@hindol
hindol / prime-factorize.clj
Last active February 20, 2020 04:43
Clojure Prime Factorization Sieve
;; Prime factorize all numbers in the range [2 100,000]
;; Naive, no sieve
(def prime-seq
(concat
[2 3 5 7]
(lazy-seq
(let [primes-from (fn primes-from
[n [f & r]]
(if (some #(zero? (rem n %))
(ns com.github.hindol.euler
(:require
[clojure.test :refer [is]]
[clojure.tools.trace :refer [trace-ns untrace-ns]])
(:gen-class))
(set! *unchecked-math* true)
(set! *warn-on-reflection* true)
(defn pentagonal-seq
@hindol
hindol / clojure_in_15_minutes.md
Last active August 8, 2021 15:51
Clojure in 15 Minutes: A Crash-course

Clojure in 15 Minutes

Hello, Clojure!

(println "Hello, world!")
  • The same in Python,
@hindol
hindol / gn-mode.el
Created October 31, 2018 09:01
Google's `gn-mode.el` with Proper Package Headers
;;; gn-mode.el --- A major mode for editing gn files.
;; Copyright 2015 The Chromium Authors. All rights reserved.
;; Use of this source code is governed by a BSD-style license that can be
;; found in the LICENSE file.
;; Author: Elliot Glaysher <[email protected]>
;; Version: 1.0
;; Created: April 03, 2015
;; Keywords: tools, gn, ninja, chromium
@hindol
hindol / generate_plots.sh
Created August 30, 2013 10:07
Example on how to use GNUPlot to output high quality graphs
#!/usr/bin/env bash
INPUT_DIR="../50_5_5"
OUTPUT_DIR=".."
PARAMETERS=( "like-mindedness" "modularity" )
LABELS=( "Like-mindedness" "Modularity (Q)" )
for i in ${!PARAMETERS[*]}; do
gnuplot <<- EOF
@hindol
hindol / sudoers
Last active January 30, 2024 00:27
How to setup proxy for `sudo` environment. Tested for `Ubuntu` and `Linux Mint`.
# The following should be in `/etc/sudoers`. To edit `/etc/suoders` use the command `sudo visudo` in a terminal.
# *Do NOT attempt to modify the file directly*
Defaults env_reset
Defaults mail_badpass
Defaults env_keep+="http_proxy ftp_proxy all_proxy https_proxy no_proxy" # Add this line
...