Skip to content

Instantly share code, notes, and snippets.

View sfalquier's full-sized avatar

Sébastien FALQUIER sfalquier

View GitHub Profile
@sfalquier
sfalquier / KafkaPartitioner.scala
Last active November 11, 2020 15:50
Kafka Custom Partitioner
import kafka.producer._
import kafka.utils._
import java.util._
import java.text._
import java.util.concurrent.atomic._
class KafkaPartitioner(props: VerifiableProperties = null) extends Partitioner {
val counter = new AtomicInteger(0)
val batch = new AtomicInteger(0)
@sfalquier
sfalquier / RandomPhoto.js
Created September 10, 2012 05:28
Radom photo picked up in a Facebook Page albums
<script type="text/javascript">
window.onload = function main()
{
var script = document.createElement("script");
script.src = "https://graph.facebook.com/platform/albums?callback=getalbum";
document.getElementsByTagName("head")[0].appendChild(script);
}
function getalbum(facebook) {
var randomalbum = Math.floor(Math.random()*(facebook.data.length));
@sfalquier
sfalquier / loadXMLFromString.java
Created September 3, 2012 08:43
load W3C xml Document object from a String
public static org.w3c.dom.Document loadXMLFromString(String xml)
throws org.xml.sax.SAXException, java.io.IOException {
return loadXMLFrom(new java.io.ByteArrayInputStream(xml.getBytes()));
}
public static org.w3c.dom.Document loadXMLFrom(java.io.InputStream is)
throws org.xml.sax.SAXException, java.io.IOException {
javax.xml.parsers.DocumentBuilderFactory factory = javax.xml.parsers.DocumentBuilderFactory
.newInstance();
factory.setNamespaceAware(true);
@sfalquier
sfalquier / memcached_symfony.php
Created July 5, 2012 08:02
Memcached in Symfony2
//file app/config/parameters.ini
[parameters]
memcached_host = 127.0.0.1
memcached_port = 11211
memcached_key_root = mykey
memcached_object_ttl = 60
//file src/MyApp/MyBundle/Resources/config/services.yml
parameters:
memcached.servers:
@sfalquier
sfalquier / SimpleMessageConsumer.java
Created January 6, 2012 08:33
SimpleMessageConsumer to receive a simple String from a queue using ApacheMQ
import javax.jms.Connection;
import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.Session;
import org.apache.activemq.ActiveMQConnectionFactory;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.listener.SimpleMessageListenerContainer;
@sfalquier
sfalquier / SimpleMessageProducer.java
Created January 6, 2012 08:28
SimpleMessageProducer to send a simple String to a queue using ApacheMQ
import java.util.Date;
import javax.jms.Connection;
import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.Session;
import javax.jms.TextMessage;
import org.apache.activemq.ActiveMQConnectionFactory;