Tutorial by Examples: st

When some programmers see this advice: "Testing strings using == is incorrect (unless the strings are interned)" their initial reaction is to intern strings so that they can use ==. (After all == is faster than calling String.equals(...), isn't it.) This is the wrong approach, from...
A closure is a procedure that holds internal state: Define a procedure that returns a closure The procedure make-an-adder takes one argument x and returns a function that closes over the value. Or to put it another way, x is within the lexical scope of the returned function. #lang racket (define...
Prepared statements See Prepared statements in MySQLi for how to prepare and execute a query. Binding of results Object-oriented style $stmt->bind_result($forename); Procedural style mysqli_stmt_bind_result($stmt, $forename); The problem with using bind_result is that it requires the s...
One of the most important implementations of Dynamic Programming is finding out the Longest Common Subsequence. Let's define some of the basic terminologies first. Subsequence: A subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the orde...
GCobol >>SOURCE FORMAT IS FIXED *> *************************************************************** *> Purpose: Demonstrate a merge pass *> Tectonics: cobc -x gnucobol-merge-sample.cob *> *************************************************************** ...
From Odata.org OData (Open Data Protocol) is an OASIS standard that defines the best practice for building and consuming RESTful APIs. OData helps you focus on your business logic while building RESTful APIs without having to worry about the approaches to define request and response headers, ...
If you want to perform a user input validation of your textfield use the following code snippet: // MARK: - UITextFieldDelegate let allowedCharacters = CharacterSet(charactersIn:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvxyz").inverted func textField(_ textField:...
A common approach to get the top most UIViewController is to get the RootViewController of your active UIWindow. I wrote an extension for this: extension UIApplication { func topViewController(_ base: UIViewController? = UIApplication.shared.keyWindow?.rootViewController) -> UIViewController ...
Using the NotificationCenter of iOS, which can be very powerful, you are able to intercept certain app-wide events: NotificationCenter.default.addObserver( self, selector: #selector(ViewController.do(_:)), name: NSNotification.Name.UIApplicationDidBecomeActive, o...
Before reading this example, it is required to have a brief idea on edge-relaxation. You can learn it from here Bellman-Ford Algorithm is computes the shortest paths from a single source vertex to all of the other vertices in a weighted digraph. Even though it is slower than Dijkstra's Algorithm, i...
First, install the morgan Middleware in your project npm install --save morgan
Add the following code to your app.js file: var express = require('express') var morgan = require('morgan') var app = express() app.use(morgan('combined')) app.get('/', function (req, res) { res.send('hello, world!') }) Now when you access your website you will see in the console y...
First, install fs and path in your project npm install --save fs path Add the following code to your app.js file: var express = require('express') var fs = require('fs') var morgan = require('morgan') var path = require('path') var app = express() // create a write stream (in append mo...
First, install fs, file-stream-rotator and path in your project npm install --save fs file-stream-rotator path Add the following code to your app.js file: var FileStreamRotator = require('file-stream-rotator') var express = require('express') var fs = require('fs') var morgan = require('morg...
To understand this example, it is recommended to have a brief idea on Bellman-Ford single source shortest path algorithm which can be found here In Bellman-Ford algorithm, to find out the shortest path, we need to relax all the edges of the graph. This process is repeated at most (V-1) times, where...
using NLog; using NLog.Config; using NLog.Targets; namespace MyNamespace { [Target("MyFirst")] public sealed class MyFirstTarget: TargetWithLayout //or inherit from Target { public MyFirstTarget() { //set defaults ...
[LayoutRenderer("hello-world")] public class HelloWorldLayoutRenderer : LayoutRenderer { /// <summary> /// I'm option and not required or default /// </summary> public string Config1 { get; set; } /// <summary> /// I'm required option. ...
This would be a basic setup in wich we will send all the log messages to the console and to a log file. Let's start with the libraries. Will use maven for that: <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-api</artifact...
Adjacency list is a collection of unordered lists used to represent a finite graph. Each list describes the set of neighbors of a vertex in a graph. It takes less memory to store graphs. Let's see a graph, and its adjacency matrix: Now we create a list using these values. This is called adjacen...
use std::ops::Deref; use std::fmt::Debug; #[derive(Debug)] struct RichOption<T>(Option<T>); // wrapper struct impl<T> Deref for RichOption<T> { type Target = Option<T>; // Our wrapper struct will coerce into Option fn deref(&self) -> &Option...

Page 262 of 369