Tutorial by Examples: a

This example will guide you through setting up a back end serving an a Hello World HTML page. Installing Requirements Order matters for this step! sudo apt-get install apache2 Setting up the HTML Apache files live in /var/www/html/. Lets quickly get there. Make sure you're in your root ...
Checking if session cookies have been created Session name is the name of the cookie used to store sessions. You can use this to detect if cookies for a session have been created for the user: if(isset($_COOKIE[session_name()])) { session_start(); } Note that this method is generally not ...
Constants can be defined inside classes using a const keyword. class Foo { const BAR_TYPE = "bar"; // reference from inside the class using self:: public function myMethod() { return self::BAR_TYPE; } } // reference from outside the class using <Class...
You can use the filter(_:) method on SequenceType in order to create a new array containing the elements of the sequence that satisfy a given predicate, which can be provided as a closure. For example, filtering even numbers from an [Int]: let numbers = [22, 41, 23, 30] let evenNumbers = number...
In Swift, we can exponentiate Doubles with the built-in pow() method: pow(BASE, EXPONENT) In the code below, the base (5) is set to the power of the exponent (2) : let number = pow(5.0, 2.0) // Equals 25
Any data structure that supports __getitem__ can have their nested structure formatted: person = {'first': 'Arthur', 'last': 'Dent'} '{p[first]} {p[last]}'.format(p=person) # 'Arthur Dent' Object attributes can be accessed using getattr(): class Person(object): first = 'Zaphod' la...
Lambda functions in C++ are syntactic sugar that provide a very concise syntax for writing functors. As such, equivalent functionality can be obtained in C++03 (albeit much more verbose) by converting the lambda function into a functor: // Some dummy types: struct T1 {int dummy;}; struct T2 {int ...
There are two main versions of IntelliJ IDEA: the Community edition and the Ultimate edition. The Community edition is free and is not lacking for features in terms of Java SE development. Windows & Linux Download IntelliJ IDEA from the JetBrains website, and follow installation procedures. If...
There are a couple of ways to delete a column in a DataFrame. import numpy as np import pandas as pd np.random.seed(0) pd.DataFrame(np.random.randn(5, 6), columns=list('ABCDEF')) print(df) # Output: # A B C D E F # 0 -0.895467 0.386902...
This example assumes you know how to test a Flask app using pytest Below is an API that takes a JSON input with integer values a and b e.g. {"a": 1, "b": 2}, adds them up and returns sum a + b in a JSON response e.g. {"sum": 3}. # hello_add.py from flask import Flask...
Generics are placeholders for types, allowing you to write flexible code that can be applied across multiple types. The advantage of using generics over Any is that they still allow the compiler to enforce strong type-safety. A generic placeholder is defined within angle brackets <>. Generic...
cURL is a tool for transferring data with URL syntax. It support HTTP, FTP, SCP and many others(curl >= 7.19.4). Remember, you need to install and enable the cURL extension to use it. // a little script check is the cURL extension loaded or not if(!extension_loaded("curl")) { die...
Broadcast variables are read only shared objects which can be created with SparkContext.broadcast method: val broadcastVariable = sc.broadcast(Array(1, 2, 3)) and read using value method: val someRDD = sc.parallelize(Array(1, 2, 3, 4)) someRDD.map( i => broadcastVariable.value.apply(...
Accumulators are write-only variables which can be created with SparkContext.accumulator: val accumulator = sc.accumulator(0, name = "My accumulator") // name is optional modified with +=: val someRDD = sc.parallelize(Array(1, 2, 3, 4)) someRDD.foreach(element => accumulator += el...
The two parameters to Range are the first number and the count of elements to produce (not the last number). // prints 1,2,3,4,5,6,7,8,9,10 Console.WriteLine(string.Join(",", Enumerable.Range(1, 10))); // prints 10,11,12,13,14 Console.WriteLine(string.Join(",", Enumerable.R...
fs.access() determines whether a path exists and what permissions a user has to the file or directory at that path. fs.access doesn't return a result rather, if it doesn't return an error, the path exists and the user has the desired permissions. The permission modes are available as a property on ...
Due to Node's asynchronous nature, creating or using a directory by first: checking for its existence with fs.stat(), then creating or using it depending of the results of the existence check, can lead to a race condition if the folder is created between the time of the check and the time of ...
In Android, a Toast is a simple UI element that can be used to give contextual feedback to a user. To display a simple Toast message, we can do the following. // Declare the parameters to use for the Toast Context context = getApplicationContext(); // in an Activity, you may also use "th...
If you don't want to use the default Toast view, you can provide your own using the setView(View) method on a Toast object. First, create the XML layout you would like to use in your Toast. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="...
cursor: value; Examples: ValueDescriptionnoneNo cursor is rendered for the elementautoDefault. The browser sets a cursorhelpThe cursor indicates that help is availablewaitThe cursor indicates that the program is busymoveThe cursor indicates something is to be movedpointerThe cursor is a pointe...

Page 174 of 1099