Tutorial by Examples: ad

IPv4 To match IPv4 address format, you need to check for numbers [0-9]{1,3} three times {3} separated by periods \. and ending with another number. ^(?:[0-9]{1,3}\.){3}[0-9]{1,3}$ This regular expression is too simple - if you want to it to be accurate, you need to check that the numbers are be...
This is an example of something that would have been straight up impossible with labels. If you execute the same label multiple times at the same time and they rely on variables that are being defined within them, they very likely interfere and cause unexpected behavior. Here is how to do it with f...
The lists form a monad. They have a monad instantiation equivalent to this one: instance Monad [] where return x = [x] xs >>= f = concat (map f xs) We can use them to emulate non-determinism in our computations. When we use xs >>= f, the function f :: a -> [b...
This error occurs when tables are not adequately structured to handle the speedy lookup verification of Foreign Key (FK) requirements that the developer is mandating. CREATE TABLE `gtType` ( `type` char(2) NOT NULL, `description` varchar(1000) NOT NULL, PRIMARY KEY (`type`) ) ENGINE=InnoD...
As of GHC 7.10, Applicative is a superclass of Monad (i.e., every type which is a Monad must also be an Applicative). All the methods of Applicative (pure, <*>) can be implemented in terms of methods of Monad (return, >>=). It is obvious that pure and return serve equivalent purposes, ...
My.Computer.Network.DownloadFile("ftp://server.my/myfile.txt", "donwloaded_file.txt") This command download myfile.txt file from server named server.my and saves it as donwloaded_file.txt into working directory. You can specify absolute path for downloaded file.
My.Computer.Network.DownloadFile("ftp://srv.my/myfile.txt", "donwload.txt", "Peter", "1234") This command download myfile.txt file from server named srv.my and saves it as donwload.txt into working directory. You can specify absolute path for downloaded fil...
My.Computer.Network.UploadFile("example.txt", "ftp://server.my/server_example.txt") This command upload example.txt file from working directory (you could specify absolute path if you want) to server named server.my. File stored on the server will be named server_example.txt. ...
My.Computer.Network.UploadFile("doc.txt", "ftp://server.my/on_server.txt", "Peter", "1234") This command upload doc.txt file from working directory (you could specify absolute path if you want) to server named server.my. File stored on the server will be na...
Remember to create folder for upload (uploads in example). install multer npm i -S multer server.js: var express = require("express"); var multer = require('multer'); var app = express(); var fs = require('fs'); app.get('/',function(req,res){ res.sendFil...
Creates an image representing a gradient of colors radiating from the center of the gradient radial-gradient(red, orange, yellow) /*A gradient coming out from the middle of the gradient, red at the center, then orange, until it is finally yellow at the edges*/
It can be useful to load a resource (image, text file, properties, KeyStore, ...) that is packaged inside a JAR. For this purpose, we can use the Class and ClassLoaders. Suppose we have the following project structure : program.jar | \-com \-project | |-file.txt \-Test.class ...
public void iterate(final String dirPath) throws IOException { final DirectoryStream<Path> paths = Files.newDirectoryStream(Paths.get(dirPath)); for (final Path path : paths) { if (Files.isDirectory(path)) { System.out.println(path.getFileName()); } } ...
Example: Invoke different constructors by passing relevant parameters import java.lang.reflect.*; class NewInstanceWithReflection{ public NewInstanceWithReflection(){ System.out.println("Default constructor"); } public NewInstanceWithReflection( String a){ ...
import java.util.ArrayList; import java.util.List; import static java.lang.System.out; public class PolymorphismDemo { public static void main(String[] args) { List<FlyingMachine> machines = new ArrayList<FlyingMachine>(); machines.add(new FlyingMachine())...
Quite often it's necessary to send/upload a file to a remote server, for example, an image, video, audio or a backup of the application database to a remote private server. Assuming the server is expecting a POST request with the content, here's a simple example of how to complete this task in Andro...
We can run custom JavaScript on a UIWebView using the method stringByEvaluatingJavaScriptFromString().This method returns the result of running the JavaScript script passed in the script parameter, or nil if the script fails. Swift Load script from String webview.stringByEvaluatingJavaScriptFromS...
Instead of web pages, we can also load the document files into iOS WebView like .pdf, .txt, .doc etc.. loadData method is used to load NSData into webview. Swift //Assuming there is a text file in the project named "home.txt". let localFilePath = NSBundle.mainBundle().pathForResource(&...
Creating Gradient UIImage with colors in CGRect Swift: extension UIImage { static func gradientImageWithBounds(bounds: CGRect, colors: [CGColor]) -> UIImage { let gradientLayer = CAGradientLayer() gradientLayer.frame = bounds gradientLayer.colors = colors ...
+ (CALayer *)gradientBGLayerForBounds:(CGRect)bounds colors:(NSArray *)colors { CAGradientLayer * gradientBG = [CAGradientLayer layer]; gradientBG.frame = bounds; gradientBG.colors = colors; return gradientBG; }

Page 47 of 114