Skip to content

Instantly share code, notes, and snippets.

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
@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

@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;
@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))
@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.

@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)) {
@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
@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;
@baumgardner
baumgardner / clojure_is_for_type_b_personalities.md
Created January 22, 2016 04:36
Clojure is for type B personalities

The other day, I was wondering why Clojure fits my brain so well. I think I was relaxing on my old couch, drinking cheap beer, eating a gas station pastry, and drawing doodles on a stack of overdue bills I forgot to pay. Little did I realize, these things are all connected.

I have a hypothesis that people choose programming languages based on their personality. For the purposes of this write-up, I’ll use the well-known distinction between type A and type B people. This may be pop psychology stuff, but it’s convenient for my point so in the spirit of American politics I will treat it as fact.

Type A vs Type B

Type A people are very organized, competitive, punctual, and like to plan ahead. When I was a kid, these were the ones who had perfect grades, competed in track or swimming, and on top of that they were nice people so I couldn't even hate the fuckers. Type B people, on the other hand, are laid back and like to do things spontaneously. Like The Dude from The Big Lebowski, they are comfortable with

@wernsey
wernsey / JDatalog.java
Last active August 23, 2023 01:19
Java Datalog Engine and Interpreter
/*
Java Datalog Engine with Stratified Negation
Copyright 2016 Werner Stoop
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0