Tutorial by Examples: bas

The basic idea of a class template is that the template parameter gets substituted by a type at compile time. The result is that the same class can be reused for multiple types. The user specifies which type will be used when a variable of the class is declared. Three examples of this are shown in m...
Django ORM is a powerful abstraction that lets you store and retrieve data from the database without writing sql queries yourself. Let's assume the following models: class Author(models.Model): name = models.CharField(max_length=50) class Book(models.Model): name = models.CharField(max...
At some point in your use of Django, you may find yourself wanting to interact with tables which have already been created, or with database views. In these cases, you would not want Django to manage the tables through its migrations. To set this up, you need to add only one variable to your model's...
main.go: package main import ( "fmt" ) func main() { fmt.Println(Sum(4,5)) } func Sum(a, b int) int { return a + b } main_test.go: package main import ( "testing" ) // Test methods start with `Test` func TestSum(t *testing.T) { go...
SelectorDescription*Universal selector (all elements)divTag selector (all <div> elements).blueClass selector (all elements with class blue).blue.redAll elements with class blue and red (a type of Compound selector)#headlineID selector (the element with "id" attribute set to headline)...
Go supports pointers, allowing you to pass references to values and records within your program. package main import "fmt" // We'll show how pointers work in contrast to values with // 2 functions: `zeroval` and `zeroptr`. `zeroval` has an // `int` parameter, so arguments will be ...
What’s a component? A component is basically a directive that uses a simpler configuration and that is suitable for a component-based architecture, which is what Angular 2 is all about. Think of a component as a widget: A piece of HTML code that you can reuse in several different places in y...
Tensorflow is more than just a deep learning framework. It is a general computation framework to perform general mathematical operations in a parallel and distributed manner. An example of such is described below. Linear Regression A basic statistical example that is commonly utilized and is r...
json.Marshal from the package "encoding/json" encodes a value to JSON. The parameter is the value to encode. The returned values are an array of bytes representing the JSON-encoded input (on success), and an error (on failure). decodedValue := []string{"foo", "bar"} ...
json.Unmarshal from the package "encoding/json" decodes a JSON value into the value pointed by the given variable. The parameters are the value to decode in []bytes and a variable to use as a storage for the de-serialized value. The returned value is an error (on failure). encodedValue :...
The Premain class will contain the method "premain(String agentArgs Instrumentation inst)" Here is an example: import java.lang.instrument.Instrumentation; public class PremainExample { public static void premain(String agentArgs, Instrumentation inst) { System.out.print...
let list1 = [ 1; 2 ] let list2 = [ 1 .. 100 ] // Accessing an element printfn "%A" list1.[0] // Pattern matching let rec patternMatch aList = match aList with | [] -> printfn "This is an empty list" | head::tail -> printfn "This list consists o...
Database transactions ensure that a set of data changes will only be made permanent if every statement is successful. Any query or code failure during a transaction can be caught and you then have the option to roll back the attempted changes. PDO provides simple methods for beginning, committing,...
Functions are declared using the fun keyword, followed by a function name and any parameters. You can also specify the return type of a function, which defaults to Unit. The body of the function is enclosed in braces {}. If the return type is other than Unit, the body must issue a return statement ...
Routing defines a map between HTTP methods and URIs on one side, and actions on the other. Routes are normally written in the app/Http/routes.php file. In its simplest form, a route is defined by calling the corresponding HTTP method on the Route facade, passing as parameters a string that match...
You can validate request data using the validate method (available in the base Controller, provided by the ValidatesRequests trait). If the rules pass, your code will keep executing normally; however, if validation fails, an error response containing the validation errors will automatically be se...
return Socialite::driver('facebook')->redirect(); This will redirect an incoming request to the appropriate URL to be authenticated. A basic example would be in a controller <?php namespace App\Http\Controllers\Auth; use Socialite; class AuthenticationController extends Controller...
/** * LoginController constructor. * @param Socialite $socialite */ public function __construct(Socialite $socialite) { $this->socialite = $socialite; } Within the constructor of your Controller, you're now able to inject the Socialite class that will help you handle login with so...
Creating a Trait trait Speak { fn speak(&self) -> String; } Implementing a Trait struct Person; struct Dog; impl Speak for Person { fn speak(&self) -> String { String::from("Hello.") } } impl Speak for Dog { fn speak(&self) ->...
First, remove autopublish. autopublish automatically publishes the entire database to the client-side, and so the effects of publications and subscriptions cannot be seen. To remove autopublish: $ meteor remove autopublish Then you can create publications. Below is a full example. import { Mon...

Page 9 of 65