Skip to content

Instantly share code, notes, and snippets.

View Artiavis's full-sized avatar

Jeff Rabinowitz Artiavis

View GitHub Profile
@Artiavis
Artiavis / deps.edn
Created December 14, 2017 03:54
I'm now considering using deps.edn as a replacement for profiles.clj, especially because it seems easier for installing user scripts (without uberjars).
;; The deps.edn file describes the information needed to build a classpath.
;;
;; When using the `clojure` or `clj` script, there are several deps.edn files
;; that are combined:
;; - install-level
;; - user level (this file)
;; - project level (current directory when invoked)
;;
;; For all attributes other than :paths, these config files are merged left to right.
;; Only the last :paths is kept and others are dropped.
@Artiavis
Artiavis / drip-cli.sh
Created December 14, 2017 03:52
A couple of handy shim functions for bootstrapping a Drip client with Clojure REPL's while bootstrapping though the new CLJ script.
#!/usr/bin/env sh
export DRIP_CLJ_CACHE_FILE="${HOME}/bin/.clj-class-path-cache"
dripclj_cache() {
clj -J-Xint -e '(-> "java.class.path" System/getProperty println)' > ${DRIP_CLJ_CACHE_FILE}
read -d $'\x04' DRIP_CLJ_CACHE < "${DRIP_CLJ_CACHE_FILE}"
}
{:user
{
:dependencies [; Clojure itself, and official clojure libraries
[org.clojure/clojure "1.8.0"]
[org.clojure/test.check "0.9.0"]
[org.clojure/core.async "0.3.442"]
[org.clojure/data.csv "0.1.3"]
[org.clojure/data.priority-map "0.0.7"]
[org.clojure/tools.namespace "0.2.11"]
; Unofficial but de facto Clojure utilities
@Artiavis
Artiavis / the_greeks.py
Created December 15, 2013 04:02
A quick script for calculating some of the Greeks in Python
# -*- coding: utf-8 -*-
from math import erf,exp,log,pi,sqrt
import argparse
def phi(x):
'Cumulative distribution function for the standard normal distribution'
return (1.0 + erf(x / sqrt(2.0))) / 2.0
def d(pos,r, sigma, T, K, S0):
x = ((r+0.5*sigma**2)*T - log(K/S0))/(sigma*sqrt(T))
@Artiavis
Artiavis / binomial_option_pricing.py
Last active December 25, 2015 03:29
A little script for evaluating and solving the binomial tree method of pricing vanilla European and American options. Takes parameters for specifying American/European call/put, number of periods, underlying price, u, d, strike, and interest.
from math import exp
from itertools import islice
import argparse
def window(seq, n=2):
it = iter(seq)
result = tuple(islice(it, n))
if len(result) == n:
yield result
for elem in it:
@Artiavis
Artiavis / GPA Calculator.py
Last active December 20, 2015 22:29
Simple command-line utility to help calculate a GPA.
import signal, sys
class _Getch:
"""Gets a single character from standard input. Does not echo to the
screen."""
def __init__(self):
try:
self.impl = _GetchWindows()
except ImportError:
self.impl = _GetchUnix()
@Artiavis
Artiavis / rmtex.py
Last active December 17, 2015 22:29
My first gist, a (hopefully) safe version of rmtex.
import os
import sys
import re
import argparse
def create_regex(reglist):
regopts = ['toc','bbl','aux','gz','blg','dvi','log','out']
filtlist = [exp for exp in reglist if exp in regopts]
if not filtlist:
raise TypeError('Invalid Regex')
@Artiavis
Artiavis / json-treasure-hunt.fsx
Last active October 22, 2015 04:24
A solution to the Reddit "Daily Programmer" Easy Challenge "JSON Treasure Hunt", found at https://www.reddit.com/r/dailyprogrammer/comments/3j3pvm/20150831_challenge_230_easy_json_treasure_hunt/. Also note a Clojure solution at https://gist.github.com/Artiavis/017b42017a3275cbbfe8.
#r "FSharp.Data.dll"
open System
open System.IO
open FSharp.Data
type TreasurePathCrumb =
| Index of int
| Key of string
@Artiavis
Artiavis / json-treasure-hunt.clj
Last active October 22, 2015 04:23
A solution to the Reddit "Daily Programmer" Easy Challenge "JSON Treasure Hunt", found at https://www.reddit.com/r/dailyprogrammer/comments/3j3pvm/20150831_challenge_230_easy_json_treasure_hunt/. Also note an F# solution at https://gist.github.com/Artiavis/29de21935d0afae782c4.
(ns json-treasure.core
(:require [clj-json [core :refer [parse-string]]]
[clojure.string :as string])
(:gen-class))
(defn build-json-path
[json-path-vec]
(string/join " -> " json-path-vec))
" Basics
set nocompatible
filetype plugin indent on
syntax on
scriptencoding utf-8
set history=1000
set hidden
set iskeyword-=.