Control FiiO KA13 DAC on Linux via USB HID
fiio-ka13-control) on Linux systems.website·Indexed 32 days ago
https://ngoding.id/posts/A technical blog featuring coding challenges, data structures and algorithms (DSA) tutorials, and development logs. Content includes the Hyperskills 12 Days of Coding challenges, Kotlin reflection and annotations, SQL basics, CUDA environment setup, and Google Cloud IAM configuration.
fiio-ka13-control) on Linux systems.@ symbol and are placed either directly above or immediately before the target element. Annotations apply only to the closest subsequent element; if multiple annotations are needed for a single target, they can be stacked.// Applied directly above
@MyAnnotation
class MyClass {}
// Applied before the code line
@MyAnnotation class MyClass {}
// Multiple annotations on one target
@NotNull
@PrimaryKey(autoGenerate = true)
var taskId: Long = 0LIn programming, searching is the process of retrieving desired data from a collection (data structure). There are two primary goals when searching:
# Add the NVIDIA repository
sudo zypper install openSUSE-repos-Tumbleweed-NVIDIA
# For Maxwell and Pascal GPUs
sudo zypper in nvidia-video-G06 nvidia-gl-G06 nvidia-compute-utils-G06 nvidia-libXNVCtrl nvidia-settings
# For Turing and newer GPUs (using Open GPU kernel modules)
sudo zypper in nvidia-open-driver-G06-signed-cuda-kmp-default nvidia-gl-G06 nvidia-compute-utils-G06 nvidia-libXNVCtrl nvidia-settingsimport java.io.File
fun main() {
// 1. Read input and remove delimiters (e.g., commas)
val patterns = File("dataset.txt").readLines().map { it.replace(",", "") }
// 2. Use the first pattern as the reference
val reference = patterns[0]
val others = patterns.drop(1)
// 3. Iterate length from largest to smallest to return early
for (length in reference.length downTo 1) {
for (startIndex in 0..reference.length - length) {
val substring = reference.substring(startIndex, startIndex + length)
// 4. Check if this substring exists in ALL other patterns
val existsInAll = others.all { it.contains(substring) }
if (existsInAll) {
println(substring.length)
return // Found the longest possible, exit immediately
}
}
}
println(0) // No common substring found
}SELECT statement can return a set of values (a tuple). You can use the AS keyword to provide an alias for the resulting column. SQL is case-insensitive, but keywords are typically written in uppercase for readability.SELECT
'Kotlin' AS name,
2025 AS year,
123*1 AS "weight in kilos"
;The basic linear search algorithm can be adapted to handle different use cases:
true/false) instead of an index.To determine if a network of bidirectional bridges can be traversed by crossing every bridge exactly once (an Eulerian Path), count the number of vertices with an odd degree.
The formula for minimum additional crossings is: (OddCount - 2) / 2.
import java.io.File
fun main() {
val degrees = mutableMapOf<String, Int>()
// 1. Build the graph degrees from the edge list (format: LandMass1,LandMass2)
File("dataset.txt").forEachLine { line ->
val (u, v) = line.split(",")
degrees[u] = degrees.getOrDefault(u, 0) + 1
degrees[v] = degrees.getOrDefault(v, 0) + 1
}
// 2. Count vertices with odd degrees
val oddVertices = degrees.values.count { it % 2 != 0 }
// 3. Calculate minimum extra crossings needed
val extraCrossings = if (oddVertices <= 2) {
0
} else {
(oddVertices - 2) / 2
}
println(extraCrossings)
}To find the path with the minimum cost (fewest lives lost) in a 2D grid where each cell has a weight (hazard level), use Dijkstra's Algorithm with a Priority Queue. The algorithm ensures that the first time the destination cell is reached, the path taken is the absolute minimum cost.
Key implementation details:
minCosts) initialized to infinity to track the cheapest known cost to reach each cell.import java.io.File
import java.util.PriorityQueue
fun main() {
// 1. Parse the grid (20x20 comma-separated values)
val grid = File("dataset.txt").readLines().map { line ->
line.split(",").map { it.toInt() }
}
val rows = grid.size
val cols = grid[0].size
// 2. Dijkstra's Algorithm
// PriorityQueue stores Triple(TotalCost, Row, Col), ordered by Cost
val pq = PriorityQueue<Triple<Int, Int, Int>>(compareBy { it.first })
// Distance array to track the cheapest way to reach each cell found so far
val minCosts = Array(rows) { IntArray(cols) { Int.MAX_VALUE } }
// Start at (0,0). Cost includes the starting cell.
minCosts[0][0] = grid[0][0]
pq.add(Triple(grid[0][0], 0, 0))
val directions = arrayOf(-1 to 0, 1 to 0, 0 to -1, 0 to 1) // Up, Down, Left, Right
while (pq.isNotEmpty()) {
val (currentCost, r, c) = pq.poll()
// If we reached the target (bottom-right), we are done
if (r == rows - 1 && c == cols - 1) {
println(currentCost)
return
}
// Optimization: If we found a cheaper way to this cell already, skip
if (currentCost > minCosts[r][c]) continue
// Check neighbors
for ((dr, dc) in directions) {
val nr = r + dr
val nc = c + dc
if (nr in 0 until rows && nc in 0 until cols) {
val newCost = currentCost + grid[nr][nc]
if (newCost < minCosts[nr][nc]) {
minCosts[nr][nc] = newCost
pq.add(Triple(newCost, nr, nc))
}
}
}
}
}SELECT combined with FROM to extract specific columns (projection) from a logical table. You can perform calculations or logical comparisons directly within the SELECT list to create derived columns.SELECT
'London' AS place,
day,
hour,
phenomena,
temperature*9/5+32 AS "temperature in Fahrenheit",
feels_like < temperature AS "feels colder",
wind_speed AS "wind speed in m/s"
FROM
weather
;import java.io.File
fun main() {
val forksHeld = BooleanArray(5) // Index 1..4 for forks (0 unused)
var contentions = 0
File("dataset.txt").forEachLine { line ->
// Format: Name,action,forkId
val parts = line.split(",")
val action = parts[1]
val forkId = parts[2].toInt()
if (action == "pick") {
if (forksHeld[forkId]) {
// Fork is already held by someone else -> Contention!
contentions++
} else {
// Fork is free -> Elf successfully picks it up
forksHeld[forkId] = true
}
} else if (action == "release") {
// Elf puts the fork down
forksHeld[forkId] = false
}
}
println(contentions)
}