Skip to content

Instantly share code, notes, and snippets.

View witoldsz's full-sized avatar

Witold Szczerba witoldsz

View GitHub Profile
@witoldsz
witoldsz / OnDemandExecutorService.java
Last active October 6, 2017 12:08
Special use-case ExecutorService which collects tasks for execution and invokes them all on #flush() method in current thread. Useful for setup tests, so one can gain control of code execution scheduled by classes under test.
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.List;
import java.util.Queue;
import java.util.concurrent.AbstractExecutorService;
import java.util.concurrent.TimeUnit;
/**
*
* @author witoldsz
var lockMonitor = {};
function schedule(messageKey, callback) {
function run(messageObject, trace, deferred) {
var lockKey = messageObject[messageKey];
if (!lockMonitor[lockKey]) {
lockMonitor[lockKey] = true;
var result = callback(messageObject, trace);
deferred.resolve(result);
@witoldsz
witoldsz / socket.js
Created April 12, 2014 11:25
Prototype of AngularJS service for socket.io v.0.9.x
(function(module) {
"use strict";
// THIS IS ALPHA VERSION, JUST A SNIPPET OF A PROTOTYPE
module.factory('socket', function($rootScope, $q, $browser) {
var self = {
_iosocket: io.connect(),
@witoldsz
witoldsz / DbScriptRunner.java
Created January 23, 2014 22:57
This script reads database commands from STDIN (as UTF-8), splits by semicolon, and executes command by command against given database.
import java.sql.Connection;
import java.sql.DriverManager;
import java.util.Scanner;
/**
* This script reads STDIN (as UTF-8), splits by semicolon, and executes command by command.
* Three arguments are required: database URL, username and password.
* Remember to set classpath for database driver.
* @author Witold Szczerba
*/
package test;
import java.util.Hashtable;
import java.util.Scanner;
import javax.naming.Context;
import javax.naming.NamingException;
import javax.naming.directory.DirContext;
import javax.naming.directory.InitialDirContext;
import javax.naming.ldap.LdapContext;
var vertx = require('vertx')
var console = require('vertx/console')
var eb = vertx.eventBus;
var address = 'example.address'
var creditsAddress = 'example.credits'
var batchSize = 10000;
package pl.espeo.sgn.e2e;
import java.util.List;
import org.apache.commons.lang3.StringUtils;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebDriverException;
import org.openqa.selenium.WebElement;
@witoldsz
witoldsz / OracleBooleanConverter.java
Created January 27, 2013 17:26
JOOQ Converter for Oracle to support boolean types in generated sources.
package pl.espeo.sgn.jooq;
import org.jooq.Converter;
/**
*
* @author Witold Szczerba
*/
public class OracleBooleanConverter implements Converter<Byte, Boolean> {
@witoldsz
witoldsz / FileEnvFilter.java
Last active December 10, 2015 23:38
The class filters file (passed as first argument) with system environment entries (properties) to standard out. If file name ends with .xml or .properties it applies proper escaping.
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.PrintStream;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* The class filters file (passed as first argument) with system environment entries to standard out.
@witoldsz
witoldsz / angular-auth.js
Created July 14, 2012 14:30
Angular Auth (work-in-progress)
/**
* @license Angular Auth
* (c) 2012 Witold Szczerba
* License: MIT
*/
angular.module('angular-auth', [])
/**
* Holds all the requests which failed due to 401 response,
* so they can be re-requested in the future, once login is completed.