Skip to content

Instantly share code, notes, and snippets.

View jandk's full-sized avatar

Jan De Kock jandk

View GitHub Profile
@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">
@jandk
jandk / fix.sh
Created September 23, 2015 19:21
#!/bin/bash
if [ "$#" -lt 1 ]
then
echo "Usage: fix.sh <folder> [folder]...\n"
exit 1
fi
for d in $@
do
package com.cmosis.test;
import java.util.Comparator;
public class NaturalOrderComparator implements Comparator<String>
{
static char charAt(String s, int i)
{
if (i >= s.length())
return 0;
import java.util.Iterator;
import java.util.NoSuchElementException;
public class IteratorWithCurrent<E> implements Iterator<E>
{
private final Iterator<E> it;
private E current;
public IteratorWithCurrent(Iterable<E> iterable) {
it = iterable.iterator();
<?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.