Skip to content

Instantly share code, notes, and snippets.

@offbynull
offbynull / longdiv.tex
Last active January 19, 2020 18:33
KaTeX basic long division hack
\begin{array}{l}
\phantom{
{5\smash{)}}
}{
047.9
} \\
{5}\overline{\smash{)}239.5} \\
\phantom{{5\smash{)}}}\underline{0} \\
\phantom{{5\smash{)}}}23 \\
\phantom{{5\smash{)}}}\underline{20} \\
@offbynull
offbynull / Main.java
Last active January 14, 2020 22:58
Apache Batik draw arc example
package com.mycompany.test;
import java.awt.Color;
import java.awt.Rectangle;
import java.awt.geom.Arc2D;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.nio.file.Files;
import java.nio.file.Path;
@offbynull
offbynull / 2labellink.dot
Created June 30, 2019 18:53
Dot graph with 2 labels on the same link.
@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 / 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 / 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 / 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 / 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 / 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 / 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 {