This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The Amazon Parent Dashboard allows searching for titles and hiding them from a profile, | |
// but you have to do it episode by episode. So, if you want to hide all Cocomelon or Blippi, | |
// it's a lot of clicking. These functions help. They're ~all structured as Promises to handle | |
// that UI actions take time, and to support sequencing them easily. | |
// This returns an HTMLCollection, which is a live view of the DOM | |
const findTitles = function() { | |
return document.getElementsByClassName("search-result-allowed-count-single-child"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Use to remove modals that some sites add when they detect | |
// an ad blocker or unauthenticated client. | |
// Minify with: https://skalman.github.io/UglifyJS-online/ | |
// Add as bookmarklet with: javascript:<minified-code> | |
(function() { | |
// Remove elements | |
[ | |
'modal', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; Happens sometimes when clojure.pprint/simple-dispatch or clojure.pprint/print-method | |
;; or whatnot don't have a stated preference for an object type that matches multiple | |
;; dispatch values. Here's a way around that. | |
;; Define a type that will match multiple dispatch values (IDeref & IPersistentMap) | |
user> (defrecord Foo [bar] | |
clojure.lang.IDeref | |
(deref [this] | |
(if bar | |
this |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; tldr; If you treat a record as a map and dissoc a property, clojure converts the | |
;; record to a PersistentArrayMap under the hood. | |
;; Example by way of a repl session | |
user> (defrecord Foo [bar baz]) ;; Define our record type | |
user.Foo | |
user> (map->Foo {:bar 1}) ;; Create a Foo... | |
#user.Foo{:bar 1, :baz nil} | |
user> (update *1 :bar inc) ;; Modify a Foo... | |
#user.Foo{:bar 2, :baz nil} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; User pack init file | |
;; | |
;; Use this file to initiate the pack configuration. | |
;; See README for more information. | |
;; Load bindings config | |
(live-load-config-file "bindings.el") | |
(add-to-list 'load-path "/Users/ryan/.live-packs/ryan-pack/lib/p4.elc") | |
(require 'p4) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;;; Quick Start Syntax | |
;; | |
;; Everybody new to clojure without a lot of lisp experience inevitably wants to | |
;; perform a known operation, without knowing what the clojure fn is to do that. | |
;; Almost every time you need a fn for some basic operation, clojure already has | |
;; it defined, but the naming can be unexpected. | |
;; | |
;; So, here’s a primer on common operations: | |
;;;; Functions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; I got thinking about this after reading Stuart Sierra's blog post on syntactic | |
;; pipelines, which while a bit old by now is still good reading for anybody | |
;; applying clojure to larger workflows. You can find it here: | |
;; http://stuartsierra.com/2012/05/16/syntactic-pipelines | |
;; | |
;; The point of this gist is an alternative way to organize synchronouse pipelines | |
;; that may otherwise be implemented as heavily nested branch expresssions, which | |
;; can be hard to read. The final proposal is a very minimal addition that fits closely | |
;; with existing clojure threading macors, but I wasn't able to find anything online | |
;; where this was already discussed. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;; I went looking for details on when it is appropriate to use the var macro (#’). | |
;; Here are a couple functions to set the context: | |
(defn something [fn x] (fn x)) | |
(defn cube [x] (* x x x)) | |
;; Now, a repl stack to demonstrate: | |
foo.core=> (something cube 4) | |
64 | |
foo.core=> (something #'cube 4) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// An exercise using scala to output a nicely formatted Pascal's triangle | |
import scala.math.max | |
// Define an extractor for Int so we can match below | |
object Int { | |
def unapply(s:String) : Option[Int] = try { | |
Some(s.toInt) | |
} catch { | |
case _ : java.lang.NumberFormatException => None | |
} |