ubuntuask.com
-
6 min readIn Kotlin, a null value represents the absence of a value in a variable. This can be useful when a variable may not have a value assigned to it at a given time. However, it is important to handle null values properly to prevent null pointer exceptions in your code.To work with null values in Kotlin, you can use nullable types. By appending a "?" to the type of a variable, you are indicating that it can accept null values. For example, if you declare a variable as "String.
-
7 min readTo write a HTTPS server using Rust, you can use the Hyper crate which is a fast and modern HTTP library for Rust. First, you need to add Hyper to your Cargo.toml file. Then, you can create a new Rust file and start implementing your server logic. You can use the hyper::Server module to create a new HTTPS server instance. You will need to provide a closure that defines the request handling logic.
-
3 min readIn Elixir, the capture operator (&) is used to capture functions so that they can be passed around as values. This allows functions to be stored in variables, passed as arguments to other functions, or returned as results from other functions. The capture operator simplifies code and makes it easier to work with functions in a functional programming style. It is particularly helpful when working with higher-order functions, such as Enum.map and Enum.
-
5 min readTo loop over two ArrayLists of different sizes in Kotlin, you can use a loop with an index variable that iterates over the smaller size of the two ArrayLists. Within the loop, you can access elements from both ArrayLists using the index variable. You can also check if you have reached the end of either ArrayList before accessing its element to avoid ArrayIndexOutOfBoundsException.
-
4 min readIn Rust, you can make a thread sleep or wait without using the standard library by using the std::thread::park_timeout function. This function allows you to block a thread for a specified amount of time before resuming its execution. You can also achieve this by creating a custom implementation of a sleep or wait function using low-level synchronization primitives like std::sync::Mutex, std::sync::Condvar, and std::time::Instant.
-
5 min readIn Elixir, the best way of error handling is using the try and rescue keywords to encapsulate code that may potentially raise an error. By wrapping the code in a try block, you can catch specific types of errors using rescue clauses and handle them accordingly. Additionally, the with keyword can be used for pattern matching on the result of expressions and handling errors in a more elegant and functional way.
-
7 min readTo configure HTTPS with Ktor in Kotlin, you can use the embedded Netty server provided by Ktor. First, you need to generate a self-signed SSL certificate or obtain a valid SSL certificate from a trusted certificate authority.Next, you can configure your application to use HTTPS by creating an instance of the SSLContext and setting it in the engine configuration. You can specify the SSL certificate and private key files in the configuration as well.
-
3 min readTo write a file per chunk in a stream in Elixir, you can use the Stream.chunk/3 function to split the stream into chunks of a specified size. Then, you can use the Enum.each/2 function to iterate over each chunk and write it to a file using the File.write/2 function. This allows you to efficiently process large streams of data without having to load the entire stream into memory at once.
-
4 min readIn Kotlin, you can avoid writing the same null check multiple times by using the safe call operator (?.) or the Elvis operator (?:).The safe call operator (?.) allows you to access properties or call methods on an object only if the object is not null. If the object is null, the expression returns null instead of throwing a NullPointerException.For example: val length = str?.length The Elvis operator (?:) is used to provide a default value in case the expression on the left is null.
-
5 min readIn Elixir, you can use the Regex.scan/3 function to find words matching a regular expression. This function takes in a string, a regular expression pattern, and options. It returns a list of all matches found in the string.Here's an example of how you can use Regex.scan/3 to find words in a string: string = "Hello World" pattern = ~r/\w+/ matches = Regex.scan(pattern, string) IO.
-
5 min readIn Kotlin, you can reference a property from a different class by using dot notation. If the property is public, you can simply write the class name followed by a dot and then the property name. If the property is private, you will need to create a getter method in the class containing the property and then use that method to access the property from another class.