Skip to content

Instantly share code, notes, and snippets.

View stewsters's full-sized avatar

Adrian Moore stewsters

View GitHub Profile
@stewsters
stewsters / gist:cf543e21a543f05fb3470aad1e464fad
Created June 28, 2019 14:41
Kotlin allow you to destructure ranges
// Lets you destructure ranges.
val (start, end) = (0..10)
private operator fun <T:Comparable<T>> ClosedRange<T>.component1(): T = this.start
private operator fun <T:Comparable<T>> ClosedRange<T>.component2(): T = this.endInclusive
@stewsters
stewsters / Groovy Style Kotlin
Created June 5, 2018 18:12
Implementing the groovy .times in Kotlin
20.times {
println(it)
}
private fun Int.times(function: (Int) -> Unit) {
for (i in 0 until this) {
function(i)
}
@stewsters
stewsters / Stats.groovy
Created April 9, 2017 02:25
Roll a number of characters
int numberOfCharacter = 5
def stats = ['str', 'dex', 'con', 'wis', 'int', 'cha']
stats.each {
print it + "\t"
}
println()
numberOfCharacter.times {
for (String stat : stats) {
@stewsters
stewsters / git-gud
Created February 23, 2017 16:14
Add this to your path to add a gud command to git. Checks out the latest master and rebases on it.
#!/bin/sh
branch=$(git branch | sed -n -e 's/^\* \(.*\)/\1/p')
echo "updating $branch to the new master"
git fetch
git checkout master
git pull
git checkout $branch
git rebase -i master
@stewsters
stewsters / gist:4e60d449a593731b26496f5846dbc6a0
Created April 1, 2016 19:47
tampermonkey script to Click robin grow button every 2 seconds
// ==UserScript==
// @name New Userscript
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match https://www.reddit.com/robin/
// @grant none
// ==/UserScript==
@stewsters
stewsters / gist:a858d8e0994f975fecec
Created November 19, 2014 22:42
Random asteroid generation
public RandomAsteroidBuilder makeBall(float radius) {
int x2 = width / 2;
int y2 = height / 2;
int z2 = depth / 2;
float radiusShare = 8;
float randomShare = 2;
for (int x = 0; x < width; x++) {
for (int y = 0; y < height; y++) {
@stewsters
stewsters / Slack message
Last active September 17, 2020 01:29
This sends messages as slackbot to slack
/**
* This sends messages as slackbot to slack using groovy
*/
String.metaClass.encodeURL = {
java.net.URLEncoder.encode(delegate, "UTF-8")
}
def address = "https://slack.com/api/"
def method = "chat.postMessage"
@stewsters
stewsters / TileSplitter
Created September 2, 2014 15:04
This code splits a tileset into individual tiles. I use it for naming files and selecting specific tiles before TexturePacking them in LibGDX
import javax.imageio.ImageIO
import java.awt.image.BufferedImage
int tileSize = 32
BufferedImage source = ImageIO.read(new File("fantasy-tileset.png"))
assert source
for (int x = 0; x < source.width / tileSize; x++) {
for (int y = 0; y < source.height / tileSize; y++) {
BufferedImage output = source.getSubimage(tileSize * x, tileSize * y, tileSize, tileSize)