Skip to content

Instantly share code, notes, and snippets.

@redhead
redhead / FeatureFlag.kt
Last active June 14, 2022 14:19
Kotlin Context Receivers allow nice Feature Toggles
// client code
object NewFeature : Feature
object NewFeatureVariant : Feature
fun main() {
// configuration
val featureConfiguration = mapOf(
NewFeature to true,
@redhead
redhead / EventSourcingRepositoryBeanDefinitionRegistrar.java
Created February 12, 2017 10:21
Automatic registrar of even sourcing repository bean
package mysystem;
import org.axonframework.commandhandling.model.Repository;
import org.axonframework.eventsourcing.EventSourcingRepository;
import org.axonframework.spring.stereotype.Aggregate;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.beans.factory.config.BeanDefinition;
Integer randomizedSelect(List<Integer> elements, int k) {
if(elements.size() == 1) return elements.get(0);
Integer pivot = elements.get(0);
List<Integer> smaller = new ArrayList<Integer>();
for(Integer i : elements) {
if(i < pivot) smaller.add(i);
}
if(k < smaller.size()) return randomizedSelect(smaller, k);
ACTOR
-----
actor NazevAktera {
description: Popis ucastnika
}
// jednotliva Kruznice je reprezentovana touto tridou Kruznice:
public class Kruznice {
public double x; // x stredu
public double y; // y stredu
public double r; // polomer
}
/////////////////////////////////////////////////////////////////////////////////
// metoda pro vypocet obsahu nejmensiho obdelniku:
public class Primka {
// rovnice primky je dana:
// y = k*x + q
public double k; // k - smernice primky
public double q; // q - posun v ose y
// kostruktor, naplni instacni promenne
// hodnotami danymi pri vytvoreni objektu:
// new Primka(2, -1) je primka y = 2x - 1
@redhead
redhead / live-form-validation.js
Created August 26, 2010 21:16
Live Form Validation for Nette 2.0
/**
* Live Form Validation for Nette 2.0
*
* @author Radek Ježdík, MartyIX, David Grudl
*/
var LiveForm = {
options: {
controlErrorClass: 'form-control-error', // CSS class for an invalid control
errorMessageClass: 'form-error-message', // CSS class for an error message