Skip to content

Instantly share code, notes, and snippets.

View jandk's full-sized avatar

Jan De Kock jandk

View GitHub Profile
import com.squareup.javapoet.*
import java.util.*
import javax.lang.model.element.Modifier
private fun generateIndexOfTriple(typeName: TypeName): List<MethodSpec> {
val arrayTypeName = ArrayTypeName.of(typeName)
val indexOf4 = indexOf4(arrayTypeName, false)
val indexOf2 = indexOf2(arrayTypeName, indexOf4, false)
val lastIndexOf4 = indexOf4(arrayTypeName, true)
val lastIndexOf2 = indexOf2(arrayTypeName, lastIndexOf4, true)
<?php
class EAN13render
{
// These are the different barcode patterns for each digit (7 bit each).
// '1' represents a black line, '0' represents white (no line).
static $Rcodes = array('1110010', '1100110', '1101100', '1000010', '1011100',
'1001110', '1010000', '1000100', '1001000', '1110100');
// The EAN13 defines three groups of bit patterns.
@jandk
jandk / Feistel.java
Last active September 27, 2018 07:39
Reversible encoding and stringification of numbers
package be.tjoener.test;
@SuppressWarnings("PointlessArithmeticExpression")
public final class Feistel {
/**
* Sets the number of rounds, security/speed trade-off
*/
private static final int ROUNDS = 16;
package com.example.demo;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.Data;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.CreationTimestamp;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
public final class Person {
private final String firstName;
private final String lastName;
private Person(String firstName, String lastName) {
this.firstName = firstName;
this.lastName = lastName;
}
@Component
@Order(Ordered.HIGHEST_PRECEDENCE)
@SuppressWarnings({"unchecked", "rawtypes"})
static final class StringToEnumConverterFactory implements ConverterFactory<String, Enum> {
@Override
public <T extends Enum> Converter<String, T> getConverter(Class<T> targetType) {
return new StringToEnum(getEnumType(targetType));
}
import java.util.Arrays;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
public class LargestNumber
{
public static void main(String[] args)
{
String number = IntStream.range(1, 31)
.mapToObj(String::valueOf)
using System.IO;
public static class Misc
{
/// <summary>
/// Calculates the checksum on a v0.90 MD superblock.
/// Don't ask me why I needed it.
/// </summary>
/// <param name="filename">
public sealed class UnionFind<T>
{
private sealed class Link<TLink>
{
public TLink parent;
public int rank = 0;
public Link(TLink parent)
{
this.parent = parent;
@jandk
jandk / Raster.cs
Created December 16, 2013 10:06
Simple image processing in a generic way (just an idea)
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
namespace Util
{
public struct Position
{