Skip to content

Instantly share code, notes, and snippets.

@johnmastro
johnmastro / filter-by-val.clj
Last active May 14, 2019 08:35
Filter Clojure maps by value
(defn filter-by-val-1
[pred m]
(into {} (filter (fn [[k v]] (pred v))
m)))
;; This one is a little faster
(defn filter-by-val-2
[pred m]
(persistent!
(reduce-kv (fn [acc k v]
Process: TablePlus [5322]
Path: /Applications/TablePlus.app/Contents/MacOS/TablePlus
Identifier: com.tinyapp.TablePlus
Version: 2.8.3 (259)
Code Type: X86-64 (Native)
Parent Process: ??? [1]
Responsible: TablePlus [5322]
User ID: 503
Date/Time: 2019-09-13 11:19:10.648 -0400
09-16 16:08:02 WARN middleware.process-userland-query :: Query failure {:status :failed,
:class java.sql.SQLNonTransientConnectionException,
:error "(conn=6989) Connection timed out (Write failed)",
:stacktrace
("org.mariadb.jdbc.internal.util.exceptions.ExceptionMapper.get(ExceptionMapper.java:234)"
"org.mariadb.jdbc.internal.util.exceptions.ExceptionMapper.getException(ExceptionMapper.java:165)"
"org.mariadb.jdbc.MariaDbStatement.executeExceptionEpilogue(MariaDbStatement.java:238)"
"org.mariadb.jdbc.MariaDbPreparedStatementClient.executeInternal(MariaDbPreparedStatementClient.java:232)"
"org.mariadb.jdbc.MariaDbPreparedStatementClient.execute(MariaDbPreparedStatementClient.java:159)"
"org.mariadb.jdbc.MariaDbPreparedStatementClient.executeQuery(MariaDbPreparedStatementClient.java:174)"
metabase/redux/metadata fetchDatabaseMetadata
v @ app-main.bundle.js?a0cb8a0cb1424da110c7:1
app-main.bundle.js?a0cb8a0cb1424da110c7:1 Error getting setting graph.x_axis._is_timeseries TypeError: Cannot read property 'cols' of undefined
at Object.getDefault (app-main.bundle.js?a0cb8a0cb1424da110c7:1)
at g (app-main.bundle.js?a0cb8a0cb1424da110c7:1)
at t.getComputedSettings (app-main.bundle.js?a0cb8a0cb1424da110c7:1)
at h (app-main.bundle.js?a0cb8a0cb1424da110c7:1)
at t.value (app-main.bundle.js?a0cb8a0cb1424da110c7:1)
at t.value (app-main.bundle.js?a0cb8a0cb1424da110c7:1)
at u.performInitialMount (vendor.bundle.js?a0cb8a0cb1424da110c7:1)
class AirtableClient:
# ...
def request(self, method, *args, **kwargs):
# ...
retries = 0
wait = 30
while True:
response = self.session.request(method, *args, headers=headers, **kwargs)
if response.status_code != 429 or retries == 3:
def load(connection, airtable, table_name, field_info, destination):
restarts = 0
while True:
try:
chunks = airtable.iter_chunks(table_name)
# Airtable will give us the records in chunks of 100, which is
# inefficiently small for loading into Snowflake, so buffer them up into
# chunks of a few thousand
chunks = rechunked(chunks, 5000)
return _load_chunks(connection, chunks, field_info, destination)
# Make sure the table is created in the db even if it's empty. This is ugly,
# including in that every column will have type `string`, but the types will be
# fixed up as soon as there's actual data to load
if count == 0:
nulls_df = result_to_df([], field_info)
nulls_df = pd.concat(
[nulls_df, pd.DataFrame([{c: None for c in nulls_df.columns}])]
)
nulls_df.to_sql(
# ...
@johnmastro
johnmastro / iterm.el
Last active September 13, 2022 14:41
Send text from Emacs to iTerm
;;; iterm.el - Send text to a running iTerm instance
(require 'pcase)
(require 'thingatpt)
;; To match SublimeText's key binding:
;; (global-set-key (kbd "<C-return>") 'iterm-send-text)
(defvar iterm-default-thing 'line
"The \"thing\" to send if no region is active.
;; An attempt at this Emacs SX question:
;; https://emacs.stackexchange.com/questions/10359/delete-portion-of-isearch-string-that-does-not-match-or-last-char-if-complete-m
(defun isearch-delete-something ()
"Delete non-matching text or the last character."
;; Mostly copied from `isearch-del-char' and Drew's answer on the page above
(interactive)
(if (= 0 (length isearch-string))
(ding)
(setq isearch-string
@johnmastro
johnmastro / Card.java
Last active March 24, 2024 19:13
Card and Deck classes in Java (from an assignment in my Java class)
import java.util.Objects;
/**
* Class representing a playing card from a standard 52-card deck.
*/
public class Card
{
/**
* Enum representing playing card suits.
*/