Skip to content

Instantly share code, notes, and snippets.

@thomasdarimont
thomasdarimont / ConditionalOtpFormAuthenticator.java
Last active November 15, 2023 05:49
Keycloak Conditional OTP Step-by-Step
package org.keycloak.authentication.authenticators.browser;
import org.keycloak.authentication.AuthenticationFlowContext;
import org.keycloak.models.RoleModel;
import org.keycloak.models.UserModel;
import javax.ws.rs.core.MultivaluedMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;
@davegurnell
davegurnell / TypeclassDemo.scala
Created October 6, 2015 14:53
Example of the type class pattern in Scala
object TypeclasseDemo {
// The parts of the type class pattern are:
//
// 1. the "type class" itself -- a trait with a single type parameter;
//
// 2. type class "instances" for each type we care about,
// each marked with the `implicit` keyword;
//
// 3. an "interface" to the type class -- one or more methods
@MLnick
MLnick / HyperLogLogStoreUDAF.scala
Last active March 16, 2022 05:31
Experimenting with Spark SQL UDAF - HyperLogLog UDAF for distinct counts, that stores the actual HLL for each row to allow further aggregation
class HyperLogLogStoreUDAF extends UserDefinedAggregateFunction {
override def inputSchema = new StructType()
.add("stringInput", BinaryType)
override def update(buffer: MutableAggregationBuffer, input: Row) = {
// This input Row only has a single column storing the input value in String (or other Binary data).
// We only update the buffer when the input value is not null.
if (!input.isNullAt(0)) {
if (buffer.isNullAt(0)) {
@msgodf
msgodf / kiczales-oopsla94-black-boxes-reuse.md
Last active March 28, 2022 22:23
Gregor Kiczales "Why are black boxes so hard to reuse?"

This talk was given by Gregor Kiczales of Xerox PARC at OOPSLA ’94, 10/26/94. © 1994, University Video Communications. A transcript, with point- and-click retrieval of the slides, is available at http:/www.xerox.com/PARC/spl/eca/oi/gregor-invite/gregor- transcript.html

Why are black boxes so hard to reuse?

I think our field will go through a revolution. We will fundamentally change the way we think about and use abstraction in the engineering of software.

The goal of this talk is to summarize the need for and the basic nature of this abstraction framework.

The change is not new problems or new systems, but a new way of thinking about existing problems and existing systems.

@jneen
jneen / variant-multimethods.clj
Created November 22, 2014 20:55
Multimethods with variants
; it's a bit cumbersome to set up and there's the unfortunate need to ignore the tag
; in the individual methods, but this allows you to leave the interpretation of open
; variants, well, *open* for extension by multimethod.
; dispatch off the first argument, which will be the tag
(defmethod command-multi (fn [tag & data] tag))
; the first argument to the *method* is still the tag
(defmulti command-multi :print [_ val] (println val))
(defmulti command-multi :read [_ fname] (slurp fname))
@erasmas
erasmas / WriteToParquetExample.java
Last active March 29, 2017 05:47
Cascalog workflow to copy data from CSV to Parquet. How do I fix this so that schema fields are not prepended with '?' ?
/**
* Same workflow but using Cascading, output fields in Parquet file are obviously fine and not prepended with '?'
*/
package cascading.sandbox;
import cascading.flow.Flow;
import cascading.flow.FlowDef;
import cascading.flow.hadoop.HadoopFlowConnector;
import cascading.pipe.Pipe;
import cascading.property.AppProps;
@john2x
john2x / 00_destructuring.md
Last active April 23, 2024 13:18
Clojure Destructuring Tutorial and Cheat Sheet

Clojure Destructuring Tutorial and Cheat Sheet

(Related blog post)

Simply put, destructuring in Clojure is a way extract values from a datastructure and bind them to symbols, without having to explicitly traverse the datstructure. It allows for elegant and concise Clojure code.

Vectors and Sequences

tell application "System Preferences"
reveal anchor "keyboardTab" of pane "com.apple.preference.keyboard"
tell application "System Events"
click checkbox 1 of tab group 1 of window 1 of application process "System Preferences"
end tell
end tell
if application "System Preferences" is running then
tell application "System Preferences" to quit
end if
@gdevanla
gdevanla / y-combinator-clojure.clj
Last active October 9, 2022 16:46
Y-Combinator in Clojure based on Jim Weirich's talk Y-NOT
;; This gist roughly transribes the demo
;; by Jim Weirich during his talk on Y-Combinator
;; called Y-Not.
;; http://www.infoq.com/presentations/Y-Combinator
;; Jim does a phenomenal job of explaining in the demo.
;; Therefore, this gist only attempts to provide
;; the code example from the poor quality video
;; The examples are simplified at some places
;; based on how I tried to understand it
@sorenmacbeth
sorenmacbeth / ambrose.clj
Last active August 29, 2015 13:55
cascalog ambrose integration
(defn ambrose?-
[& bindings]
(let [[name bindings] (flow/parse-exec-args bindings)
bindings (mapcat (partial apply normalize-sink-connection)
(partition 2 bindings))
flow (-> (apply compile-flow name bindings)
flow/flow-def
flow/compile-hadoop)
server (EmbeddedAmbroseCascadingNotifier.)]
(.addListener flow server)