Skip to content

Instantly share code, notes, and snippets.

View edefazio's full-sized avatar
🙂
Focusing

edefazio

🙂
Focusing
View GitHub Profile
@mmozeiko
mmozeiko / shader.hlsl
Last active November 7, 2024 20:23
compute shader for rendering monospaced glyphs in grid
//
struct TerminalCell
{
// cell index into GlyphTexture, should be two 16-bit (x,y) values packed: "x | (y << 16)"
uint GlyphIndex;
// 0xAABBGGRR encoded colors, nonzero alpha for Foreground indicates to render colored-glyph
// which means use RGB values from GlyphTexture directly as output, not as ClearType blending weights
uint Foreground;
typedef enum {
CMD_INT = NODE_INT,
CMD_NEG = NODE_NEG,
CMD_NOT = NODE_NOT,
CMD_ADD = NODE_ADD,
CMD_SUB = NODE_SUB,
CMD_RET = 128,
CMD_SETREF,
CMD_GETREF,
} Cmd;

Here's an example of using C code from Java, via GraalVM.

I want to run the xxHash algorithm for some reason (I don't know anything about this algorithm, I just know I found a single-file C implementation of it). There's a Java port, but let's say there isn't for the sake of argument, so I want to run the original C version rather than doing the port myself.

I clone it from https://github.com/Cyan4973/xxHash.

I can then compile the native version.

@headius
headius / Hello.java
Last active January 19, 2018 16:56
"Hello, %s" using method handles two different ways
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
public class Hello {
private static final MethodHandles.Lookup lookup = MethodHandles.lookup();
public static void main(String[] args) throws Throwable {
System.out.println("Hello, " + args[0]);
}
@tomgibara
tomgibara / BitVectorSample.java
Created February 29, 2012 22:36
BitVector introduction
// INTRODUCTION
/**
* A BitVector is a fixed-length sequence of bits. It's an extremely
* powerful class because of the huge number of ways that it allows the
* bits to be accessed and modified. Algorithms that rely heavily on bit
* manipulation can improve their performance by reducing the frequency
* with which bit data needs to be moved between different data
* structures; they can rely on BitVector for all the bit manipulations
* they require.