Skip to content

Instantly share code, notes, and snippets.

Avatar

Christopher Currie christophercurrie

View GitHub Profile
@christophercurrie
christophercurrie / Polymorph.java
Created Feb 11, 2014
Example of Polymorphic Deserialization using Jackson
View Polymorph.java
import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.fasterxml.jackson.databind.PropertyNamingStrategy;
import com.fasterxml.jackson.databind.annotation.JsonNaming;
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type")
@JsonSubTypes({
@JsonSubTypes.Type(value=AudioAttachment.class, name="audio"),
@JsonSubTypes.Type(value=LinkAttachment.class, name="link")
View keybase.md

Keybase proof

I hereby claim:

  • I am christophercurrie on github.
  • I am chriscurrie (https://keybase.io/chriscurrie) on keybase.
  • I have a public key ASCCB_YofVMqzc8YHie8ApdSQkyHJ8ERSI8g17UxbLtW3go

To claim this, I am signing this object:

@christophercurrie
christophercurrie / package.json
Created Jul 20, 2018
Package installs with warnings
View package.json
{
"name": "test",
"version": "1.0.0",
"description": "foo",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
View package-lock-bad.json
{
"name": "test",
"version": "1.0.0",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
"@semantic-release/commit-analyzer": {
"version": "4.0.1",
"resolved": "https://registry.npmjs.org/@semantic-release/commit-analyzer/-/commit-analyzer-4.0.1.tgz",
"integrity": "sha512-mbyk+KPnI2UesHC1Az21CTZjzoGkzFm3w9qGKxifkmaAPMObKmbD6tPLwcFu8Bz5h08xG5yjtp1K0Pb3AKk+Dw==",
View gist:3841860
@Override
public ServletContainer getJerseyContainer(DropwizardResourceConfig resourceConfig,
MyServiceConfig serviceConfig) {
// I like having a root module, but you can use as many as you like
final Injector injector = Guice.createInjector(new MyServiceModule(serviceConfig));
return new GuiceContainer(injector) {
@Override
public ResourceConfig getDefaultResourceConfig(Map<String,Object> props, WebConfig webConfig) {
@christophercurrie
christophercurrie / CustomObjectMapperProvider.scala
Created Jan 8, 2014
Example of implementing a custom Jackson object mapper provider for Scala
View CustomObjectMapperProvider.scala
import javax.ws.rs.ext.{ContextResolver, Provider}
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.module.scala.DefaultScalaModule
@Provider
class CustomObjectMapperProvider extends ContextResolver[ObjectMapper] {
def getContext(tpe: Class[_]): ObjectMapper = {
if (tpe != classOf[ObjectMapper]) null
else {
val m = new ObjectMapper()
@christophercurrie
christophercurrie / authenticate.java
Last active Dec 21, 2015
Example of different authenticators in dropwizard
View authenticate.java
abstract class MyPrincipal {};
class BasicAuthPrincipal extends MyPrincipal {};
class OAuthPrincipal extends MyPrincipal {};
class BasicAuthenticator implements Authenticator<BasicCredentials, BasicAuthPrincipal> {
public Optional<BasicAuthPrincipal> authenticate(BasicCredentials creds) {
return new BasicAuthPrincipal();
}
};
@christophercurrie
christophercurrie / JsonUnwrappedTest.java
Created Jul 13, 2013
Example demonstrating complexities of JsonUnwrapped
View JsonUnwrappedTest.java
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonUnwrapped;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.Test;
import java.io.IOException;
class JAddress {
View BitmapDecoder bug
Known issue: Stream opened for Uri is not closed until finalized unless BitmapCacheOption.OnLoad set
Both overloads of this method contain a bug, where a stream is opened for the Uri, which is not closed until the bitmap decoder is finalized, unless BitmapCacheOption.OnLoad is set. Since there is no Dispose() method, there is no way to force closing the stream, except for removing all references to the BitmapDecoder, and forcing finalization using GC.Collect().
The workaround is to use the overload that takes a Stream, and dispose of the stream after you are done with the Decoder.
http://connect.microsoft.com/VisualStudio/feedback/details/344914/bitmapdecoder-not-releasing-file-lock
@christophercurrie
christophercurrie / AsyncDownloadQueue.cs
Last active Dec 18, 2015
Various attempts at implementing an asynchronous download processor.
View AsyncDownloadQueue.cs
internal class BoundedAsyncDownload1
{
private const int MaxRequests = 4;
private void HandleResponse(WebResponse response)
{ }
private void CreateRequest(ConcurrentQueue<WebRequest> queue)
{
WebRequest request;