Skip to content

Instantly share code, notes, and snippets.

View stickfigure's full-sized avatar

Jeff Schnitzer stickfigure

  • Winters, CA
View GitHub Profile
@stickfigure
stickfigure / RefSerializer.java
Created April 17, 2012 04:46
Jackson forgets @JSONVIEW when serializing through RefSerializer
public class RefSerializer extends JsonSerializer<Ref> {
@Override
public void serialize(Ref value, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonProcessingException {
jgen.writeObject(value.getValue());
}
}
@stickfigure
stickfigure / sample.java
Created April 18, 2012 17:29
Saving the description of an event
/**
* Edit the description of an event.
*/
@AuthRequired
@POST
@Path("/event/description")
@Produces(MediaTypeUTF8.APPLICATION_JSON)
@JsonView(Event.JsonAll.class)
public Event saveDescription(final @FormParam("event") Key<Event> eventKey, final @FormParam("editor") String description) {
@stickfigure
stickfigure / gist:6201192
Created August 10, 2013 17:04
Ant snippet for GAE rolling deployment
<target name="deploy-prod" depends="auth, optimize">
<property name="appid" value="theappid" />
<tstamp>
<format property="vnum" pattern="yyyy-MM-dd-HHmm"/>
</tstamp>
<echo message="Deploying to version: ${vnum}" />
<appcfg action="update" war="${staging.dir}">
<options>
@stickfigure
stickfigure / RewriteDataTask.java
Last active August 29, 2015 13:57
App Engine tasks which rewrite data for a single entity type
package blah;
import com.google.appengine.api.taskqueue.DeferredTask;
import com.google.common.base.Function;
import com.google.common.collect.Iterables;
import com.googlecode.objectify.Key;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import st.voo.tick.Queues;
/*
*/
package st.voo.tick.entity.util;
import com.googlecode.objectify.Key;
import com.googlecode.objectify.Ref;
/**
* A simple way to remove some boilerplate from some entity.
@stickfigure
stickfigure / MissingDataTests.java
Created May 15, 2014 16:56
Show that missing data is ignored
/**
* Tests of what happens when some data is missing in the db
*
* @author Jeff Schnitzer <[email protected]>
*/
public class MissingDataTests extends TestBase
{
@com.googlecode.objectify.annotation.Entity
static class Foo {
@Id
@stickfigure
stickfigure / GuiceResteasyFilterDispatcher.java
Created April 26, 2015 17:51
A better way to integrate Guice and Resteasy
package com.example;
import com.google.inject.Injector;
import org.jboss.resteasy.plugins.guice.ModuleProcessor;
import org.jboss.resteasy.plugins.server.servlet.FilterDispatcher;
import org.jboss.resteasy.spi.Registry;
import org.jboss.resteasy.spi.ResteasyProviderFactory;
import javax.inject.Inject;
import javax.inject.Singleton;
import javax.servlet.FilterConfig;
@stickfigure
stickfigure / MoneyDeserializer.java
Last active June 4, 2021 22:36
Jackson serializer and deserializer for Joda Money
package com.orbitkit.houston.util.json;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
import com.example.MoneySerializer.MoneyJson;
import org.joda.money.CurrencyUnit;
import org.joda.money.Money;
@stickfigure
stickfigure / Scatter.java
Created November 10, 2015 22:43
Scatter mapping using Objectify
package com.foo.housekeeping;
import com.google.appengine.api.datastore.Entity;
import com.google.common.collect.Range;
import com.googlecode.objectify.Key;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import static com.googlecode.objectify.ObjectifyService.ofy;
@stickfigure
stickfigure / cloak.js
Created May 24, 2020 05:42
Cloudflare worker that proxies encrypted urls
addEventListener('fetch', event => {
event.respondWith(handleRequest(event.request))
})
const encoder = new TextEncoder();
const decoder = new TextDecoder();
const SECRET_KEY_DATA = encoder.encode('YOUR SECRET KEY');
function normalizeBase64(base64urlencoded) {
return base64urlencoded.replace(/-/g, '+').replace(/_/g, '/');