Skip to content

Instantly share code, notes, and snippets.

View naiquevin's full-sized avatar

Vineet Naik naiquevin

View GitHub Profile
@naiquevin
naiquevin / clj-fn-usages
Last active March 8, 2023 17:22
A crude way to find clojure functions usages in a codebase using ripgrep (false positives possible)
#!/usr/bin/env bash
## Script for searching for all references to a particular function in
## a clojure project (A crude implementation of "Find usage"
## functionality commonly found in IDEs such as Intellij) False
## positives are possible.
##
## Usage:
##
## $ clj-fn-usages NAMESPACE_QUALIFIED_FN [ paths ... ]
@naiquevin
naiquevin / inclojure_mocks.clj
Last active January 13, 2018 11:54
Generative mocking using circleci/bond and core.spec (IN/Clojure 2018 lightning talk)
(ns inclojure-mocks)
;; IN/Clojure 2018 lightning talk :: 13/01/2018
;;
;; Topic: Mocking code (mainly for writing tests)
;;
;; Will be covered:
;;
;; 1. Mocking code using circleci/bond library
@naiquevin
naiquevin / ansible-vault-diff
Last active April 26, 2016 14:01
Decrypted git diff for encrypted ansible vault files
#!/usr/bin/env bash
set -e
usage()
{
cat << EOF
usage: $(basename $0) [ -c COMMIT -v VAULT_PASSWORD_FILE ] -f FILE
To view the actual changes in ansible vault/secret files for a git commit.
@naiquevin
naiquevin / fnone.py
Created November 7, 2015 15:07
fnil's cousin from python land
from itertools import izip_longest
def fnone(f, *xs):
"""Takes a function f, and returns a function that calls f, replacing
a None first argument to f with the supplied value x. Higher arity
versions can replace arguments in the second and third
positions (y, z). Note that the function f can take any number of
arguments, not just the one(s) being None-patched.
"""
@naiquevin
naiquevin / throttle_greedy.py
Created June 30, 2015 18:54
Greedy throttling for function calls
import time
from functools import wraps
def throttle_greedy(wait):
def decorator(fn):
state = {'last_call_at': None}
@wraps(fn)
def wrapper(*args, **kwargs):
@naiquevin
naiquevin / async.clj
Created January 8, 2015 18:10
clojure core.async - consume until some timeout
(defn consume-until-timeout
[ms ch f init & args]
(let [tmt (timeout ms)]
(go (loop [ret init]
(if-let [v (first (alts! [ch tmt]))]
(recur (apply f ret [v]))
ret)))))
(comment
@naiquevin
naiquevin / a.py
Last active August 29, 2015 14:09
Python scoping
import d
x = 10
def f(n):
return x + n
print 'f(2) called directly in module a [a.x = 10]'
print f(2)
@naiquevin
naiquevin / fifthel-mcl-r-session.txt
Last active August 29, 2015 14:02
Hands on R session from Machine learning workshop
### Hands on R session by Harshad Saykhedkar from today's Machine
### learning workshop (Fifth elephant Mumbai run-up event)
---
R version 3.1.0 (2014-04-10) -- "Spring Dance"
Copyright (C) 2014 The R Foundation for Statistical Computing
Platform: i686-pc-linux-gnu (32-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
@naiquevin
naiquevin / message_ring.erl
Created May 29, 2014 16:49
message_ring.erl
-module(message_ring).
-compile(export_all).
-export([]).
%% Problem Statement: Write a ring benchmark. Create N processes in a
%% ring. Send a message round the ring M times so that a total of N *
%% M messages get sent. Time how long this takes for different values
%% of N and M.
@naiquevin
naiquevin / concurrently.py
Last active August 29, 2015 14:01
Concurrently run list of functions and get results as a list
from operator import itemgetter
from threading import Thread
try:
from Queue import Queue
except ImportError:
from queue import Queue
def concurrently(fns):