Skip to content

Instantly share code, notes, and snippets.

@taylorwood
taylorwood / google-redirect.md
Created Jun 21, 2019
Google Redirect (Beta)
View google-redirect.md

Google Redirect (Beta)

Google has a https://www.google.com/url?q= endpoint that redirects to q, and it turns out you can nest these recursively and it'll 302 redirect you to each one in succession.

So here's the the most inefficient link to Google that will fit in a Tweet:

https://www.google.com/url?q=https%3A%2F%2Fwww.google.com%2Furl%3Fq%3Dhttps%253A%252F%252Fwww.google.com%252Furl%253Fq%253Dhttps%25253A%25252F%25252Fwww.google.com%25252Furl%25253Fq%25253Dhttps%2525253A%2525252F%2525252Fwww.google.com

Here's some Clojure I used to make the link:

@taylorwood
taylorwood / README.md
Created Apr 25, 2019
Scala Slick compile error: query with group by
View README.md

What happened?

This compilation error was generated by a Scala Slick query that's essentially a SQL SELECT with two JOINs and a GROUP BY:

slick.SlickTreeException: Cannot convert node to SQL Comprehension
GroupBy t3 : Vector[(t3<(Option[String'], Option[String'])>, Vector[t4<{s5: Option[scala.math.BigDecimal'], s6: SOption[OptionDisc/Int], s7: Option[String'], s8: SOption[OptionDisc/Int], s9: Option[String']}>])]
  from s2: Bind : Vector[t4<{s5: Option[scala.math.BigDecimal'], s6: SOption[OptionDisc/Int], s7: Option[String'], s8: SOption[OptionDisc/Int], s9: Option[String']}>]
    from s10: Filter s11 : Vector[t12<{s13: String', s14: String', s15: String', s16: String', s17: String', s18: Option[String'], s19: Int', s20: Option[String'], s21: String', s22: scala.math.BigDecimal', s23: String', s24: String', s25: String', s26: String', s27: String', s28: Boolean', s29: scala.math.BigDecimal', s30: String', s31: String', s32: Boolean', s33: Option[String'], s34: String', s35: Option[String'], s36:
@taylorwood
taylorwood / core.clj
Last active Sep 28, 2020
GraalVM polyglot interop between Clojure and JavaScript https://blog.taylorwood.io/2018/11/26/graal-polyglot.html
View core.clj
(ns polydact.core
(:import (clojure.lang IFn)
(org.graalvm.polyglot Context Value)
(org.graalvm.polyglot.proxy ProxyArray ProxyExecutable ProxyObject)))
(set! *warn-on-reflection* true)
(comment
(do
(def context
@taylorwood
taylorwood / hickory-css-selectors.clj
Last active Nov 16, 2019
CSS selectors for Hickory
View hickory-css-selectors.clj
(ns hickory-css-selectors
"Convert CSS selectors into Hickory selectors."
(:require [clojure.string :as cs]
[hickory.select :as s]
[instaparse.core :as p]
[instaparse.transform :as pt]))
(def css-selector-parser
"An incomplete and not very good parser for CSS selectors.
https://drafts.csswg.org/selectors-3/#selectors"
@taylorwood
taylorwood / transducers.clj
Created Sep 23, 2018
Clojure transducers
View transducers.clj
(defn zip
"Returns a transducer that zips cs with inputs."
[& cs]
(fn [rf]
(let [cs (volatile! cs)]
(fn
([] (rf))
([result] (rf result))
([result item]
(if (every? seq @cs)
@taylorwood
taylorwood / README.md
Last active May 6, 2020
clj.native-image CLI JSON-to-EDN example
View README.md

GraalVM native image + deps.edn example

A CLI tool that reads JSON from stdin then writes it to stdout in EDN format.

Build

➜ clojure -A:native-image
@taylorwood
taylorwood / instaparse.clj
Created May 14, 2018
Clojure Instaparse examples
View instaparse.clj
;; "human" date/time format parsing
(def human-time-parser
(insta/parser
"S = H (':' M)? ' '? P? (' ' Z)?
H = #'[1-9]' | #'1[0-2]'
M = #'0[0-9]' | #'[1-5][0-9]'
P = AM | PM
AM = 'A' 'M'?
PM = 'P' 'M'?
@taylorwood
taylorwood / Player.clj
Created Apr 30, 2018
CodinGame Battle Royale Bot
View Player.clj
(ns Player
(:require [clojure.pprint :refer [print-table pprint]]
[clojure.set :as set])
(:gen-class))
(defmacro debug [& body] `(binding [*out* *err*] (do ~@body)))
(def split-by (juxt filter remove))
(defn read-map [ks]
(let [vs (repeatedly (count ks) read)]
(zipmap ks vs)))
@taylorwood
taylorwood / clj-jdbc-postgres.clj
Created Feb 6, 2018
Clojure JDBC Postgres streaming resultset
View clj-jdbc-postgres.clj
(defn query-lazy ;; adapted from https://stackoverflow.com/a/39775018
[[sql & params] & {:as opts}]
(jdbc/with-db-transaction [tx (db/connection)]
(jdbc/query tx
(into [(jdbc/prepare-statement (:connection tx) sql {:fetch-size 100})] params)
opts)))
@taylorwood
taylorwood / stackoverflow-svg-icon-jekyll.html
Created Jan 5, 2018
Stack Overflow SVG icon for GitHub Pages Jekyll Footer
View stackoverflow-svg-icon-jekyll.html
{% if site.stackoverflow_username %}
<li>
<a href="https://stackoverflow.com/story/{{ site.stackoverflow_username }}">
<span class="icon icon--stackoverflow">
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" x="0px" y="0px" viewBox="0 0 120 120" style="enable-background:new 0 0 120 120;" xml:space="preserve">
<polygon fill="#828282" points="84.4,93.8 84.4,70.6 92.1,70.6 92.1,101.5 22.6,101.5 22.6,70.6 30.3,70.6 30.3,93.8 "/>
<path fill="#828282" d="M38.8,68.4l37.8,7.9l1.6-7.6l-37.8-7.9L38.8,68.4z M43.8,50.4l35,16.3l3.2-7l-35-16.4L43.8,50.4z M53.5,33.2 l29.7,24.7l4.9-5.9L58.4,27.3L53.5,33.2z M72.7,14.9l-6.2,4.6l23,31l6.2-4.6L72.7,14.9z M38,86h38.6v-7.7H38V86z"/>
</svg>
</span>
You can’t perform that action at this time.