Skip to content

Instantly share code, notes, and snippets.

@Sennahoi
Sennahoi / WSTest.java
Last active July 5, 2016 11:42
Tomcat 7 / Maven / JAX-WS / File upload via MTOM
package upload.test;
import java.awt.Image;
import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.jws.soap.SOAPBinding.Style;
@WebService
@Sennahoi
Sennahoi / BasicAuthenticationFilter.java
Created December 11, 2015 08:08 — forked from neolitec/BasicAuthenticationFilter.java
HTTP Basic authentication Java filter
package com.neolitec.examples;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@Sennahoi
Sennahoi / python_encoding_examples.py
Created November 17, 2014 09:33
Some basic python encoding/decoding/unicode examples
string_with_utf8 = "T\xc3\xa4ter" # str, no unicode
correct_unicode = string_with_utf8.decode("utf-8") # interpret string as utf-8
print repr(correct_unicode) # T\xe4ter, correct unicode string
string_with_utf8_new = correct_unicode.encode("utf-8") # make a utf-8 str()
print repr(string_with_utf8_new) # equals repr(string_with_utf8), str()
#correct_unicode.encode("ascii") # UnicodeEncodeError becuase ascii has no representation for this char!
bad_unicode = unicode("T\xc3\xa4ter")
@Sennahoi
Sennahoi / example1.html
Created November 14, 2014 10:16
Examples of angular bindings
<ul class="list">
<li ng-repeat="location in locations">
<a href="#">{{location.id}}. {{location.name}}</a>
</li>
</ul>
<map locations='locations'></map>
@Sennahoi
Sennahoi / client.py
Created November 6, 2014 13:37
Send arbitrary data via http with python's httplib
import httplib
import urllib
DATA = "Hello"
connection = httplib.HTTPConnection("localhost:9999", timeout=20)
connection.request("POST", "/stream", headers = {'content-length' : str(len(DATA))})
connection.send(DATA)
response = connection.getresponse()
@Sennahoi
Sennahoi / example.py
Created October 2, 2014 06:39
PyLucene custom char Tokenizer, Analyzer
from org.apache.pylucene.analysis import PythonAnalyzer, PythonCharTokenizer
from org.apache.lucene.analysis import Analyzer
from org.apache.lucene.analysis.core import LowerCaseTokenizer, LowerCaseFilter, StopAnalyzer, StopFilter
class LucTokenizer(PythonCharTokenizer):
def __init__(self, version, input):
PythonCharTokenizer.__init__(self, version, input)
def isTokenChar(self, c):
return c >= 48 and c <= 57 or c >=65 and c <= 90 or c >=97 and c <=122
@Sennahoi
Sennahoi / Test.java
Created September 17, 2014 07:01
Spring MVC Hello World, annotation driven
package de.example.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
@Controller
public class Test {
@RequestMapping("/test")
@Sennahoi
Sennahoi / NIOServlet.java
Created August 5, 2014 14:18
Tomcat Comet Example
public class NIOServlet extends HttpServlet implements CometProcessor {
@Override
public void event(CometEvent event) throws IOException, ServletException {
HttpServletResponse response = event.getHttpServletResponse();
if (event.getEventType() == CometEvent.EventType.BEGIN) {
new HandlerThread(event, response).start();
} else if (event.getEventType() == CometEvent.EventType.ERROR) {
@Sennahoi
Sennahoi / extract.js
Created August 5, 2014 14:16
Extract bookmarks from a netscape bookmark file with node.js
var cheerio = require("cheerio"),
fs = require("fs");
fs.readFile('bookmarks.html', "utf-8", function read(err, data) {
if (err) {
throw err;
}
var $ = cheerio.load(data);
$("a").each(function(index, a) {
@Sennahoi
Sennahoi / config.java
Last active August 29, 2015 14:04
MetricsServlet (metrics.codahale.com/) configuration
MetricRegistry metricRegistry = new MetricRegistry();
ctx.getServletContext().setAttribute("com.codahale.metrics.servlets.MetricsServlet.registry", metricRegistry);