Skip to content

Instantly share code, notes, and snippets.

View rabidaudio's full-sized avatar

Julien (CJK) rabidaudio

View GitHub Profile
require 'open-uri'
# I happened to watch [this video](https://www.youtube.com/watch?v=le5uGqHKll8) and it got
# me thinking about if the executioner cheats by changing the word during the course of the
# game, can the guesser still win?
#
# Results:
# 1: y, 24
# 2: ky, 20
# 3: qqv, 16
@rabidaudio
rabidaudio / deep_jsonb_concat.sql
Last active April 19, 2020 04:57
Deep jsonb_concat for Postgres
-- Postgres jsonb_concat() function only merges the top level keys, it does not merge nested objects.
-- This will merge all nested objects. Note that it doesn't recurse through arrays, nor does it append
-- arrays, it simply replaces them. It would be easy to adjust this if you need. Tested on 9.6.
-- NOTE: This was mostly an experiment and has not been thoroughly vetted for functionality or performance,
-- use at your own risk!
-- This work is in the Public Domain.
CREATE OR REPLACE FUNCTION _deep_jsonb_concat(a jsonb, b jsonb) RETURNS jsonb AS $$
DECLARE
key text;
merged jsonb;
@rabidaudio
rabidaudio / English.g4
Last active July 30, 2019 01:33
Experimenting with Antlr grammar syntax
grammar English;
paragraph: sentence+ EOF;
sentence: prepositionalPhrase* subject activeVerb directObject indirectObject? prepositionalPhrase* '.'
| prepositionalPhrase* subject? toBeVerb (directObject | adjective)? prepositionalPhrase* '.'
| toBeVerb subject (directObject | adjective)? prepositionalPhrase* '?';
subject: nounPhrase;
directObject: nounPhrase;

Keybase proof

I hereby claim:

To claim this, I am signing this object:

@rabidaudio
rabidaudio / dialog.kt
Created September 16, 2017 20:42
Kotlin Coroutine Android examples
suspend fun showConfirmationDialog() = suspendCancellableCoroutine<Boolean> { cont ->
val dialog = AlertDialog.Builder(this)
.setMessage("Are you sure?")
.setPositiveButton("Yes", { _, _ -> cont.resume(true) })
.setNegativeButton("No", { _, _ -> cont.resume(false) })
.setCancelable(true)
.setOnCancelListener { cont.cancel() }
.create()
dialog.show()
@rabidaudio
rabidaudio / Units.kt
Created July 12, 2017 02:12
Playing with unit analysis in kotlin
// see https://discuss.kotlinlang.org/t/units-of-measure/3454/7
// see http://javanut.net/2017/05/23/more-fun-with-generics-in-kotlin/
//class Bag<T> private constructor(val wrapped: List<T>): Collection<T> by wrapped {
//
// private class DefaultComparator<T>: Comparator<T> {
// override fun compare(o1: T, o2: T): Int = o1.toString().compareTo(o2.toString())
// }
//
// companion object {
@rabidaudio
rabidaudio / Main.kt
Created April 15, 2017 05:46
Blocking coroutine behavior
package com.example
import kotlinx.coroutines.experimental.*
import java.util.concurrent.ExecutorService
import java.util.concurrent.Executors
/**
* simulated blocking operation
*/
fun blockingFoo(x: Int): Int {
//
// Observable+Promise.swift
//
// Created by Charles Julian Knight on 1/2/17.
// Copyright © 2017 Charles Julian Knight. All rights reserved.
//
import Foundation
import RxSwift
import PromiseKit
@rabidaudio
rabidaudio / MenuContainerView.swift
Created February 3, 2016 17:02
A view which draws left and right menus (Swift)
//
// MenuContainerView.swift
// menu-tab-test
//
// Created by @charlesjuliank on 2/2/16.
//
import UIKit
// This is a special view where you can set a mainView as well as left and right menu views.
@rabidaudio
rabidaudio / KeyboardAvoidView.swift
Last active January 19, 2017 23:15
View for moving views out from under keyboard (Swift)
//
// KeyboardAvoidViewController.swift
//
// Created by Charles Julian Knight on 2/3/16.
// Copyright (c) 2017 Charles Julian Knight
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge,