Skip to content

Instantly share code, notes, and snippets.

@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 / 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=`
-- 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)
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({
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'
};
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");
}
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];