Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am DomWilliams0 on github.
  • I am domwilliams0 (https://keybase.io/domwilliams0) on keybase.
  • I have a public key whose fingerprint is 36B5 EB10 9835 6E7B A795 8AC1 1E6D A1A8 6369 CBC8

To claim this, I am signing this object:

@DomWilliams0
DomWilliams0 / genetic.py
Created July 23, 2015 18:17
Simple genetic algorithm
import random
import string
from time import sleep
POSSIBLE_CHARS = string.ascii_letters + string.punctuation + " "
def evolve(population, pop_count, crossover_mutation_ratio):
def swap(src, dst, i, j=None):
@DomWilliams0
DomWilliams0 / rps.py
Created July 19, 2014 17:54
A simple rock-paper-scissors game
import random
from time import sleep
moves = ["rock", "paper", "scissors"]
choices = [x[0] for x in moves]
WIN, LOSS, DRAW = "WIN", "LOSS", "DRAW"
player_score = 0
computer_score = 0
@DomWilliams0
DomWilliams0 / tenjava.py
Created July 15, 2014 13:56
Extracts all individual words from the tenjava 2014 repositories to a single file
import urllib.request
import re
import os
import glob
def fetch_repos(outputpath):
print("fetching repo names from github")
pages = list(range(1, 10))
pat = re.compile("/tenjava/(.+\-t[1-3])\"")
@DomWilliams0
DomWilliams0 / StringWrapping.java
Last active January 1, 2016 16:39
Colour-persistent string wrapping
/**
* @param str The string to wrap
* @param colourCode The colour code character to use, such as '&' or '§'
* @param lineLength The line length to base around - not all lines will be this length exactly
* @param wrapLongWords Whether long words should be cut up to fit the lines
* @return The wrapped string, divided by new line characters
*/
public static String wrapString(String str, char colourCode, int lineLength, boolean wrapLongWords)
{
// split up into words
/*
Example:
new BukkitRunnable()
{
Scroller scroller = new Scroller("&aThis is an &2important &amessage!", 16, 5, '&');
Sign sign = a-sign-from-somewhere;
public void run()
{
@DomWilliams0
DomWilliams0 / String Scroller.java
Last active December 25, 2015 23:19
Convert a String into a List, which can be printed continually to scroll the text along.
/*
Example:
---
List<String> scrolling = scroll("This is a scrolling string!", 10, 5);
int i = 0;
while (true)
{
System.out.println(scrolling.get(i++ % scrolling.size()));
// some delay