Skip to content

Instantly share code, notes, and snippets.

View corlaez's full-sized avatar
🏠
WFH since January 2020

Armando Cordova corlaez

🏠
WFH since January 2020
View GitHub Profile
@corlaez
corlaez / Cliente.java
Last active September 27, 2024 06:40
Codigo para persistir objetos en Java
package clases;
import java.io.Serializable;
public class Cliente implements Serializable {
private static final long serialVersionUID = 1_000_000_000_000_001L;
private Integer codigo;
private String nombre;
private String apellido;
@corlaez
corlaez / LICENSE
Last active February 20, 2024 18:04
html dsl htmx extensions
Copyright (c) <year> <copyright holders>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
@corlaez
corlaez / README.md
Last active December 24, 2023 00:30
Tiny Kotlin Static Server

This is a tiny kotlin server, useful for simple dev scenarios. Features and limitations:

  • Validation of arguments, no hiding of errors
  • No caching, will read file each time is served (ideal for development server)
  • No dependency or dep management (gradle, maven). Just a single kotlin file and bat scripts
  • Prints all routes that it configures
  • Explicit, it requires you to declare a list of the filesnames to serve
  • No nesting. It will only serve files in the same directory

startServerAfterCompile.bat takes longer to initialize because it first compiles serve.kt to serveKt.class. However, this is only necessary if you are making changes to serve.kt. Use startServer.bat to run the server without compiling (starts faster)

@corlaez
corlaez / checkboxFix.js
Last active June 10, 2023 08:44
htmx cookbook
// This is meant to be in a html head script tag
// checkboxes are very inconvenient in html and will serialize nothing when the checkbox is unchecked
// instead of using hx-vals and writting a bit of JSON each time you have a checkbox I decided to fix it globally:
window.onload = function() {
document.body.addEventListener('htmx:configRequest', function(evt) {
const isInput = evt.detail.elt.tagName == 'INPUT';
const isCheckbox = evt.detail.elt.type == 'checkbox';
const isNotChecked = evt.detail.elt.checked == false;
if(isInput && isCheckbox && isNotChecked) {
const name = evt.detail.elt.name;
@corlaez
corlaez / README.md
Last active June 6, 2023 03:12
Kotlin Webjars Locator Ktor Gradle

This is how I like to use webjars in kotlin.

build.gradle.kts dependencies:

dependencies {
    // webjars
    implementation("org.webjars:webjars-locator:0.46")
    implementation("org.webjars.npm:htmx.org:1.9.2")
}
@corlaez
corlaez / main.kt
Last active June 2, 2023 20:40
Fast Inverse Square Root in Kotlin
import kotlin.math.pow
fun fastInverseSqrt(number: Float): Float {
val ieee754FloatBits = number.toBits() // evil floating point bit hack, avoided
val invSqrt = Float.fromBits(0x5f3759df - (floatsBits shr 1)) // what the fish
return invSqrt * (1.5F - (0.5F * number * invSqrt * invSqrt)) // Newton iteration
}
@corlaez
corlaez / Main.kt
Last active August 31, 2022 13:32
Simple browser auto-reloader in Kotlin
import org.eclipse.jetty.http.HttpStatus
import java.time.LocalDateTime
fun main(args: Array<String>) {
val arg = Args.valueOf(args[0])
val port = System.getenv("PORT") ?: "8080"
if (arg.isRegenerate()) {
val serverArg = getRequestArg(port)
with(EnvContext(serverArg, port, webPlugins)) {
generate()// Here I generate my static website
@corlaez
corlaez / LICENSE
Last active August 28, 2022 03:23
Modest Variation (Markdown css)
The MIT License (MIT)
Copyright (c) 2014-2015 John Otander
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
@corlaez
corlaez / main.kt
Created May 18, 2022 02:10
Self Study Flashcard CLI
val chapter1 = mapOf(
"2 + 2" to "4",
"0 + 2" to "2",
)
val chapters = chapter1// + chapter2 + chapter3
fun main() {
while (true) {
val shuffledQuestions = chapters.keys.shuffled()
@corlaez
corlaez / README.md
Last active March 20, 2022 21:08
Violin Strings guide

String Identification

  • E is the thinnest string
  • A is the second thinnest string
  • D is the second thickest string
  • G is the thickest string

image