Skip to content

Instantly share code, notes, and snippets.

View rwilson's full-sized avatar

Ryan Wilson rwilson

View GitHub Profile
@rwilson
rwilson / amazon_parent_dashboard.js
Created July 6, 2022 18:59
Amazon Parent Dashboard
// 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");
}
@rwilson
rwilson / unmodalify.js
Last active November 14, 2018 03:51
Unmodalify Bookmarklet
// 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',
@rwilson
rwilson / code.clj
Created March 21, 2016 23:09
Multiple methods in multimethod match dispatch value
;; 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
@rwilson
rwilson / dissoc_record.clj
Created January 9, 2016 02:30
Beware dissociating declared record fields
;; 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}
@rwilson
rwilson / init.el
Last active June 24, 2017 03:15
My Emacs Live init.el
;; 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)
@rwilson
rwilson / quickstart.clj
Created December 10, 2015 20:59
Clojure Syntax Quick-Start
;;;; 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
@rwilson
rwilson / core_ext.clj
Created December 10, 2015 20:53
Clojure Syntactic Piplines with a while-> Threading Macro
;; 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.
@rwilson
rwilson / vars.clj
Last active March 21, 2016 23:10
Clojure: when to use the var macro?
;;; 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)
@rwilson
rwilson / Pascal.scala
Created November 30, 2010 21:27
Pascal's Triangle in scala
// 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
}