Skip to content

Instantly share code, notes, and snippets.

@raychenon
raychenon / Slugify.kt
Last active Mar 5, 2021
Slug transforms a raw text (ex: title) into a pretty URL
View Slugify.kt
import java.text.Normalizer
/**
* Extension function
*/
fun String.slugify(): String =
Normalizer
.normalize(this, Normalizer.Form.NFD)
.replace("[^\\w\\s-]".toRegex(), "") // Remove all non-word, non-space or non-dash characters
.replace('-', ' ') // Replace dashes with spaces
View hex-transparency-color.go
package main
import (
"fmt"
"strconv"
"strings"
)
func dec2hex(dec int) string {
color := dec * 255 / 100