Skip to content

Instantly share code, notes, and snippets.

View jnorthrup's full-sized avatar

Jim Northrup jnorthrup

View GitHub Profile
/**
* Numerically re-prioritizable reference.
* Repurposes SoftReference.timestamp field as a priority value.
* <p>
* Intended to re-use all SoftReference-related VM features
* except its time-as-priority behavior.
*
* TODO this requires some modifications to internal JVM GC behavior.
@jnorthrup
jnorthrup / server.kt
Created October 29, 2021 01:45 — forked from kavanmevada/server.kt
Kotlin/Native POSIX Socket Server
package sample
import kotlinx.cinterop.*
import platform.linux.inet_ntoa
import platform.posix.*
/**
*
*/
import java.lang.reflect.Field;
import sun.misc.Unsafe;
public class Test {
private static final int N = 128 * 1024 * 1024;
public static void main(String[] args) throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
{
Field theUnsafe = Unsafe.class.getDeclaredField("theUnsafe");
@jnorthrup
jnorthrup / JSObj.kt
Last active October 15, 2021 03:31 — forked from mpetuska/JSObj.kt
Fluent Kotlin DSL for building JSON trees
@DslMarker
annotation class JSBuilderDsl
@DslMarker
annotation class JSSetterDsl
data class JSObj(val map: MutableMap<String, Any?> = linkedMapOf()) : MutableMap<String, Any?> by map {
object Arr {
@JSBuilderDsl
@jnorthrup
jnorthrup / git_create_orphan.sh
Created May 1, 2019 09:45 — forked from seanbuscay/git_create_orphan.sh
Create an orphan branch in a repo.
cd repository
git checkout --orphan orphan_name
git rm -rf .
rm '.gitignore'
echo "#Title of Readme" > README.md
git add README.md
git commit -a -m "Initial Commit"
git push origin orphan_name
@jnorthrup
jnorthrup / letsencrypt-jetty-auto.sh
Created February 15, 2019 03:50 — forked from smiley-yoyo/letsencrypt-jetty-auto.sh
How to use Letsencrypt certificate & private key with Jetty
#!/usr/bin/env bash
if [ ! -n "$1" ]; then
echo "usage: letsencrypt-jetty-auto.sh your_password_here"
exit 1
fi
# input: fullchain.pem and privkey.pem as generated by the "letsencrypt-auto" script when run with
# the "auth" aka "certonly" subcommand
@jnorthrup
jnorthrup / Parser.kt
Created August 14, 2017 18:32 — forked from absurdhero/Parser.kt
monadic parser combinator in Kotlin
package net.raboof.parser
// based on http://blogs.msdn.com/b/lukeh/archive/2007/08/19/monadic-parser-combinators-using-c-3-0.aspx
data class Result<TInput, TValue>(val value: TValue, val rest: TInput)
class Parser<TInput, TValue>(val f: (TInput) -> Result<TInput, TValue>?) {
operator fun invoke(input: TInput): Result<TInput, TValue>? = f(input)
infix fun or(other: Parser<TInput, TValue>): Parser<TInput, TValue> {
public class HowDoIInnerHtml implements EntryPoint {
@Override
public void onModuleLoad() {
Element body = Document.get().getBody();
DivElement newDiv = Document.get().createDivElement();
newDiv.setClassName("foo");
newDiv.setInnerText("Text in the div");
SpanElement newSpan = Document.get().createSpanElement();