Skip to content

Instantly share code, notes, and snippets.

@oxtoacart
oxtoacart / AmazonRedirector.java
Created August 29, 2013 20:18
HttpRequestFilter is currently applied after we've determined the downstream server based on the host header. It would be neat to have the option of applying request filters on the way in, such that the host header can be modified. This test shows an example of how one might use that, provided by Marco Palladino.
package org.littleshoot.proxy;
import io.netty.handler.codec.http.HttpRequest;
import io.netty.handler.codec.http.HttpResponse;
/**
* <p>
* This is based on some code from Marco Palladino that was giving him trouble.
* Use the below command to test:
* </p>
@oxtoacart
oxtoacart / selfloops.js
Created September 4, 2013 15:53
Snippet for generating self-loops on Lantern map
// Use this in place of the existing pathConnection defined in vis.js
$scope.pathConnection = function (peer) {
var pSelf = projection([model.location.lon, model.location.lat]),
pPeer = projection([peer.lon, peer.lat]),
xS = pSelf[0], yS = pSelf[1], xP = pPeer[0], yP = pPeer[1];
var distanceBetweenPeers = Math.sqrt(Math.pow(xS - xP, 2) + Math.pow(yS - yP, 2));
if (distanceBetweenPeers < 30) {
// Peer and self are very close, draw a loopy arc
@oxtoacart
oxtoacart / SystemTrayImpl.java
Created September 6, 2013 15:47
This is a first cut at eliminating the SWT system tray stuff. It runs on OS X, but hasn't been thoroughly tested.
package org.lantern;
import java.awt.AWTException;
import java.awt.Image;
import java.awt.MenuItem;
import java.awt.PopupMenu;
import java.awt.TrayIcon;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.awt.Desktop;
import java.net.URI;
import java.net.URLEncoder;
public class TestMailto {
public static void main(String[] args) throws Exception {
String recipient = "ox@getlantern.org";
String subject = URLEncoder
.encode("Join the Lantern Network to Circumvent Censorship");
String body = URLEncoder
# FTE-Powered echo server program
import socket
import fte
client_server_regex = '^GET\\ \\/([a-zA-Z0-9\\.\\/]*) HTTP/1\\.1\\r\\n\\r\\n$'
server_client_regex = '^HTTP/1\\.1\\ 200 OK\\r\\nContent-Type:\\ ([a-zA-Z0-9]+)\\r\\n\\r\\n\\C*$'
HOST = '' # Symbolic name meaning all available interfaces
PORT = 50008 # Arbitrary non-privileged port
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
# FTE-Powered echo client program
import socket
import fte
client_server_regex = '^GET\\ \\/([a-zA-Z0-9\\.\\/]*) HTTP/1\\.1\\r\\n\\r\\n$'
server_client_regex = '^HTTP/1\\.1\\ 200 OK\\r\\nContent-Type:\\ ([a-zA-Z0-9]+)\\r\\n\\r\\n\\C*$'
HOST = '127.0.0.1' # The remote host
PORT = 50007 # The same port as used by the server
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
# FTE-Powered echo client program
import socket
import fte
import random
import string
def random_string(size):
"""Return a random alphanumeric string of length ``size``."""
chars = string.ascii_uppercase + string.digits
return ''.join(random.choice(chars) for x in range(size))
@oxtoacart
oxtoacart / datum.pb.go
Created June 30, 2014 03:02
Benchmark of JSON, Protocol Buffers and MsgPack in Go
// Code generated by protoc-gen-go.
// source: datum.proto
// DO NOT EDIT!
/*
Package sbenchmark is a generated protocol buffer package.
It is generated from these files:
datum.proto
<!-- This is a simple test of the stat server in flashlight -->
<html>
<head>
<script type="text/javascript">
var source = new EventSource('http://127.0.0.1:15670/');
source.addEventListener('message', function(e) {
console.log(e.data);
}, false);
package main
import (
"crypto/tls"
"crypto/x509"
"fmt"
"io"
"log"
"net"
"net/http"