Skip to content

Instantly share code, notes, and snippets.

@codyaray
codyaray / private.py
Created May 31, 2011 14:45
The authentication section of Mailman's private.py
# Authorization confirmed... output the desired file
try:
ctype = content_type(path)
if mboxfile:
f = open(os.path.join(mlist.archive_dir() + '.mbox',
mlist.internal_name() + '.mbox'))
ctype = 'text/plain'
elif true_filename[-3:] == '.gz':
import gzip
f = gzip.open(true_filename, 'r')
@codyaray
codyaray / ValidatingJacksonJsonProvider.java
Created January 2, 2013 00:34
Automatic model validation using Jersey, Jackson, and Hibernate Validator
package com.mydomain.myapp.resources;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
import java.util.List;
import java.util.Set;
@codyaray
codyaray / AbstractInjectableProvider.java
Created January 3, 2013 06:54
Basic AbstractInjectableProvider for building RESTful web services with Jersey using reflection to find the Super Type Tokens. See http://codyaray.com/2013/01/finding-generic-type-parameters-with-guava for details.
package com.mydomain.myapp.resources;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import javax.ws.rs.core.Context;
import com.sun.jersey.core.spi.component.ComponentContext;
import com.sun.jersey.core.spi.component.ComponentScope;
import com.sun.jersey.server.impl.inject.AbstractHttpContextInjectable;
@codyaray
codyaray / AbstractInjectableProvider.java
Created January 3, 2013 06:57
Simplified AbstractInjectableProvider for building RESTful web services with Jersey using Guava to find the generic parameter types. See http://codyaray.com/2013/01/finding-generic-type-parameters-with-guava for details.
package com.mydomain.myapp.resources;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import javax.ws.rs.core.Context;
import com.google.common.reflect.TypeToken;
import com.sun.jersey.core.spi.component.ComponentContext;
@codyaray
codyaray / AbstractXmlReader.java
Created January 3, 2013 07:13
Simple AbstractXmlReader for building RESTful web services with Jersey using Guava to find the generic parameter types. See http://codyaray.com/2013/01/finding-generic-type-parameters-with-guava for details.
package com.mydomain.myapp.resources.xml;
import java.io.IOException;
import java.io.InputStream;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.ext.MessageBodyReader;
@codyaray
codyaray / CompositeX509KeyManager.java
Last active March 5, 2024 16:37
A composite KeyManager for doing SSL in Java with multiple keystores. See http://codyaray.com/2013/04/java-ssl-with-multiple-keystores
package com.mycompany.ssl;
import java.net.Socket;
import java.security.Principal;
import java.security.PrivateKey;
import java.security.cert.X509Certificate;
import java.util.List;
import javax.annotation.Nullable;
import javax.net.ssl.X509KeyManager;
@codyaray
codyaray / get_cheesies_followers_count.sh
Created January 4, 2014 18:40
Periodically checks a Twitter user's follower count and displays it as a Growl notification. http://codyaray.com/2014/01/hacking-twitter-competitions-automatically-tracking-followers-count
PATH=$PATH:/usr/bin/:/usr/local/bin/:$HOME/bin
curl -s "https://api.twitter.com/1.1/users/show.json?screen_name=Cheesies_Truck" \
-H "Authorization: Bearer <token>" \
| jq ".followers_count" \
| xargs -I {} growlnotify -t "Cheesies Count is {}"
@codyaray
codyaray / BinaryToString.java
Last active August 29, 2015 13:57
Storm trident function to parse metrics from JSON
// Copyright 2014 BrightTag, Inc. All rights reserved.
package com.brighttag.storm.utils;
import backtype.storm.tuple.Values;
import storm.trident.operation.BaseFunction;
import storm.trident.operation.TridentCollector;
import storm.trident.tuple.TridentTuple;
/**
* Converts the first tuple from a byte array into a string.
@codyaray
codyaray / MyTopology.java
Created May 15, 2014 15:31
Best practice to randomly shard data between multiple TridentStates
List<StateFactory> factories = Lists.newArrayListWithCapacity(mongoHosts.size());
for (String host : mongoHosts) {
factories.add(MongoStateFactory.opaque(host, mongoDatabase));
}
StateFactory stateFactory = new RandomShardState.Factory(factories);
@codyaray
codyaray / StormParallelism.java
Created May 22, 2014 23:52
The Big-4 Rules of Storm Tuning
// Copyright 2014 BrightTag, Inc. All rights reserved.
package com.brighttag.storm.utils;
import static com.google.common.base.Preconditions.checkArgument;
/**
* Computes the parallelism for a particular topology and machine configuration.
*
* @author codyaray
* @since 4/21/2014