Skip to content

Instantly share code, notes, and snippets.

View Leowbattle's full-sized avatar

Leo Battle Leowbattle

  • England
View GitHub Profile
@Leowbattle
Leowbattle / DancersUK.py
Created November 9, 2017 16:08
Some Homework
# Set of default scores used to quickly debug without typing in scores every time.
# Scores taken from the booklet PDF.
defaultScores = {"A": [6, 9, 9, 10, 5],
"B": [7, 6, 8, 5, 4],
"C": [9, 5, 4, 7, 8],
"D": [5, 6, 9, 7, 6],
"E": [5, 6, 9, 7, 6],
"F": [6, 4, 7, 8, 7]
}
@Leowbattle
Leowbattle / TransitionScreen.java
Created March 3, 2018 15:49
Simple fade-in fade-out screen transition for libGDX
package leo.sortorsplode;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
public class TransitionScreen implements Screen {
private Screen currentScreen;
private Screen nextScreen;
#include "Event.hpp"
void Event::doEvent() {
for (int i = 0; i < handlers.size(); i++) {
handlers.at(i)->handle(this);
}
if (!cancelled) {
execute();
}
@Leowbattle
Leowbattle / Event.hpp
Last active April 14, 2018 09:05
EventsV2
#ifndef Event_hpp
#define Event_hpp
#include <vector>
#include <functional>
class Event;
typedef std::function<void(Event*)> EventHandler;
class Event {
@Leowbattle
Leowbattle / ruin_java.rb
Created July 2, 2018 15:43
Prank your friends by running this script on their Java project (please make sure it is backed up first)
javaFiles = Dir.glob "#{ARGV[0]}/**/*.java"
javaFiles.each do |javaFile|
javaCode = File.read javaFile
javaCode = javaCode.gsub /l|cl/, ""
File.open(javaFile, "w") {|file| file.puts javaCode}
end
@Leowbattle
Leowbattle / esc.rb
Created July 17, 2018 19:07
Turn C code into Spanish
if ARGV.length == 0
puts "Usage: ruby esc.rb [filename]"
exit
end
prog = File.read ARGV[0]
prog = prog.gsub(/auto/, "automático")
prog = prog.gsub(/const/, "constante")
prog = prog.gsub(/double/, "doble");
import math
SQRT_5 = math.sqrt(5)
PHI1 = (0.5, 0.5)
PHI2 = (0.5, -0.5)
def s5n_sub(s5n_1, s5n_2):
(a, b) = s5n_1
(c, d) = s5n_2
return (a - c, b - d)
@Leowbattle
Leowbattle / pow2.cpp
Created September 18, 2021 22:47
Print large powers of 2
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdint>
using namespace std;
using Digit = uint8_t;
using BigInt = vector<Digit>;
# Does the decimal expansion of 1/q terminate?
def terminates(q):
while q % 2 == 0:
q //= 2
while q % 5 == 0:
q //= 5
return q == 1
# If the decimal expansion of 1/q terminates return 0, else return the period of the repeating digits.
def period(q):
@Leowbattle
Leowbattle / Main.java
Created June 17, 2022 09:36
Some code for adding rational points on elliptic curves.
public class Main {
public static void main(String[] args) throws Exception {
var p = new RationalEllipticCurve.Point(new Rational(1), new Rational(2));
var a = new Rational(-7);
var b = new Rational(10);
var curve = new RationalEllipticCurve(a, b);
var r = curve.multiply(p, -10);
System.out.println(r);