Skip to content

Instantly share code, notes, and snippets.

Avatar

Ondrej Medek xmedeko

View GitHub Profile
@xmedeko
xmedeko / adminlog.jsp
Created Aug 6, 2012 — forked from iamkristian/log4jAdmin.jsp
Change log4j log levels runtime from a jsp
View adminlog.jsp
<%@ page language="java" contentType="text/html;charset=UTF-8" %>
<%@ page import="org.apache.log4j.Level" %>
<%@ page import="org.apache.log4j.LogManager" %>
<%@ page import="org.apache.log4j.Logger" %>
<%@ page import="java.util.HashMap" %>
<%@ page import="java.util.Enumeration" %>
<%@ page import="java.util.Set" %>
<%@ page import="java.util.Arrays" %>
<%
/* This was originally suggested by Nelz on http://nelz.net/2008/04/08/log4j-runtime-configuration */
@xmedeko
xmedeko / NativeSQLOrder.java
Created Oct 16, 2012
Hibernate NativeSQLOrder
View NativeSQLOrder.java
package org.xmedeko.hibernate;
import org.hibernate.Criteria;
import org.hibernate.HibernateException;
import org.hibernate.criterion.CriteriaQuery;
import org.hibernate.criterion.Order;
import com.google.common.base.Strings;
/**
@xmedeko
xmedeko / NativeSQLAliasedCriterion.java
Created Oct 16, 2012
Hibernate Native SQL Aliased Criterion
View NativeSQLAliasedCriterion.java
package org.xmedeko.hibernate;
import org.hibernate.Criteria;
import org.hibernate.EntityMode;
import org.hibernate.HibernateException;
import org.hibernate.criterion.CriteriaQuery;
import org.hibernate.criterion.Criterion;
import org.hibernate.engine.TypedValue;
import org.hibernate.type.Type;
import org.hibernate.util.ArrayHelper;
@xmedeko
xmedeko / jdump.sh
Created May 22, 2013
jdump - JDK heap dump, wrapper around jmap (and jps)
View jdump.sh
#!/bin/sh
## Wrapper around jmap (and jps).
## Usage: PID file
if [[ "$#" -le 0 ]]; then
jps -ml
echo
echo "Usage: $(basename $0) PID file"
exit
@xmedeko
xmedeko / JLinkButton.java
Last active Dec 28, 2015
Java Swing JLinkButton draws a button like JLabel with blue color and underlined font on mouse hover. Disclaimer: inspired by a few others similar solutions.
View JLinkButton.java
import java.awt.Color;
import java.awt.Cursor;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.font.TextAttribute;
import java.util.Map;
import javax.swing.Action;
@xmedeko
xmedeko / BatchInitalizer.java
Last active Dec 28, 2015
Simple helper to batch load of uninitialized LAZY relations in Hibernate entities.
View BatchInitalizer.java
package org.xmedeko;
import java.util.List;
import java.util.Set;
import org.hibernate.annotations.BatchSize;
import org.hibernate.proxy.HibernateProxy;
import org.hibernate.proxy.LazyInitializer;
import com.google.common.base.Preconditions;
@xmedeko
xmedeko / IpRange.java
Created Jan 29, 2016
IpRange parse and contains test
View IpRange.java
package org.xmedeko;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Arrays;
import java.util.logging.Logger;
/**
* IP range or just one IP address. The main method {@link #containsAddress(byte[])} tests if the given address is in the range.
*
@xmedeko
xmedeko / DapperSelectColumns.cs
Created Mar 20, 2016
Hack to get select columns for Dapper.Contrib ORM type
View DapperSelectColumns.cs
namespace Helpers
{
public static class DapperSelectColumns
{
/// <summary>
/// Hack to string for select statement for the given ORM type.
/// </summary>
/// <param name="ormType"></param>
public static string SelectClause(Type ormType, string alias)
{
@xmedeko
xmedeko / gsmkdirs.sh
Created Sep 21, 2016
Google Cloud Bucket: create explicit dirs
View gsmkdirs.sh
#!/bin/bash
##
## Creates explicit dirs on the bucket
##
function print_help() {
echo "Usage:" $(basename $0) bucket_mounted_dir
exit 1
}
@xmedeko
xmedeko / Example.xaml
Last active Dec 22, 2016
WPF Content control ignoring the content width. Suitable to force a TextBlock to wrap the text.
View Example.xaml
<!-- Especially usefull when placed inside Window and ScrollViewer -->
<myc:IgnoreWidthControl>
<TextBlock Text="Very long text which has to be wrapped. Yeah, it must be wrapped." TextWrapping="Wrap" />
</myc:IgnoreWidthControl>
You can’t perform that action at this time.