Skip to content

Instantly share code, notes, and snippets.

View christophercurrie's full-sized avatar

Christopher Currie christophercurrie

View GitHub Profile
/*=============================================================================
Copyright (c) 2001-2010 Joel de Guzman
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
=============================================================================*/
///////////////////////////////////////////////////////////////////////////////
//
// A Calculator example demonstrating generation of AST
//
@christophercurrie
christophercurrie / post-receive-redmine.sh
Created January 10, 2012 20:46 — forked from colinmollenhour/post-receive-redmine.sh
gitolite update hooks to reject CRLF line endings and require formatted commit messages
#!/bin/bash
#
# see https://github.com/kahseng/redmine_gitolite_hook/blob/master/README.rdoc
#
# The "post-receive" script is run after receive-pack has accepted a pack
# and the repository has been updated. It is passed arguments in through
# stdin in the form
# <oldrev> <newrev> <refname>
# For example:
# aa453216d1b3e49e7f6f98441fa56946ddcd6a20 68f7abf4e6f922807889f52bc043ecd31b79f814 refs/heads/master
@christophercurrie
christophercurrie / TestKeySerializer.java
Created September 21, 2012 04:26
Key Serializer caching test
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.google.common.collect.ImmutableMap;
import org.junit.Before;
import org.junit.Test;
import java.io.IOException;
@christophercurrie
christophercurrie / gist:3841860
Created October 5, 2012 19:32
Guice for Dropwizard
@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 / Install-WIF-OnAzure.ps1
Created October 8, 2012 17:19
Installing Windows Identity Foundation on Windows Azure (within a startup task)
$currentDir = (Get-Location -PSProvider FileSystem).ProviderPath
function SearchInstall($SearchVersion, $PathKey)
{
$installObjects = ls -path $PathKey;
$found = $FALSE;
foreach($installEntry in $installObjects)
{
$entryProperty = Get-ItemProperty -LiteralPath registry::$installEntry
<%def name="outer(x)">
<%def name="inner(y)">
values ${x} and ${y}
</%def>
${caller.body()}
</%def>
<%self:outer x="1">
<%self:inner y="${x + 1}" />
</%self:outer>
@christophercurrie
christophercurrie / cloudbees-jenkins-sbt.md
Created April 13, 2013 19:24
Configuring CloudBees Jenkins for SBT publishing

I want to use the CloudBees Jenkins service to build nightly snapshots of an SBT-based scala project and publish them to the Sonatype OSS Maven Repository. SBT has [two ways][credentials] of providing publishing credentials to the build; one has the credentials inline in an .sbt file (unencrypted, natch), and the other does allow for a hard-coded path to an external properties file (still, sadly, unencrypted).

CloudBees has a [mechanism][buildfiles] for providing configuration files to build agents, but I don't want to hard code the path to this location in my build.sbt, nor can I

@christophercurrie
christophercurrie / AsyncDownloadQueue.cs
Last active December 18, 2015 15:59
Various attempts at implementing an asynchronous download processor.
internal class BoundedAsyncDownload1
{
private const int MaxRequests = 4;
private void HandleResponse(WebResponse response)
{ }
private void CreateRequest(ConcurrentQueue<WebRequest> queue)
{
WebRequest request;
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 / JsonUnwrappedTest.java
Created July 13, 2013 18:58
Example demonstrating complexities of JsonUnwrapped
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 {