A String can be read from an InputStream using the byte array constructor.
import java.io.*;
public String readString(InputStream input) throws IOException {
byte[] bytes = new byte[50]; // supply the length of the string in bytes here
input.read(bytes);
return new String(bytes);
...
This code compiles:
Integer arg = null;
int x = arg;
But it will crash at runtime with a java.lang.NullPointerException on the second line.
The problem is that a primitive int cannot have a null value.
This is a minimalistic example,
but in practice it often manifests in more sophisticated f...
CL-PPCRE:REGISTER-GROUPS-BIND will match a string against a regular expression, and if it matches, bind register groups in the regex to variables. If the string does not match, NIL is returned.
(defun parse-date-string (date-string)
(cl-ppcre:register-groups-bind
(year month day)
(...
Prolog doesn't have iteration, but all iteration can be rewritten using recursion. Recursion appears when a predicate contains a goal that refers to itself. When writing such predicates in Prolog, a standard recursive pattern always has at least two parts:
Base (non-recursive) clause: Typically...
The ref keyword for callers of methods is now optional when calling into methods supplied by COM interfaces. Given a COM method with the signature
void Increment(ref int x);
the invocation can now be written as either
Increment(0); // no need for "ref" or a place holder variable any m...
The proof tree (also search tree or derivation tree) is a tree that shows the execution of a Prolog program. This tree helps visualise the chronological backtracking process present in Prolog. The root of the tree represents the initial query and branches are created when choice points occur. Every ...
This example uses Parallel.ForEach to calculate the sum of the numbers between 1 and 10000 by using multiple threads. To achieve thread-safety, Interlocked.Add is used to sum the numbers.
using System.Threading;
int Foo()
{
int total = 0;
var numbers = Enumerable.Range(1, 10000).ToLis...
POST requests are made with the request.post() method.
If you need to send a web form request as a POST body, pass in a dictionary with key-value pairs as the data argument; requests will encode these to a application/x-www-form-urlencoded mimetype body:
r = requests.post('https://github.com/', d...
Dereferencing happens with the . operator:
Object obj = new Object();
String text = obj.toString(); // 'obj' is dereferenced.
Dereferencing follows the memory address stored in a reference, to the place in memory where the actual object resides. When an object has been found, the requested meth...
The requests module has top-level functions for most HTTP methods:
r = requests.put('https://example.com/', data=put_body)
r = requests.delete('https://example.com/')
r = requests.head('https://example.com/')
r = requests.options('https://example.com/')
r = requests.patch('https://example.com/'...
When a response contains valid JSON, just use the .json() method on the Response object to get the decoded result:
response = requests.get('http://example.com/')
decoded_result = response.json()
However, this does not fail gracefully; it will raise a JSONDecodeError if the response object is no...
Docker volumes are not automatically removed when a container is stopped. To remove associated volumes when you stop a container:
docker rm -v <container id or name>
If the -v flag is not specified, the volume remains on-disk as a 'dangling volume'. To delete all dangling volumes:
docker ...
Declaration
A common misunderstanding, especially beginners, have is read-only property is the one marked with readonly keyword. That's not correct and in fact following is a compile time error:
public readonly string SomeProp { get; set; }
A property is read-only when it only has a getter.
pu...
K&R
void* is a catch all type for pointers to object types. An example of this in use is with the malloc function, which is declared as
void* malloc(size_t);
The pointer-to-void return type means that it is possible to assign the return value from malloc to a pointer to any other type of ob...
Conditional expressions can be done with ~[ and ~]. The clauses of the expression are separated using ~;.
By default, ~[ takes an integer from the argument list, and picks the corresponding clause. The clauses start at zero.
(format t "~@{~[First clause~;Second clause~;Third clause~;Fourth cl...
With Clipping and Masking you can make some specified parts of elements transparent or opaque. Both can be applied to any HTML element.
Clipping
Clips are vector paths. Outside of this path the element will be transparent, inside it's opaque. Therefore you can define a clip-path property on elemen...
- removeObjectForKey:
Removes a given key and its associated value from the dictionary.
NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithDictionary:@{@"key1":@"Easy",@"key2": @"Tutorials"}];
[dict removeObjectForKey:@"key1"];
NSLog...
In this example will render five <li> tags
<ul id="render-sample">
<li v-for="n in 5">
Hello Loop
</li>
</ul>
Public Function GetUserFirstName(UserName As String) As String
Dim Firstname As String = ""
'Specify the SQL that you want to use including a Parameter
Dim SQL As String = "select firstname from users where username=@UserName"
'Provide a Data Sourc...