Skip to content

Instantly share code, notes, and snippets.

View kyptin's full-sized avatar

Jeff Terrell kyptin

View GitHub Profile
@kyptin
kyptin / reload-safari-tab.sh
Last active November 3, 2022 13:47
reload-safari-tab - use osascript to reload a safari tab by url substring - composable with entr for auto-reloading
#!/bin/bash
set -euo pipefail
usage() {
echo "$(basename "$0") - Reload any Safari tabs that contain the given string."
echo "Usage:"
echo " $(basename "$0") STRING"
echo " fd <opts> | entr reload-safari-tab STRING"
}
@kyptin
kyptin / commits.clj
Created March 2, 2020 15:58
Fetch commit author frequences from the GitHub API (COMP 590 in-class exercise)
(ns commits
(:require [clj-http.client :as http]
[clj-json.core :as json]
[clojure.pprint :refer [pprint]]))
(def api-url "https://api.github.com/repos/clojure/clojure/commits")
(defn get-committers-from-page [n]
(some->> (http/get api-url {:query-params {"per_page" 100, "page" n}})
:body
@kyptin
kyptin / isolated_behaviors_quiz.clj
Created February 17, 2020 15:20
Code for an in-class quiz (COMP 590/spring 2020) for listing behaviors of a function assuming isolated tests
;; To write tests for this function, what behaviors would you list?
(defn pascal-row
"Return a seq of the numbers in the n-th row of Pascal's triangle (where n=0 is
the first row)."
[n]
(for [i (range (inc n))]
(combinations n i)))
@kyptin
kyptin / behaviors_quiz.clj
Created February 12, 2020 15:24
Code for an in-class quiz (COMP 590/spring 2020) for listing behaviors of a function
;; To write tests for this function, what behaviors would you list?
(defn summation
([xs] (summation identity xs))
([f xs] (reduce + 0 (map f xs))))
@kyptin
kyptin / before.js
Created October 21, 2019 16:40
Effects refactoring example (UNC COMP 523)
// Goal: assign students to seats
// Usage: node before.js
// Context: UNC COMP 523 (https://comp523.cs.unc.edu)
// Exercise: refactor to manage effects better
const makePref = ([pid, section, isVip]) =>
({pid, section, isVip, isAssigned: false})
const makePrefs = (rows) => rows.map(makePref)
@kyptin
kyptin / deploy-current-commit.sh
Created June 17, 2019 17:29
Deploy current commit to Datomic Ions
#!/bin/bash
# This automates the process of using Datomic Ions to push, deploy, and wait for
# the deployment to finish. It works as of com.datomic/ion.dev version 0.9.229.
# For more info, see https://docs.datomic.com/cloud/ions/ions.html
set -euxo pipefail
status_cmd=$(clj -A:dev -m datomic.ion.dev '{:op :push}' 2>&1 | \
grep -v ^Downloading | \
@kyptin
kyptin / .block
Created December 7, 2018 14:56 — forked from hannahherbig/.block
Better Quicksort V
license: gpl-3.0
@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.

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 / 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