Skip to content

Instantly share code, notes, and snippets.

public class LexiSortable {
// Lookup table to find hex digits from bytes.
private final static char[] HEX_DIGITS = {
'0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', 'A', 'B', 'C', 'D', 'E', 'F'
};
// Lookup table to find bytes from hex digits.
private final static byte[] BYTE_LOOKUP = new byte['F' + 1];
public static String toLexiSortable(final double d) {
long tmp = Double.doubleToRawLongBits(d);
return toHexString('d', (tmp < 0) ? ~tmp : (tmp ^ SIGN_MASK));
}
public static double doubleFromLexiSortable(final String s) {
if (!s.startsWith("d")) {
throw new IllegalArgumentException(s
+ " does not represent a double");
}
import java.util.Arrays;
import java.util.Random;
public class LexiSortable {
// Converting to hex is fast and easy
private final static char[] HEX_DIGITS = {
'0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', 'A', 'B', 'C', 'D', 'E', 'F'
};
package org.jdiscript
import org.jdiscript.handlers.*
import org.jdiscript.util.VMSocketAttacher
import com.sun.jdi.*
VirtualMachine vm = new VMSocketAttacher(12345).attach()
JDIScript j = new JDIScript(vm)
j.monitorContendedEnterRequest({
-- Full precision summation based on http://code.activestate.com/recipes/393090/
msum :: [Double] -> Double
msum [] = 0
msum (x:xs) = sum $ foldl' (\ps x' -> reverse (partials x' ps)) [x] xs
partials :: Double -> [Double] -> [Double]
partials x = foldl' (\acc p -> case hilo x p of (hi, 0) -> hi:acc
(hi, lo) -> hi:lo:acc) []
hilo :: Double -> Double -> (Double, Double)
@jfager
jfager / gist:2976645
Created June 23, 2012 03:25
shared bash profile via dropbox
alias sha1='openssl dgst -sha1'
SHARED_BASH_REMOTE=~/path/to/dropbox/shared_bash.sh
SHARED_BASH_TMP=~/.bash_shared.sh.tmp
SHARED_BASH_LOCAL=~/.bash_shared.sh
if [ -f $SHARED_BASH_REMOTE ]; then
cp $SHARED_BASH_REMOTE $SHARED_BASH_TMP
if [ -f $SHARED_BASH_LOCAL ]; then
SHARED_LOCAL_SHA=`sha1 $SHARED_BASH_LOCAL | cut -f2 -d=`
SHARED_TMP_SHA=`sha1 $SHARED_BASH_TMP | cut -f2 -d=`
@jfager
jfager / simple_server.rs
Last active December 18, 2015 09:59
Writing a websocket server in Rust, ran into an issue where the server would hang after a few connection attempts. Here's a minimal client/server; in the server, if you uncomment the separate spawned task on the default scheduler, the hang always happens. Putting that other task on its own thread makes everything work fine.
extern mod extra;
use std::{int,io,result};
use extra::{net,net_tcp,uv};
fn main() {
let (accept_port, accept_chan) = stream();
let (finish_port, finish_chan) = stream();
let addr = extra::net_ip::v4::parse_addr("127.0.0.1");
@jfager
jfager / segfaulting_server.rs
Last active December 18, 2015 13:09
Run segfaulting_server with 'rustc segfaulting_server.rs && export RUST_LOG=extra::net_tcp=debug && ./segfaulting_server', then run the client. The server will segfault after the 3rd client request. If you comment out lines 43 & 44, everything works great.
extern mod extra;
use std::{int,io,result,task};
use extra::{net,net_tcp,uv};
fn server(outer_ch: Chan<Chan<~str>>) {
let (accept_port, accept_chan) = stream();
let (finish_port, finish_chan) = stream();
let addr = extra::net_ip::v4::parse_addr("127.0.0.1");
#include<stdio.h>
main() {
long long a = -9223372036854775808;
long long b = a * -1;
printf("%lld\n", b);
}
fn ip6_to_str(ip6: &[u8]) -> ~str {
let f = u8::to_str_radix;
return fmt!("%s%s:%s%s:%s%s:%s%s:%s%s:%s%s:%s%s:%s%s",
f(ip6[ 0], 16), f(ip6[ 1], 16),
f(ip6[ 2], 16), f(ip6[ 3], 16),
f(ip6[ 4], 16), f(ip6[ 5], 16),
f(ip6[ 6], 16), f(ip6[ 7], 16),
f(ip6[ 8], 16), f(ip6[ 9], 16),
f(ip6[10], 16), f(ip6[11], 16),
f(ip6[12], 16), f(ip6[13], 16),