Skip to content

Instantly share code, notes, and snippets.

@offbynull
offbynull / gist:3259bace31444ed7c703
Created March 9, 2015 23:35
ASM method stack and local vars table introspection
package com.offbynull.test.asmtest;
import java.io.DataOutputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.ListIterator;
import java.util.Map;
import java.util.Map.Entry;
@offbynull
offbynull / ContinuationClassLoader
Created August 5, 2015 17:11
Javaflow's ContinuationClassLoader modified to use Coroutines 1.1.0
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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
*
@offbynull
offbynull / SshjBasic.java
Created March 6, 2018 19:04
Basic SSHJ Usage
package com.offbynull.rfm.ssh;
import java.io.IOException;
import net.schmizz.sshj.SSHClient;
import net.schmizz.sshj.connection.channel.direct.Session.Command;
import net.schmizz.sshj.userauth.keyprovider.KeyProvider;
public final class SshjBasic {
public static void main(String[] args) throws Exception {
@offbynull
offbynull / AsmInvokeDynamic.java
Created June 8, 2018 02:03
ASM access invokedynamic bootstrap method information
import java.io.FileInputStream;
import static java.util.Arrays.asList;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.tree.AbstractInsnNode;
import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.InvokeDynamicInsnNode;
import org.objectweb.asm.tree.MethodNode;
public class AsmInvokeDynamic {
@offbynull
offbynull / flatten.sql
Last active June 19, 2018 23:56
Flatten out key-value data into a row
-- Imagine the following table...
-- --------------------
-- |ID|NAME|VAL |
-- |==|====|============|
-- |A |KEY1|1.0000000000|
-- |A |KEY2|2.0000000000|
-- |B |KEY1|3.0000000000|
-- |B |KEY2|4.0000000000|
-- |B |KEY3|5.0000000000|
-- |C |KEY1|6.0000000000|
@offbynull
offbynull / custom_markup.js
Created April 14, 2019 18:29
Custom markup in markdown-it
var MarkdownIt = require("markdown-it");
var md = new MarkdownIt('commonmark');
// Add custom INLINE rule that pulls in anything wrapped in a ::: <TEXT> ::: and wrap in a span tag
function custom_inline(state, silent) {
let pos = state.pos;
@offbynull
offbynull / custom_blocks.js
Last active April 16, 2019 23:49
Override markdown-it inline code and fence
module.exports = function(md, options) {
const blockIdMap = options.blockIdMap;
const inlineIdMap = options.inlineIdMap;
const oldFenceRule = md.renderer.rules.fence;
const oldInlineCodeRule = md.renderer.rules.code_inline;
md.renderer.rules.fence = function(tokens, idx, options, env, self) {
const token = tokens[idx];
const infoMatch = token.info.match(/^\s*\{([A-Za-z0-9]*)\}\s*/);
@offbynull
offbynull / sticky_top_right.html
Created June 22, 2019 20:21
Sticky an element to the top-right of a viewport
<span style="position: fixed; top: 0; right: 0; border: 0; background-color:red">hello world</span>
<div>fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff</div>
hi<br>
hi<br>
hi<br>
hi<br>
hi<br>
hi<br>
hi<br>
hi<br>
@offbynull
offbynull / equals_hashcode.ts
Created June 22, 2019 23:24
An easy way to do automated equals / hashCode for sets and maps in collection-js and immutable-js
// Easy doesn't mean fast. See immutable-js docs for how to implement hashCode
// and equals (see ValueObject -- you just add in the methods to your
// class/object, no TS interfaces to implement).
import { MD5 } from 'object-hash';
import deepEqual from 'deep-equal';
const o1 = {
a: 'hi',
b: 4,
@offbynull
offbynull / 2labellink.dot
Created June 30, 2019 18:53
Dot graph with 2 labels on the same link.