Skip to content

Instantly share code, notes, and snippets.

View ogregoire's full-sized avatar

Olivier Grégoire ogregoire

  • Europe
View GitHub Profile
@ogregoire
ogregoire / WtfCreator.java
Created December 8, 2022 10:15 — forked from nikialeksey/WtfCreator.java
Joshua Bloch Wtf.java break-in
import org.apache.commons.math3.analysis.interpolation.NevilleInterpolator;
public class WtfCreator {
public static void main(String[] args) {
var text = "Hello, world!\n";
double[] x = new double[text.length() + 1];
double[] y = new double[text.length() + 1];
for(var i = 0; i < text.length(); i++) {
x[i] = i;
import bisect
class NFA(object):
EPSILON = object()
ANY = object()
def __init__(self, start_state):
self.transitions = {}
self.final_states = set()
self._start_state = start_state
public class DhondtMethod {
public int[] partition(int totalSeats, int[] votes) {
int[] seats = new int[votes.length];
if (totalSeats == 0) {
return seats;
}
if (votes.length == 0) {
return seats;
}
@ogregoire
ogregoire / GitConfigHttpProxy.md
Created April 19, 2019 15:19 — forked from evantoli/GitConfigHttpProxy.md
Configure Git to use a proxy

Configure Git to use a proxy

##In Brief

You may need to configure a proxy server if you're having trouble cloning or fetching from a remote repository or getting an error like unable to access '...' Couldn't resolve host '...'.

Consider something like:

@ogregoire
ogregoire / Strings.java
Created April 28, 2017 13:33
Levenshtein distance
public class Strings {
// From https://en.wikibooks.org/wiki/Algorithm_Implementation/Strings/Levenshtein_distance#Java
public int levenshteinDistance (CharSequence lhs, CharSequence rhs) {
int len0 = lhs.length() + 1;
int len1 = rhs.length() + 1;
// the array of distances
int[] cost = new int[len0];
int[] newcost = new int[len0];
@ogregoire
ogregoire / OkHttpExample.java
Last active March 28, 2017 09:08
OkHttpExample
OkHttpClient client = new OkHttpClient.Builder()
// Logging
.addInterceptor(new HttpLoggingInterceptor(System.err::println).setLevel(HttpLoggingInterceptor.Level.BODY))
// Timeout
.connectTimeout(60, TimeUnit.SECONDS)
.writeTimeout(60, TimeUnit.SECONDS)
.readTimeout(60, TimeUnit.SECONDS)
// Proxy
.proxy(new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyHost, proxyPort))
.proxyAuthenticator(($, response) -> response.request().newBuilder()
@ogregoire
ogregoire / keybase.md
Created December 22, 2016 23:59
keybase.md

Keybase proof

I hereby claim:

  • I am ogregoire on github.
  • I am ogregoire (https://keybase.io/ogregoire) on keybase.
  • I have a public key ASA0h2SBHE-twB-WbT-Pp4aimGzSWu5wNo-dDSxhskHpjgo

To claim this, I am signing this object:

Not empty content
@ogregoire
ogregoire / Replacer.java
Last active July 12, 2016 14:08
Replacement class for multiple replacements occurring at once.
package replacer;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.base.Function;
import com.google.common.base.Functions;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
@ogregoire
ogregoire / Pi.java
Last active March 18, 2016 10:47
Computing Pi to the nth decimal in Java
import java.math.BigDecimal;
import java.math.RoundingMode;
public class Pi {
private static final BigDecimal TWO = new BigDecimal("2");
private static final BigDecimal FOUR = new BigDecimal("4");
private static final BigDecimal FIVE = new BigDecimal("5");
private static final BigDecimal TWO_THIRTY_NINE = new BigDecimal("239");