Skip to content

Instantly share code, notes, and snippets.

View mgodave's full-sized avatar
🤟

Dave Rusek mgodave

🤟
  • ex-Twitter
  • Denver, CO
  • 18:00 (UTC -06:00)
View GitHub Profile
@mgodave
mgodave / gist:871002
Created March 15, 2011 16:42
Infinite Sequence of packets from capture interface
(ns netflow.packet
(:import jpcap.JpcapCaptor)
(:import jpcap.packet.Packet))
(def captor (JpcapCaptor/openFile "mytrace.pcap"))
(defn packet-seq [captor]
(let [packet (.getPacket captor)]
(when-not (= (Packet/EOF) packet)
(lazy-seq (cons packet (packet-seq captor))))))
@mgodave
mgodave / gist:871978
Created March 16, 2011 03:46
Using java.io.FileDescriptor
;; Problem: I have a raw file descriptor, from a parent process and I need to read from it:
(import java.io.FileDescriptor)
(import java.io.FileInputStream)
(def fdfield (.getDeclaredField (Class/forName "java.io.FileDescriptor") "fd"))
(def fd (FileDescriptor.))
(.setInt fdfield fd 10)
(FileInputStream. fd)
@mgodave
mgodave / gist:876561
Created March 18, 2011 18:19
Create flows from a stream of packets
;;WARNING: UNTESTED
(ns flows
(:import jpcap.JpcapCaptor))
(defrecord flow-tuple :src-ip :dst-ip :src-port :dst-port :protocol)
(defrecord flow :flow-tuple :octets :first-update :last-update)
(comment
(defprotocol CaptureProtocol
@mgodave
mgodave / gist:1806160
Created February 12, 2012 04:06
portaudio paex_record.c java jna port
/**
* Created by IntelliJ IDEA.
* User: drusek
* Date: 2/10/12
* Time: 12:40 PM
* To change this template use File | Settings | File Templates.
*/
import com.sun.jna.*;
import com.sun.jna.ptr.PointerByReference;
@mgodave
mgodave / logging.h
Created March 1, 2012 18:30
Logging to j.u.Logger from JNI
#ifndef __LOGGING_H__
#define __LOGGING_H__
#include <jni.h>
typedef enum {
SEVERE = 0,
WARNING,
INFO,
FINE,
import org.junit.Test;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import static org.junit.Assert.assertFalse;
/**
import com.google.common.util.concurrent.*;
import org.apache.commons.dbcp.cpdsadapter.DriverAdapterCPDS;
import org.apache.commons.dbcp.datasources.SharedPoolDataSource;
import org.apache.commons.dbutils.AsyncQueryRunner;
import org.apache.commons.dbutils.ResultSetHandler;
import javax.sql.DataSource;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.concurrent.ThreadPoolExecutor;
/**
* Copyright 2013 David Rusek <dave.rusek@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
package org.robotninjas.audio;
import com.google.common.util.concurrent.*;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import static com.google.common.util.concurrent.MoreExecutors.listeningDecorator;
@mgodave
mgodave / gist:5060406
Last active December 14, 2015 08:48
DelayedFutureTask
package org.robotninjas.audio;
import com.google.common.base.Ticker;
import com.google.common.primitives.Longs;
import java.util.concurrent.Callable;
import java.util.concurrent.Delayed;
import java.util.concurrent.FutureTask;
import java.util.concurrent.TimeUnit;