Skip to content

Instantly share code, notes, and snippets.

@gja
gja / kotlin-shadow.kt
Last active December 25, 2022 12:47
Kotlin DSL Shadowing
data class SetFoo(val foo: Int)
data class SetFooAndBar(val foo: Int, val bar: Int)
fun setFooTo3AndBarTo42(exec: SetFooAndBar.() -> Unit) {
SetFooAndBar(3, 42).exec()
}
fun setFooTo4(exec: SetFoo.() -> Unit) {
SetFoo(4).exec()
}
@gja
gja / get-google-font.sh
Created October 24, 2018 19:23
Get fonts from Google Font in woff2 and woff
#!/bin/bash -e
function getCSSFile() {
curl -sH "User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:27.0) Gecko/20100101 Firefox/27.0" "https://fonts.googleapis.com/css?family=$@"
echo ---------------------
curl -sH "User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.90 Safari/537.36" "https://fonts.googleapis.com/css?family=$@"
}
function mergeCSSfiles() {
gawk -f <(cat << EOF
@gja
gja / paste-in-console.js
Created January 18, 2018 05:55
Print out the Barbie
deleteElement = (elem) => elem.parentElement.removeChild(elem)
deleteElement($(".show_print")[0]);
deleteElement($(".app-band-text")[0]);
deleteElement($(".nudge-app-band-wrapper")[0]);
$(".article-content").addClass("show_print");
window.print();
@gja
gja / infinite-scroll.js
Last active June 7, 2021 11:12
React Infinite Scroll with IntersectionObserver
const React = require("react");
// An item in the infinite scroll
class ScrollItem extends React.Component {
constructor(props) {
super(props);
this.state = {
minHeight: props.minHeight
}
}
@gja
gja / Readme.md
Last active November 11, 2017 17:52
Cat Mode on OSX
  1. Install Karabiner-Elements https://pqrs.org/osx/karabiner/
  2. Save this as your ~/.config/karabiner/karabiner.json
  3. Launch Karabiner-Elements
  4. You will have a profile called Cat Mode which disables all keys except the power button

There is a github repo which was a Karabiner extension I borrowed some inspiration from. I'll link to it if I find it again.

@gja
gja / volume.clj
Created April 28, 2017 02:31
Find the shortest path to a certain volume
(defn- neighboring-edges [node capacity]
(for [i (range (count capacity))
j (range (count capacity))
:when (not= i j)]
(let [total-amount (+ (get node i) (get node j))
amount-in-j (min total-amount (get capacity j))
amount-in-i (- total-amount amount-in-j)]
{:node (assoc node i amount-in-i j amount-in-j)
:pour [i j]})))
@gja
gja / main.go
Last active December 15, 2016 16:13
Program Showing Of Go Pipelining
package main
import (
"fmt"
"time"
"sync"
)
func producer(output_channel chan <- int) {
for i := 0; i < 100; i++ {
@gja
gja / log4j2.xml
Last active September 25, 2015 20:24
log4j2 and ryslog2
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
<Appenders>
<Syslog name="syslog" host="localhost" port="4242" protocol="UDP" format="RFC5424" enterpriseNumber="18060" appName="quest" mdcId="quest">
<LoggerFields>
<KeyValuePair key="thread" value="%t"/>
<KeyValuePair key="name" value="%c"/>
</LoggerFields>
</Syslog>
<Async name="AsyncUDPAppender">
@gja
gja / core.clj
Last active August 15, 2022 16:25
Building a lein uberjar without any compilation
(ns simplequest.core)
(defn -main
"I don't do a whole lot ... yet."
[& args]
(println "Hello, World!"))
@gja
gja / combine-pdf.sh
Created June 28, 2014 03:17
Command to combine PDFs
/System/Library/Automator/Combine\ PDF\ Pages.action/Contents/Resources/join.py --output output.pdf $@