Skip to content

Instantly share code, notes, and snippets.

View ktprezes's full-sized avatar

Tadeusz Kurpiel ktprezes

View GitHub Profile
@ktprezes
ktprezes / linux-fsck-bad-blocks-search-remarks.txt
Last active August 23, 2023 19:46
Linux - fsck command and `bad blocks search / disk surface scan` - remarks
The `fsck` command (file system check) works as a kind of _wrapper_ for file-system-type-dependent specialized commands,
and the options allowed MAY VARY depending of the file system type...
For example:
- for `fat32` file system the `fsck.vfat` is used, and the `-c N` option selects the `DOS codepage`,
and the `-t` option tests for bad clusters
- for `ext4` file system the `e2fsck` is used, and checking for bad blocks requires the `-c` (read-only test) option
or the `-cc` (read/non-destructive-write test) option - and the `badblocks` command is used then under the hood
- some linux systems contain the `fsck.ntfs` command, but some don't. And it seems the `ntfsfix` command
doesn't offer the `bad blocks` check, and the `badblocks` command lists the bad bocks found, but apparently doesn't
update the `bad blocks list` of the device
@ktprezes
ktprezes / pandas_multiindex_selection.py
Last active August 15, 2023 12:28
Python - Pandas - MultiIndex DataFrame selections
import pandas as pd
# suppose we have a simple 'stocks' dataframe:
stocks = pd.read_csv('http://bit.ly/smallstocks')
"""# stocks
Date Close Volume Symbol
0 2016-10-03 31.50 14070500 CSCO
1 2016-10-03 112.52 21701800 AAPL
2 2016-10-03 57.42 19189500 MSFT
@ktprezes
ktprezes / palindrome_test.kt
Created May 1, 2023 09:58
kotlin - palindrome test - 3 implementations: string reversed, stack, stack with size optimized
import kotlin.collections.ArrayDeque
// version #1 - the shortest implementation
// fun checkPalindrome(word: String): Boolean = word.reversed() == word
// version #2 - 'pure stack' implementation
/*
fun checkPalindrome(word: String): Boolean {
if (word.isBlank())
return false
@ktprezes
ktprezes / kotlin_utils.kt
Created March 6, 2023 01:00
Kotlin utility functions 'safeReadln()' 'String.toIntOrDefault(...)', 'String.toDoubleOrDefault(...)'
// package some_kotlin_utils
/**
* handles the 'end of stream (EOF) case' - e.g. when the user presses "Ctrl-D" instead of typing a string;
* in this case returns the passed default value (e.g. "") instead of throwing an exception as 'plain' readln() does
*
* @param default String value returned when exception occurred
* @param printErrMsg Boolean when true prints the message connected with an exception to 'stderr'
*
* @return the user-entered string or the passed default value when an exception occurred
@ktprezes
ktprezes / UsageExample.kt
Created January 14, 2023 20:45
Kotlin - reading resource bundle from the XML file(s) instead of '.properties' file(s)
import utils.XMLResourceBundle
import utils.XMLResourceBundleControl
import java.util.*
fun main() {
val resBndl1 = ResourceBundle.getBundle("props", Locale.forLanguageTag("pl"), XMLResourceBundleControl())
println(resBndl1.getString("app_name") // prints: "Moja apka"
val resBndl2 = XMLResourceBundle.getBundle("props") // gets default Locale
println(resBndl2.getString("prop1") // prints: "Example 1"
@ktprezes
ktprezes / TestClass.java
Created January 12, 2023 20:21 — forked from asicfr/TestClass.java
Properties and ResourceBundle from Xml file
package test;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import java.util.ResourceBundle;
public class TestClass {
@ktprezes
ktprezes / GregorianCalendarPlayground1.java
Created June 20, 2022 15:53
Java GregorianCalendar strange behaviour - the difference between these 2 files is the presence of 'printf' with gregCal.get(...) functions only, and the results are different!!!
import java.util.Calendar;
import java.util.GregorianCalendar;
class GregorianCalendarPlayground1 {
public static void main(String[ ] args) {
Calendar gregCal = new GregorianCalendar();
// wrong date, but the class in default 'lenient' mode should maintain this
gregCal.set(0, Calendar.DECEMBER, 31);
@ktprezes
ktprezes / gist:31f2dbdee2e1298f0dd65eaf1df39864
Last active February 18, 2022 00:43
log4j2 troubleshooting
to troubleshoot the log4j (ver1.*) it was enough to provide the:
-Dlog4j.debug
option to the JVM, e.g.:
java -Dlog4j.debug -jar test.jar
the equivilent option for log4j2 is:
-Dlog4j2.debug
or:
-Dorg.apache.logging.log4j.simplelog.StatusLogger.level=trace
@ktprezes
ktprezes / (U)ByteArray extension functions.kt
Created January 14, 2022 10:42
Kotlin ByteArray and UByteArray 'toChars' and 'toHexDigitsString' extension functions
```kotlin
const val HEX_LOWERCASE_DIGITS = "0123456789abcdef"
const val HEX_UPPERCASE_DIGITS = "0123456789ABCDEF"
const val HEX_DIGITS = "0123456789ABCDEFabcdef"
// ======================================================================================
// ByteArray and UByteArray 'toChars' extension functions
//
@ktprezes
ktprezes / SplitString.kt
Last active July 9, 2022 21:49
Kotlin - splitting a string into individual characters
val string: String = "abcd"
val splitString: List<String> = string.map { it.toString() }
/*
EXPLANATION:
A) In Java, the output of the code:
String str = "abcd";
String[] splitString = str.split("");
System.out.println(Arrays.toString(splitString));
System.out.println(splitString[0].getClass());