Tutorial by Examples: ga

val list = listOf(1,2,3,4,5,6) //filter out even numbers val even = list.filter { it % 2 == 0 } println(even) //returns [2,4]
To add a method to a button, first create an action method: Objective-C -(void) someButtonAction{ NSLog(@"Button is tapped"); } Swift func someButtonAction() { print("Button is tapped") } Now to add this action method to your button, you have to wri...
There are several sort functions for arrays in php: sort() Sort an array in ascending order by value. $fruits = ['Zitrone', 'Orange', 'Banane', 'Apfel']; sort($fruits); print_r($fruits); results in Array ( [0] => Apfel [1] => Banane [2] => Orange [3] => Zitr...
View file: <?php use yii; use yii\bootstrap\ActiveForm; use yii\helpers\Html; ?> <?php $form = ActiveForm::begin([ 'action' => ['comments/ajax-comment'], 'options' => [ 'class' => 'comment-form' ] ]); ?> <?= $form->field($model, '...
To set a cookie i.e. to create it and schedule for sending to the browser you need to create new \yii\web\Cookie class instance and add it to response cookies collection: $cookie = new Cookie([ 'name' => 'cookie_monster', 'value' => 'Me want cookie!', 'expire' => time() + 86...
In order to read a cookie use the following code: $value = \Yii::$app->getRequest()->getCookies()->getValue('my_cookie'); Note: this code allows read cookies that has been set using cookie component (because it signs all cookies by default). Therefore if you add/update cookie using JS c...
A less known builtin feature is Controller Action injection using the FromServicesAttribute. [HttpGet] public async Task<IActionResult> GetAllAsync([FromServices]IProductService products) { return Ok(await products.GetAllAsync()); } An important note is that the [FromServices] c...
Given a Person struct struct Person { let name: String let birthYear: Int? } and an Array of Person(s) let persons = [ Person(name: "Walter White", birthYear: 1959), Person(name: "Jesse Pinkman", birthYear: 1984), Person(name: "Skyler White&quo...
Variable tensors are used when the values require updating within a session. It is the type of tensor that would be used for the weights matrix when creating neural networks, since these values will be updated as the model is being trained. Declaring a variable tensor can be done using the tf.Varia...
In PaaS sites such as Heroku, it is usual to receive the database information as a single URL environment variable, instead of several parameters (host, port, user, password...). There is a module, dj_database_url which automatically extracts the DATABASE_URL environment variable to a Python dictio...
To connect to MySQL you need to use the MySQL Connector/J driver. You can download it from http://dev.mysql.com/downloads/connector/j/ or you can use Maven: <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version...
Android Studio can configure Kotlin automatically in an Android project. Install the plugin To install the Kotlin plugin, go to File > Settings > Editor > Plugins > Install JetBrains Plugin... > Kotlin > Install, then restart Android Studio when prompted. Configure a project Cr...
In order to include plots created with matplotlib in TeX documents, they should be saved as pdf or eps files. In this way, any text in the plot (including TeX formulae) is rendered as text in the final document. import matplotlib.pyplot as plt plt.rc(usetex=True) x = range(0, 10) y = [t**2 for t...
If you want to access a workbook that's already open, then getting the assignment from the Workbooks collection is straightforward: dim myWB as Workbook Set myWB = Workbooks("UsuallyFullPathnameOfWorkbook.xlsx") If you want to create a new workbook, then use the Workbooks collection o...
Often saving new data in an existing workbook using VBA will cause a pop-up question noting that the file already exists. To prevent this pop-up question, you have to suppress these types of alerts. Application.DisplayAlerts = False 'disable user prompt to overwrite file myWB.SaveAs FileNa...
To create a project called helloworld run: stack new helloworld simple This will create a directory called helloworld with the files necessary for a Stack project.
app.js const readline = require('readline'); const fs = require('fs'); var file = 'path.to.file'; var rl = readline.createInterface({ input: fs.createReadStream(file), output: process.stdout, terminal: false }); rl.on('line', function (line) { console.log(line) // print...
Download and install Xamarin Studio Community. Open Xamarin Studio. Click File → New → Solution. Click .NET → Console Project and choose C#. Click Next to proceed. Enter the Project Name and Browse... for a Location to Save and then click Create. The newly created project w...
Creating the JFrame Creating a window is easy. You just have to create a JFrame. JFrame frame = new JFrame(); Titling the Window You may wish to give your window a title. You can so do by passing a string when creating the JFrame, or by calling frame.setTitle(String title). JFrame frame = new...
You can build a JSON object tree (a JsValue) manually import play.api.libs.json._ val json = JsObject(Map( "name" -> JsString("Jsony McJsonface"), "age" -> JsNumber(18), "hobbies" -> JsArray(Seq( JsString("Fishing"), ...

Page 47 of 137