Skip to content

Instantly share code, notes, and snippets.

💭
breathing

Logan Linn loganlinn

💭
breathing
Block or report user

Report or block loganlinn

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View board.ex
defmodule TicTacToe do
defmodule Board do
def create(maxX \\ 3, maxY \\ 3) do
for x <- 0..(maxX - 1),
y <- 0..(maxY - 1) do
{{x, y}, nil}
end
|> Map.new()
|> Map.put_new(:maxY, maxY)
|> Map.put_new(:maxX, maxX)
@loganlinn
loganlinn / custom_map_delegate.kt
Created Dec 7, 2018
Kotlin delegate property that allows map key to be different than property name
View custom_map_delegate.kt
import kotlin.properties.ReadWriteProperty
import kotlin.reflect.KProperty
fun <V> map(props: Props, key: String): ReadWriteProperty<Any?, V> {
return object : ReadWriteProperty<Any?, V> {
@Suppress("UNCHECKED_CAST")
override fun getValue(thisRef: Any?, property: KProperty<*>): V = props[key]!! as V
override fun setValue(thisRef: Any?, property: KProperty<*>, value: V) {
props[key] = value
@loganlinn
loganlinn / uuid_bytearray.kt
Created Nov 30, 2018
Kotlin extension function to convert UUID to ByteArray
View uuid_bytearray.kt
import java.nio.ByteBuffer
import java.util.UUID
fun UUID.asBytes(): ByteArray {
val b = ByteBuffer.wrap(ByteArray(16))
b.putLong(mostSignificantBits)
b.putLong(leastSignificantBits)
return b.array()
}
View swagger.yml
swagger: 2.0
info:
title: Clash Royale API
description:
version: v1
termsOfService: http://supercell.com/en/terms-of-service/
host: api.clashroyale.com
basePath: /v1
@loganlinn
loganlinn / yarn-client-config-generate.js
Last active Oct 23, 2018
Hadoop YARN client configuration as TypeScript interface
View yarn-client-config-generate.js
// https://hadoop.apache.org/docs/r2.7.5/hadoop-yarn/hadoop-yarn-common/yarn-default.xml
function generateInterface() {
return ['export interface IYarnClientConfig {',
$x('/html/body/table/tbody/tr/td[1]/a').flatMap(function(a) {
return [' /**',
' * '+a.parentElement.parentElement.children[2].innerText,
' */',
" '" + a.innerHTML + "'?: string",
'']
}).join("\n"),
@loganlinn
loganlinn / SharedMetricRegistries.kt
Last active Aug 29, 2018
Kotlin version of com.codahale.metrics.SharedMetricRegistries
View SharedMetricRegistries.kt
import com.codahale.metrics.MetricRegistry
import java.util.concurrent.ConcurrentHashMap
/**
* A map of shared, named metric registries.
*/
object SharedMetricRegistries {
private val REGISTRIES = ConcurrentHashMap<String, MetricRegistry>()
@Volatile
@loganlinn
loganlinn / travis-release.py
Created Aug 24, 2018
python script to release gradle project based on commit message in travis-ci environment
View travis-release.py
#!/usr/bin/env python
import logging
import os
import re
import subprocess
import sys
logging.basicConfig(format="%(asctime)s %(levelname)s %(message)s", datefmt='%Y-%m-%dT%H:%M:%SZ')
logging.getLogger().setLevel(logging.DEBUG)
View ServerTestUtils.java
import java.io.IOException;
import java.net.ServerSocket;
public class ServerTestUtils {
/**
* Returns a free port number on localhost.
*
* Heavily inspired from org.eclipse.jdt.launching.SocketUtil (to avoid a dependency to JDT just because of this).
* Slightly improved with close() missing in JDT. And throws exception instead of returning -1.
*
View SamzaBridgedMetricRegistry.java
import com.codahale.metrics.*;
import com.google.common.base.Preconditions;
import org.apache.samza.metrics.Gauge;
import org.apache.samza.metrics.MetricsRegistry;
import java.util.HashMap;
import java.util.Map;
/**
* Bridges <a href="http://dropwizard.github.io/metrics/">Dropwizard Metrics</a> (aka Coda Hale metrics)
View DebugExceptionMapper.java
import org.apache.commons.lang.exception.ExceptionUtils;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.ext.ExceptionMapper;
import javax.ws.rs.ext.Provider;
import java.util.StringJoiner;
/**
* Catch-all exception mapper that creates response with message and stack trace.
You can’t perform that action at this time.