Skip to content

Instantly share code, notes, and snippets.

@SubSide
SubSide / LocalNavController.kt
Created January 16, 2023 14:29
Example for providing a CompositionLocal for the NavController so you don't need to pass it around
import androidx.compose.material.Button
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.staticCompositionLocalOf
import androidx.navigation.NavController
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.rememberNavController
@SubSide
SubSide / 1. RouteProcessor.kt
Last active May 28, 2024 20:22
An easy way to register controller methods in Ktor. This helps clean up some code.
import io.ktor.application.ApplicationCall
import io.ktor.application.call
import io.ktor.http.HttpMethod
import io.ktor.routing.Route
import io.ktor.routing.Routing
import io.ktor.routing.route
import kotlin.reflect.KFunction
import kotlin.reflect.full.callSuspendBy
import kotlin.reflect.full.declaredMemberFunctions
import kotlin.reflect.jvm.javaType
<canvas id="buienradar" width="453" height="120"></canvas>
<script type="text/javascript">
function request() {
var xmlHttp = new XMLHttpRequest();
xmlHttp.onreadystatechange = function() {
if (xmlHttp.readyState == 4 && xmlHttp.status == 200)
doDraw(xmlHttp.responseText);
}
xmlHttp.open("GET", "https://graphdata.buienradar.nl/forecast/json/?lat=52.16&lon=4.49", true); // true for asynchronous
@SubSide
SubSide / Updated Lang.java
Created April 12, 2015 14:45
Updated it, now it doesn't fail, and just continue when a string can't be found in the lang.json, for example, when a newer version has new strings.
package subside.plugins.koth;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
@SubSide
SubSide / lang.json
Created March 30, 2015 15:19
Json created by the Lang.java
{
"PREFIX": "&3[KOTH] &b",
"COMMAND_AREACREATED": "You successfully created the area %area%!",
"KOTH_STARTING": "The koth %area% has begun!",
"KOTH_PLAYERCAP": "%player% has started to cap %area%!",
"KOTH_WON": "The koth %area% ended! %player% won!",
"KOTH_CAPTIME": "%player% is capping the koth! %minutes_left%:%seconds_left% left!",
"KOTH_LEFT": "%player% left the koth!",
"AREA_ALREADYEXISTS": "The area %area% already exists!",
"COMMAND_AREAREMOVED": "You've successfully removed the area %area%!",
@SubSide
SubSide / Lang.java
Created March 30, 2015 15:13
Lang file for the new Koth
package subside.plugins.koth;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;