Skip to content

Instantly share code, notes, and snippets.

View jarek-przygodzki's full-sized avatar

Jarek Przygódzki jarek-przygodzki

View GitHub Profile
@jarek-przygodzki
jarek-przygodzki / PostgreSQL.groovy
Created February 9, 2013 20:12
Howto connect to PostgreSQL DB in Groovy
import groovy.sql.Sql
def dbUrl = "jdbc:postgresql://localhost/test-db"
def dbUser = "test"
def dbPassword = "test"
def dbDriver = "org.postgresql.Driver"
def sql = Sql.newInstance(dbUrl, dbUser, dbPassword, dbDriver)
@jarek-przygodzki
jarek-przygodzki / jaranalyzer-deps-visualization.groovy
Last active December 12, 2015 09:09
Visualize the output of JarAnalyzer as directed graph
@Grapes([
@Grab(group='net.sf.jung', module='jung2', version='2.0.1'),
@Grab(group='net.sf.jung', module='jung-algorithms', version='2.0.1'),
@Grab(group='net.sf.jung', module='jung-visualization', version='2.0.1'),
@Grab(group='net.sf.jung', module='jung-graph-impl', version='2.0.1')])
import java.awt.*
import javax.swing.*
import edu.uci.ics.jung.graph.*
@jarek-przygodzki
jarek-przygodzki / unsignjar.xml
Created February 18, 2013 21:48
Unsign a JAR with Ant
<!-- http://frank.zinepal.com/unsign-a-jar-with-ant -->
<macrodef name="unsignjar">
<attribute name="jar"/>
<sequential>
<!-- Remove any existing signatures from a JAR file. -->
<tempfile prefix="usignjar-" destdir="${java.io.tmpdir}" property="temp.file"/>
<echo message="Removing signatures from JAR: @{jar}"/>
<mkdir dir="${temp.file}"/>
// http://www.javacodegeeks.com/2013/02/increased-compile-time-safety-with-phantom-types.html
public interface Entity {
Long getId();
}
public final class Ref<T extends Entity> implements Serializable {
public final long id;
@jarek-przygodzki
jarek-przygodzki / MoreRestrictions.java
Created February 26, 2013 11:01
HOW to Handle ORA-01795 in Hibernate using Restrictions.disjunction()
// http://docs.jboss.org/hibernate/core/3.3/api/org/hibernate/criterion/Restrictions.html#disjunction%28%29
public static Criterion createInRestriction(String propertyName, Collection values) {
if (values.size() <= 1000) {
return Restrictions.in(propertyName, values);
} else {
List valueList = asList(values);
Disjunction disjunction = Restrictions.disjunction();
int packSize = 1000;
for (int i = 0; i < values.size(); i += pack) {
-- http://msdn.microsoft.com/en-us/library/ms345103.aspx
SELECT o.name AS major_name, o.type_desc AS major_type_desc
, c.name AS minor_name, c.type_desc AS minor_type_desc
, at.assembly_class
FROM (
SELECT object_id, name, user_type_id, 'SQL_COLUMN' AS type_desc
FROM sys.columns
UNION ALL
SELECT object_id, name, user_type_id, 'SQL_PROCEDURE_PARAMETER'
@jarek-przygodzki
jarek-przygodzki / mssql-cheatsheet.sql
Created March 2, 2013 15:26
Microsoft SQL Server Cheat Sheet
-- create user
-- sqlcmd -S <ComputerName>\<InstanceName> -E -i mssql_user_setup.sql -v db=<DbName> -v user=<UserName> -v password=<Password>
use [$(db)];
go
create schema $(user);
go
create login $(user) with PASSWORD = '$(password)';
create user $(user) for login $(user) with DEFAULT_SCHEMA=$(user);
go
grant alter to $(user);
@jarek-przygodzki
jarek-przygodzki / cycle-finder.groovy
Last active December 16, 2015 02:59
Detecting cycles in a directed graph
//#!/usr/bin/env groovy
/**
* Finding cycles in a directed graph
*/
class CycleFinder {
// Zbiór wierzchołków w grafie
def V
/**
* Object which is capable of writing itself
*/
public interface Writable<WriterType> {
/*
* Writes this object to the given writer
*/
WriterType writeTo(WriterType writer);
}
@jarek-przygodzki
jarek-przygodzki / cycle-finder.groovy
Created April 15, 2013 18:58
Finding cycles in a directed graph using DFS and back edges
interface DfsVisitor {
void preorder(v)
void postorder(v)
void beforeChild(v)
void afterChild(v)
void skipChild(v)