Skip to content

Instantly share code, notes, and snippets.

@inancsevinc
inancsevinc / turkish_character_unicode_escapes
Created June 21, 2012 14:02
unicode escapes for turkish chars
* ğ - \u011f
* Ğ - \u011e
* ı - \u0131
* İ - \u0130
* ö - \u00f6
* Ö - \u00d6
* ü - \u00fc
* Ü - \u00dc
* ş - \u015f
* Ş - \u015e
@inancsevinc
inancsevinc / AdminResourceFilter.java
Created July 2, 2012 06:45
JAX-RS resource filter class used to authorize requests
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Response;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.sun.jersey.spi.container.ContainerRequest;
import com.sun.jersey.spi.container.ContainerRequestFilter;
import com.sun.jersey.spi.container.ContainerResponse;
import com.sun.jersey.spi.container.ContainerResponseFilter;
@inancsevinc
inancsevinc / PortalResourceTopItems.java
Created July 2, 2012 07:18
JAX-RS optional path params example
/**
* Returns most popular(retrieved using records in portal_log) documents opened using portal.
* This rest service responds all these requests:<br/>
* ../log/top ({p:/?} makes / optional)<br/>
* ../log/top/<br/>
* ../log/top/10 (same as ../log/top)<br/>
* ../log/top/20 (any number is fine)<br/>
*
* @param numberOfItems max number of items, default 10
* @return list of items containing cuid, rank and viewCount, ordered by viewCount desc
@inancsevinc
inancsevinc / TestRSA.java
Created July 10, 2012 09:30
Junit for RSA encryption/decryption
import static org.junit.Assert.*;
import java.math.BigInteger;
import java.security.Key;
import java.security.KeyFactory;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.spec.RSAPrivateKeySpec;
@inancsevinc
inancsevinc / PropertySourceInitializer.java
Created August 2, 2012 06:55
Spring ApplicationContextInitializer class which adds a new PropertySource to Spring's DefaultEnvironment.
import java.util.HashMap;
import java.util.Map;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.mapping.Environment;
import org.apache.ibatis.session.Configuration;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
@inancsevinc
inancsevinc / ExtendedJDBCAppender.java
Created August 6, 2012 11:24
Extension of the log4j to allow using a JNDI data source
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;
@inancsevinc
inancsevinc / RSAHelper.java
Created August 6, 2012 11:29
Helper class for RSA encryption and key generation(private_key.xml for .net integration)
import java.net.URLEncoder;
import java.security.Key;
import java.security.KeyFactory;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.PublicKey;
import java.security.interfaces.RSAPrivateCrtKey;
import java.security.spec.PKCS8EncodedKeySpec;
import java.security.spec.RSAPublicKeySpec;
import java.util.HashMap;
@inancsevinc
inancsevinc / TestResource.java
Created August 31, 2012 06:09
Expose war package build date as a rest service, using maven, spring and jax-rs
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
/**
* @author Inanc Sevinc
@inancsevinc
inancsevinc / ns_to_package_mapper.py
Created October 1, 2012 06:23
namespace-to-package mapper for non-standard namespaces in wsdl/xsd files, to be run before jax-rpc client generation
import os, re
searchDir= "C:/temp"
mydict = {} #empty dictionary, keys are namespace urls, values are mapped packages
for dirpath, dirnames, filenames in os.walk(searchDir): #walk thru directories recursively
for file in [ f for f in filenames if os.path.splitext(f)[1] in [".xsd",".wsdl"] ]:
with open(os.path.join(dirpath,file)) as current_file:
for line in current_file.readlines():
m = re.search(r'(http://)(isbank\.com([^\"])+)', line)
@inancsevinc
inancsevinc / jquery.ba-tinypubsub.js
Created October 3, 2012 12:37 — forked from cowboy/HEY-YOU.md
jQuery Tiny Pub/Sub: A really, really, REALLY tiny pub/sub implementation for jQuery.
/* jQuery Tiny Pub/Sub - v0.7 - 10/27/2011
* http://benalman.com/
* Copyright (c) 2011 "Cowboy" Ben Alman; Licensed MIT, GPL */
(function($) {
var o = $({});
$.subscribe = function() {
o.on.apply(o, arguments);