Skip to content

Instantly share code, notes, and snippets.

View JochemKuijpers's full-sized avatar

Jochem Kuijpers JochemKuijpers

View GitHub Profile
BigInteger sqrt(BigInteger n) {
BigInteger a = BigInteger.ONE;
BigInteger b = n.shiftRight(5).add(BigInteger.valueOf(8));
while (b.compareTo(a) >= 0) {
BigInteger mid = a.add(b).shiftRight(1);
if (mid.multiply(mid).compareTo(n) > 0) {
b = mid.subtract(BigInteger.ONE);
} else {
a = mid.add(BigInteger.ONE);
}
@JochemKuijpers
JochemKuijpers / demo.html
Created August 11, 2017 13:24
Javascript date timer demo
<html>
<head>
<title>Javascript date timer demo</title>
<script type="text/javascript">
var e;
function init() {
e = document.getElementById("pre");
}
@JochemKuijpers
JochemKuijpers / Vector.h
Created February 18, 2018 03:38
[CLion] "No matching constructor" but still compiles
#ifndef SDL_PROJECT_VECTOR_H
#define SDL_PROJECT_VECTOR_H
#include <iostream>
#include <cstdarg>
#include <sstream>
#include <cmath>
template <typename NumType, int N>
class Vector {
@JochemKuijpers
JochemKuijpers / Main.java
Last active October 12, 2018 19:56
Letter Clock generator
import java.util.*;
public class Main {
public static void main(String[] args) {
int targetRows = 16;
int width = 16;
long tries = 0;
double bestScore = 0;
@JochemKuijpers
JochemKuijpers / install_synology_drive_on_fedora.sh
Created January 5, 2019 03:40
Installs Synology Drive on Fedora 29 (from the .deb package). Use at own risk.
#!/usr/bin/env bash
if [[ $UID != 0 ]];
then
echo "Please run this script with sudo or as root:"
echo
echo "sudo $0 $*"
exit 1 || return 1
fi
@JochemKuijpers
JochemKuijpers / main.c
Last active September 13, 2019 02:37
Frog puzzle decision tree
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#define MIN(X,Y) (((X) < (Y)) ? (X) : (Y))
// used for modeling rational numbers exactly as two integers (nom/den)
typedef struct Ratio {
uint64_t den;
uint64_t nom;