Skip to content

Instantly share code, notes, and snippets.

View demoth's full-sized avatar
🎯
Refactoring full throttle!

demoth demoth

🎯
Refactoring full throttle!
View GitHub Profile
@demoth
demoth / echo.kt
Created November 24, 2023 18:09
Simple Echo program that directly plays audio captured from the microphone
import java.io.FileOutputStream
import java.io.IOException
import java.io.InputStream
import java.io.OutputStream
import javax.sound.sampled.*
import kotlin.concurrent.thread
import kotlin.system.exitProcess
fun main() {
val format = AudioFormat(16000.0f, 16, 1, true, true)
@demoth
demoth / simple_audio_player.kt
Last active November 24, 2023 18:10
Simple audio WAV player based on javax sound clip api
import java.io.BufferedInputStream
import java.io.FileInputStream
import javax.sound.sampled.*
// expect a path to a wav file as a first argument
fun main(args: Array<String>) {
val fileInputStream = BufferedInputStream(FileInputStream(args.first()))
val audioInputStream = AudioSystem.getAudioInputStream(fileInputStream)
val clip = AudioSystem.getClip()
@demoth
demoth / mdl2obj.kt
Created February 12, 2023 23:03
Q2 mdl to obj converter
package shaders
fun convertToObj(model: Md2Model, frameIndex: Int): String {
val result = StringBuilder()
val frame = model.frames[frameIndex] ?: return ""
result.appendLine("mtllib sphere.mtl")
result.appendLine("o testModel")
// v vec3_position
frame.points.forEach {
result.appendLine("v ${it.x * frame.scale[0]} ${it.z * frame.scale[2]} ${it.y * frame.scale[1]}")
@demoth
demoth / sample-pain-001-001-08.xml
Created March 31, 2017 19:59
iso20022 PAIN 001 001 08 sample
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Document xmlns="urn:iso:std:iso:20022:tech:xsd:pain.001.001.08">
<CstmrCdtTrfInitn>
<GrpHdr>
<MsgId>3f93b34c-8b69-4b0c-bcee-d181881cc95</MsgId>
<CreDtTm>2017-03-31T18:51:44.018+03:00</CreDtTm>
<NbOfTxs>39</NbOfTxs>
<CtrlSum>12754007436</CtrlSum>
<InitgPty>
<Id>
@demoth
demoth / JsonValidator.groovy
Last active October 15, 2015 21:08
JsonValidator
class JsonValidator extends BuilderSupport {
def root = null
void setParent(Object parent, Object child) {
if (!root) root = parent
parent.children << child
}
void createNode(Object name, Map attributes, Object value) {
return [name: name, value: value, children: []]
}
case ItemType.USABLE:
if (item.quantity) {
item.effects*.apply this
item.quantity--
}
if (!item.quantity)
inventory.remove item
break
@demoth
demoth / LogicTest.groovy
Last active August 29, 2015 14:19
Logic tests
package org.demoth.aurora.server
import com.jme3.network.*
import org.demoth.aurora.common.*
import org.demoth.aurora.common.messages.TextMessage
import org.demoth.aurora.common.messages.client.*
import org.demoth.aurora.common.messages.server.GameUpdateMessage
import org.demoth.aurora.server.abilities.Ability
import org.demoth.aurora.server.items.*
import org.junit.*
@demoth
demoth / Actor.groovy
Last active August 29, 2015 14:19
inventory
class Actor {
private static final ArrayList<ItemSlot> BOTH_HANDS = [MAIN_HAND, OFF_HAND]
private static final ArrayList<ItemSlot> BOTH_RINGS = [RING_RIGHT, RING_LEFT]
// items
Collection<Item> inventory = []
Map<ItemSlot, Item> equipment = [:]
void useOrEquip(int itemId, ItemSlot targetSlot) {
@demoth
demoth / Logic.groovy
Last active August 29, 2015 14:18
some pieces of games
void update(float tpf) {
super.update(tpf)
// lets process a message
ClientMessage mess = messages.poll()
if (mess != null) {
switch (mess.class) {
case ActionRequestMessage:
if (players.get(mess.id).name != null) // if logged in
players.get(mess.id).actions << (mess as ActionRequestMessage)
break