Skip to content

Instantly share code, notes, and snippets.

@jteso
jteso / README
Created September 24, 2011 04:33 — forked from vangberg/README
Deploying a Sinatra app to Heroku
# Deploying a Sinatra app to Heroku
## Database
The location of the database Heroku provides can be found in the environment
variable DATABASE_URL. Check the configure-block of toodeloo.rb for an example
on how to use this.
## Server
Heroku is serving your apps with thin, with means you have all your thin goodness available,
such as EventMachine.
@jteso
jteso / DynamicTrigger.java
Created February 1, 2012 23:17
A trigger for periodic task execution with the added capability to modify runtime the period between polls.
package directlabs.integration;
import java.util.Date;
import java.util.concurrent.TimeUnit;
import org.springframework.scheduling.Trigger;
import org.springframework.scheduling.TriggerContext;
import org.springframework.util.Assert;
/**
@jteso
jteso / JacksonUtils.java
Created February 2, 2012 03:04
The two most used utility methods to convert Java Pojos from/to Json.
package directlabs.extra;
import java.io.StringWriter;
import java.io.Writer;
import org.codehaus.jackson.map.ObjectMapper;
import org.springframework.util.Assert;
/**
* The two most used utility methods to convert Java Pojos from/to Json.
@jteso
jteso / HdfsOutboundEndpoint.java
Created February 3, 2012 05:23
Spring Integration Outbound adapter to write files into HDFS (Hadoop file System).
package directlabs.experimental;
import org.apache.commons.lang.exception.ExceptionUtils;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FSDataOutputStream;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.springframework.integration.Message;
import org.springframework.integration.handler.AbstractMessageHandler;
import org.springframework.util.Assert;
@jteso
jteso / META-INF
Created February 6, 2012 03:33
Steps required to package your own SI adaptor for reuse
META-INF/spring.handlers
------------------------
http\://jteso.com/schema/integration=directlabs.experimental.springintegration.customadapters.outbound.config.TerminalMessagingNamespaceHandler
META-INF/spring.schemas
-----------------------
http\://jteso.com/schema/integration/jteso-integration-1.0.xsd=directlabs/experimental/springintegration/customadapters/outbound/config/jteso-integration-1.0.xsd
@jteso
jteso / channels-si.md
Created February 6, 2012 05:54
Notes about SI channels

Spring Integration Channels

Point-to-Point Channel (ie. only one consumer will receive the message)

  • QueueChannel - Most basic one, receiver has to call the 'receive' method with timeout optionally
  • PriorityChannel - Allows the endpoint to receive messages in a specified priority.
  • RendezvousChannel - Sender will be bloqued until the receiver retrieves the msg from the channel
  • DirectChannel (default) - Push messages but only one receiver can obtain the message - handleMessage will be perfomed within the sender's thread before send() method returns. Transactional
  • ExecutorChannel - Similar to DirectChannel, but dispatching of the message happends in an instance of TaskExecutor (different to sender's thread), so no transactional support.
  • NullChannel - Used for testing, send() method returns TRUE and receive() method always null.
@jteso
jteso / Test.java
Created February 13, 2012 04:41
Example of REST service in spring framework 3.1
package springapp.test;
import java.io.IOException;
import org.apache.commons.httpclient.Header;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.methods.GetMethod;
@jteso
jteso / ZipFileInputFormat.java
Created February 20, 2012 05:56
How to read zip files from Map Reduce job -- Rolling your own input format (source:https://github.com/cotdp)
package com.jteso.hadoop.contrib.inputformat;
import java.io.IOException;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.BytesWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.InputSplit;
import org.apache.hadoop.mapreduce.RecordReader;
import org.apache.hadoop.mapreduce.TaskAttemptContext;
@jteso
jteso / dynamic-formset.js
Created March 20, 2012 03:08
Dynamically adding forms to a formset with jQuery in Django
function updateElementIndex(el, prefix, ndx) {
var id_regex = new RegExp('(' + prefix + '-\\d+)');
var replacement = prefix + '-' + ndx;
if ($(el).attr("for")) $(el).attr("for", $(el).attr("for").replace(id_regex, replacement));
if (el.id) el.id = el.id.replace(id_regex, replacement);
if (el.name) el.name = el.name.replace(id_regex, replacement);
}
function addForm(btn, prefix) {
var formCount = parseInt($('#id_' + prefix + '-TOTAL_FORMS').val());
@jteso
jteso / require-login-middleware.py
Created March 20, 2012 04:01
Require login middleware for Django
from django.conf import settings
from django.http import HttpResponseRedirect
import re
class RequireLoginMiddleware(object):
def __init__(self):
self.urls = tuple([re.compile(url) for url in settings.LOGIN_REQUIRED_URLS])
self.require_login_path = getattr(settings, 'LOGIN_URL', '/accounts/login/')