Skip to content

Instantly share code, notes, and snippets.

View kragen's full-sized avatar

Kragen Javier Sitaker kragen

View GitHub Profile

This is slightly munged jstack output from a .find() of a Java regular expression that looks like some initial stuff some stuff (\d+) some more stuff (foo|bar) some more sstuff (\d+) being matched against a logfile line of around 100 characters.

"main" prio=10 tid=0x0000000000f31800 nid=0x523e runnable [0x00007f7ece452000]
   java.lang.Thread.State: RUNNABLE
at java.util.regex.Pattern$Curly.match(Pattern.java:3761)
at java.util.regex.Pattern$GroupHead.match(Pattern.java:4185)
at java.util.regex.Pattern$Slice.match(Pattern.java:3499)
at java.util.regex.Pattern$GroupTail.match(Pattern.java:4244)
at java.util.regex.Pattern$BranchConn.match(Pattern.java:4095)
at java.util.regex.Pattern$Slice.match(Pattern.java:3499)

How do I dynamically generate bytecode?

Aside from understanding the JVM bytecode (for which javap -c, javap -c -private, and chapter 6 of the JVM spec are helpful), there’s the question of how to get from a plan for code to generate to actually being able to run the code on the JVM, as described in [chapter 5][] of the JVM spec.

@kragen
kragen / gist:69bafe7c98d70e3181c7
Created June 5, 2015 20:17
If an opinion doesn't touch the question of when violence is justifiable, it's not a political opinion.

I claimed, "If an opinion doesn't touch the question of when violence is justifiable, it's not a political opinion.". Brian Mastenbrook asked, "Doesn't this imply that there are no politics amongst anarchists?" As I understand it, the underpinning of this question is that anarchists do not accept or consider justifiable the kinds of state violence that everyone else considers not only justifiable but usually morally obligatory.

Leaving aside current deep philosophical differences among anarchists about the question of when non-state violence may or may not be justifiable, I think the discussions we normally characterize as political still, usually, boil down to questions of violence.

Of course, the most usual example of politics is entirely, 100%, about when violence is justifiable: it concerns either what policies the State is to enforce using its Westphalian monopoly on justifiable violence, or who will make that decision. Taking as an the example

@kragen
kragen / micromousetrap.js
Created June 8, 2015 23:20
A JavaScript micro-library for cross-browser keyboard event handling.
// This is an attempt to paper over the keycode differences between
// Gecko and WebKit (e.g. Iceweasel or Firefox and Chrome or
// Chromium), somewhat following the model of Mousetrap:
// <https://github.com/ccampbell/mousetrap>.
// The mapping tables herein are far from comprehensive, implementing
// more or less only what I need for this calculator.
function decodeKeyEvent(event) {
return decodeKeyEventProperties(event.key, event.keyCode, event.shiftKey);
}
@kragen
kragen / gist:cbf6ddc77826a8c47591
Created June 9, 2015 09:22
a command-line game
: user@debian:~/devel/dev3; ./guess
I’ve chosen a number from 0 to 100. Try to guess it.
: user@debian:~/devel/dev3; ./guess 50
Your guess is too big!
: user@debian:~/devel/dev3; ./guess 25
Your guess is too small!
: user@debian:~/devel/dev3; ./guess 37
Your guess is too big!
: user@debian:~/devel/dev3; ./guess 31
: user@debian:~/devel/dev3; cat modtree.py
#!/usr/bin/python
import sys
def main((_, modname,)):
showed = set()
for depth, name, filename in mod_tree(__import__(modname)):
print ' ' * 4 * depth, name, filename if name not in showed else ''
showed.add(name)
@kragen
kragen / gist:dc93d2756747f63f333d
Created August 9, 2015 00:29
guix 0.8.1 failing
patch-shebang: /gnu/store/p5k561811xx6ipqqiz5anz5qjqhfdaa4-gzip-1.6/bin/znew: changing `/gnu/store/nx4zd42igyb7ghmv4mxv6ncg8wr7ypa1-bash-4.3.33/gnu/store/nx4zd42igyb7ghmv4mxv6ncg8wr7ypa1-bash-4.3.33/bin/bash' to `/gnu/store/nx4zd42igyb7ghmv4mxv6ncg8wr7ypa1-bash-4.3.33/bin/bash'
phase `patch-shebangs' succeeded after 0 seconds
starting phase `strip'
stripping binaries in "/gnu/store/p5k561811xx6ipqqiz5anz5qjqhfdaa4-gzip-1.6/bin" with "strip" and flags ("--strip-debug")
phase `strip' succeeded after 0 seconds
starting phase `validate-documentation-location'
phase `validate-documentation-location' succeeded after 0 seconds
starting phase `compress-documentation'
compressing documentation in '/gnu/store/p5k561811xx6ipqqiz5anz5qjqhfdaa4-gzip-1.6/share/man' with "gzip" and flags ("--best" "--no-name")
compressing documentation in '/gnu/store/p5k561811xx6ipqqiz5anz5qjqhfdaa4-gzip-1.6/share/info' with "gzip" and flags ("--best" "--no-name")
private Flaunch(OrderManager om,
List<Duration> taus,
List<Duration> futureTimes,
long samplingInterval) {
this.om = om;
this.samplingInterval = samplingInterval;
for (Duration tau : taus) {
filters.add(ExponentialFilter.create(tau));
}
forwardDeltas = new long[futureTimes.size()];
test 0046...[HTTP, get cookies and store in cookie jar]
46: protocol FAILED:
--- log/check-expected 2015-08-11 20:26:26.601137712 +0000
+++ log/check-generated 2015-08-11 20:26:26.601137712 +0000
@@ -1,5 +1,5 @@
GET /want/46 HTTP/1.1[CR][LF]
Host: 127.0.0.1:8990[CR][LF]
Accept: */*[CR][LF]
-Cookie: empty=; mooo2=indeed2; mooo=indeed[CR][LF]
# Ruby assembler DSEL, following tqbf’s unreleased one:
# http://news.ycombinator.com/item?id=378457
$assembly_output = nil
class Program
def initialize() @contents = [] end
def add() $assembly_output = self; yield end
def append(something) @contents.push(something) end
end