Skip to content

Instantly share code, notes, and snippets.

@koraktor
koraktor / RepositoryImpl.java
Created August 18, 2017 10:43
Combining specifications and projections in Spring Data JPA
public class RepositoryImpl<T, ID extends Serializable>
extends SimpleJpaRepository<T, ID extends Serializable> {
ProjectionFactory projectionFactory;
public <P> List<P> findProjected(Specification<?> spec, Sort sort, Class<P> projectionClass) {
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
CriteriaQuery<Tuple> tupleQuery = criteriaBuilder.createTupleQuery();
Root<?> root = tupleQuery.from(getDomainClass());
module MyModule
# Defines method_missing
module ClassMethods
def method_missing(method)
puts "Method: \"#{method}\" does not exist."
end
end
# Will add method_missing to MyModule itself
@koraktor
koraktor / directory-structure.txt
Created April 15, 2011 07:04
Using a Git submodule as Maven parent project
_
\
project
|
|--.git--...
|
|--parent
| |
| |--.git
| |
@koraktor
koraktor / rubikon-config.rb
Created January 24, 2011 18:42
Rubikon: A global option to override config files
class ConfigSample < Rubikon::Application::Base
global_option :c => :config
global_option :config, 'Override the configuration with the given file', :config_file do
path = File.dirname config_file
file = File.basename config_file
config = Rubikon::Config::Factory.new(file, path).config
@__app__.instance_eval { @config = config }
end
@koraktor
koraktor / version-check.php
Created December 31, 2010 14:10
Source server version check
<?php
require_once 'steam-condenser.php';
$game = 'cstrike';
error_reporting(E_ERROR);
$master = new MasterServer(MasterServer::SOURCE_MASTER_SERVER);
$challenge = $master->getChallenge();
$servers = $master->getServers(MasterServer::REGION_EUROPE, "\\gamedir\\{$game}");
@koraktor
koraktor / timeout.php
Created December 30, 2010 08:31
Customizing socket timeouts in Steam Condenser (>= 0.12.0)
<?php
require_once 'steam-condenser.php';
// Setting the timeout to 50ms (default is 1000ms / 1s)
SteamSocket::setTimeout(50);
// Query a local server which should respond quite fast
$server = new SourceServer(new InetAddress('192.168.0.5'));
$server->getRules();
@koraktor
koraktor / rm-rbx-bytecode.sh
Created November 28, 2010 11:31
Removes Rubinius' bytecode files from a directory tree
find . -name '*.rbc' -exec rm {} \;
@koraktor
koraktor / Output:
Created October 13, 2010 08:29
This demonstrates how to call constructors of multiple included modules in Ruby
Hello World!
The weather is nice!
See you soon.
@koraktor
koraktor / gist:607502
Created October 2, 2010 09:51
Sample hooks for using Git as a backup tool
#!/bin/sh
#
# This code is free software; you can redistribute it and/or modify it under
# the terms of the new BSD License.
#
# Copyright (c) 2010, Sebastian Staudt
#
# This is a demonstration hook that can be used to automatically update a
# backup repository.
#
@koraktor
koraktor / gist:587533
Created September 20, 2010 07:23
YARD question: Documenting multiple attr_reader
# This works:
# @return [String] This is attribute #1
attr_reader :attr1
# @return [Object] This is attribute #2
attr_reader :attr2
# But this won't: