Skip to content

Instantly share code, notes, and snippets.

View kyptin's full-sized avatar

Jeff Terrell kyptin

View GitHub Profile
@kyptin
kyptin / setup-nested-lein-projects.sh
Last active December 17, 2015 08:09
Setup nested "checkout" projects for Leiningen, to demonstrate the (current) lack of a desired feature.
#!/bin/bash
# Referenced in Leiningen Issue #1180, here:
# https://github.com/technomancy/leiningen/issues/1180
if [ ! -z `ls -A | egrep -v '^(main|child|grandchild|setup-nested-lein-projects.sh)$'` ]; then
echo "Cowardly refusing to continue in a directory with unrecognized files."
exit 0
fi
@kyptin
kyptin / setup-3level-lein-checkouts.sh
Last active December 17, 2015 22:00
Setup 3 levels of nested "checkout" projects for Leiningen, to demonstrate the (current) lack of a desired feature.
#!/bin/bash
# Referenced in Leiningen Issue #1190, here:
# https://github.com/technomancy/leiningen/issues/1190
if [ ! -z `ls -A | egrep -v '^(main|child|grandchild|greatgrandchild|setup-3level-lein-checkouts.sh)$'` ]; then
echo "Cowardly refusing to continue in a directory with unrecognized files."
exit 0
fi
@kyptin
kyptin / core.clj
Created March 22, 2014 21:45
Evaluation of different methods for computing variance
(ns perftest.core
(:require
[clojure.java.io :as io]))
(defn perftest
[]
(with-open [writer (io/writer "times.out")]
(let [bigseq (range 1e8)]
(doall
(for [item bigseq]
@kyptin
kyptin / ec2-ssh
Last active May 12, 2016 19:02
SSH to AWS EC2 instance
ec2-ssh ()
{
local host="ec2-user@$1";
local opts;
opts="-i $HOME/TestKeyPair.pem";
opts="$opts -o UserKnownHostsFile=/dev/null";
opts="$opts -o StrictHostKeyChecking=no";
scp $opts ~/aws-bashrc $host:.bashrc && ssh $opts ec2-user@$@
}
@kyptin
kyptin / s3_presigned_url.clj
Last active May 13, 2016 17:35
S3 presigned URLs ready for image upload
(ns s3-presigned-url
"You can pre-sign an S3 path to allow users to access it without credentials.
This gives fine-grained access control with expiration to 'anonymous' (from
the perspective of S3) users. It's a convenient mechanism, if you can get it
to work.
There are some relatively well-trod paths for doing pre-signed S3 URLs, e.g.
when giving read-only access via an HTTP GET request. These paths have more
convenient and well-known mechanisms out there.
@kyptin
kyptin / make_cdf.clj
Last active May 12, 2016 18:59
Make a CDF (cumulative distribution function) from a seq of numbers in Clojure
(defn make-cdf
"Given a seq of numbers, return a plottable vector of [x,y] pairs
representing the cumulative distribution function.
Ex:
(cdf-data [1 2 1 3])
; => [[1 0] [1 1/2] [2 3/4] [3 1]]"
[xs]
{:pre [(sequential? xs)]}
(let [n (count xs)
uniq-xs (->> xs frequencies (into (sorted-map)))
@kyptin
kyptin / entropy.clj
Last active August 30, 2022 05:29
Shannon's entropy in Clojure
(defn entropy
"Calculate the Shannon entropy, a.k.a. amount of information, in a
distribution. Uses the log-base-2 version, so the result can be thought of as
the number of bits of information. Accepts either a seq of numbers or a map of
freqencies like that returned by the `clojure.core/freqencies` function.
Ex:
(entropy [1]) ; => 0.0
(entropy [0 1 0 1]) ; => 1.0
(entropy [0 1 2 3]) ; => 2.0
(entropy {0 2, 1 2}) ; => 1.0

Keybase proof

I hereby claim:

  • I am kyptin on github.
  • I am kyptin (https://keybase.io/kyptin) on keybase.
  • I have a public key ASDD9FgPd0WBlTnf1EGJJlzQ2wQ_WhmtuNRrB5eVH5ZSgwo

To claim this, I am signing this object:

@kyptin
kyptin / steps.md
Last active October 16, 2023 06:22
Accessing a rails console in Google App Engine (flexible)

If you're running a Rails app in Google App Engine's flexible environment, it takes a bit of setup to get to a rails console attached to your deployed environment. I wanted to document the steps for my own reference and also as an aid to others.

  1. Open the Google App Engine -> instances section of the Google Cloud Platform (GCP) console.

  2. Select the "SSH" drop-down for a running instance. (Which instance? Both of my instances are in the same cluster, and both are running Rails, so it didn't matter for me. YMMV.) You have a choice about how to connect via ssh.

    1. Choose "Open in browser window" to open a web-based SSH session, which is convenient but potentially awkward.

    2. Choose "View gcloud command" to view and copy a gcloud command that you can use from a terminal, which lets you use your favorite terminal app but may require the extra steps of installing the gcloud command and authenticating the gcloud command with GCP.

@kyptin
kyptin / .block
Created December 7, 2018 14:56 — forked from hannahherbig/.block
Better Quicksort V
license: gpl-3.0