Skip to content

Instantly share code, notes, and snippets.

John Ellis deckerego

Block or report user

Report or block deckerego

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@deckerego
deckerego / odd_http_traffic_patterns.r
Created Dec 6, 2013
If you consider aberrant traffic hit rates ones that are more or equal to two standard deviations away from the mean
View odd_http_traffic_patterns.r
# Massage your data into a data frame that provides access by Hour and URI
traffic.df <- parse.log("access.log") #parse.log is left as an exercise for the reader
# Aggregate
uri.hits <- ddply(traffic.df, .(Hour, URI), summarise, Hits=length(URI), .parallel = TRUE)
uri.stats <- ddply(uri.hits, .(URI), summarise, Mean=mean(Hits), Variance=sd(Hits), Total=sum(Hits), .parallel = TRUE)
uri.stats <- join(uri.hits, uri.stats, c("URI"))
# Find two std dev away from mean
uri.bad <- subset(uri.stats, Variance > 0)
@deckerego
deckerego / rabbitmq_stats.r
Created Dec 6, 2013
Reading RabbitMQ Message Statistics
View rabbitmq_stats.r
queueStatsToDataframe <- function(uri, username, password) {
uri <- paste(uri, "api/queues", sep="/")
credentials = paste(username, password, sep=":")
doc <- getURL(uri, userpwd=credentials, httpauth=1L)
src <- fromJSON(doc)
items.df <- data.frame()
if(length(src) > 0) {
for(i in 1:length(src)) {
if(length(src[[i]]$messages_details) == 3) {
@deckerego
deckerego / auth_untrusted_ssl.r
Created Dec 6, 2013
Authenticating Over an Untrusted SSL Connection
View auth_untrusted_ssl.r
getContents <- function(uri, username, password) {
credentials = paste(username, password, sep=":")
doc <- getURL(uri, userpwd=credentials, httpauth=1L, ssl.verifypeer = FALSE)
}
@deckerego
deckerego / rss_df.r
Created Dec 6, 2013
Reading an RSS XML Feed as a Dataframe
View rss_df.r
rssToDataframe <- function(uri) {
doc <- getURL(uri)
doc <- xmlParse(doc)
src <- xpathApply(doc, "/rss/channel/item")
items.df <- data.frame()
if(length(src) > 0) {
for(i in 1:length(src)) {
item <- xmlSApply(src[[i]], xmlValue)
record.df <- data.frame(t(item), stringsAsFactors=FALSE)
@deckerego
deckerego / rss_atom_df.r
Created Dec 6, 2013
Reading an RSS Atom Feed as a Dataframe
View rss_atom_df.r
atomToDataframe <- function(uri) {
doc <- getURL(uri)
doc <- xmlParse(doc)
src <- getNodeSet(doc, "/d:feed/d:entry", c(d = "http://www.w3.org/2005/Atom"))
items.df <- data.frame()
if(length(src) > 0) {
for(i in 1:length(src)) {
item <- xmlSApply(src[[i]], xmlValue)
record.df <- data.frame(t(item), stringsAsFactors=FALSE)
@deckerego
deckerego / DatabaseTester.java
Created Dec 6, 2013
DBUnit is oooooooooooooooold and hasn't been updated in forever, but still quasi-useful. It never had an official way of loading spreadsheets based on the absolute path of a flie name; paths were always relative to its own class context. Snippets load a spreadsheet using DBUnit specified by an absolute file path, and then demonstrate what a setu…
View DatabaseTester.java
private static IDatabaseTester databaseTester;
@Resource
protected ComboPooledDataSource dataSource;
@Before //You can use @BeforeClass if dataSource isn't loaded by dependency injection
public void setupDatabase() throws Exception {
if(databaseTester == null) { //Only load once, this can be removed if using @BeforeClass
databaseTester = new DataSourceDatabaseTester(dataSource);
IDataSet dataSet = new XlsDataFileLoader().load("TestDAO-data.xls");
databaseTester.setDataSet(dataSet);
@deckerego
deckerego / TestServlet.java
Created Dec 6, 2013
Unit testing a Servlet managed by Spring
View TestServlet.java
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration()
public class TestServlet {
private HttpServlet servlet;
@Resource
protected ApplicationContext applicationContext;
@Before
public void initServlet() throws Exception {
StaticWebApplicationContext webContext = new StaticWebApplicationContext();
@deckerego
deckerego / HashCode.java
Created Dec 6, 2013
Several hashcode implementations (including the one within the Java foundation classes) relies on integer overflows to have predictable behavior. This assumption prevents these hashcode implementations from being portable, since integer overflows result in different values across runtime environments. The following hashcode implementation does n…
View HashCode.java
@Override
public int hashCode() {
int hash = 0, buffer = 0;
int modulo, logicalShiftLeft;
for(int index = 0, max = this.stringProperty.length(); index < max; ++index) {
modulo = index % 4;
logicalShiftLeft = 8 * modulo;
buffer += this.stringProperty.charAt(index) << logicalShiftLeft;
if(modulo == 3) {
@deckerego
deckerego / management.jmxremote.password
Created Dec 6, 2013
Enabling Remote JMX with Plaintext Authentication
View management.jmxremote.password
monitorRole readOnlyPassword
controlRole adminPassword
@deckerego
deckerego / LookupJini.java
Created Dec 6, 2013
Looking Up a Jini Service Entry, with thanks to Shay at the GigaSpaces forums ( http://forum.openspaces.org/thread.jspa?messageID=10328 )
View LookupJini.java
LookupCache getLookupCache(String host, Class template) {
if (System.getSecurityManager() == null)
System.setSecurityManager(new RMISecurityManager());
LookupLocator primaryRegistrar = new LookupLocator(host);
LookupDiscoveryManager discoveryManager =
new LookupDiscoveryManager(null, new LookupLocator[] {primaryRegistrar}, null);
ServiceDiscoveryManager serviceDiscoveryManager =
new ServiceDiscoveryManager(discoveryManager, new LeaseRenewalManager());
ServiceTemplate serviceTemplate = new ServiceTemplate(null, new Class[] {template}, null);
You can’t perform that action at this time.