Tutorial by Examples: ce

If you need to remove one or more elements from a slice, or if you need to work with a sub slice of another existing one; you can use the following method. Following examples uses slice of int, but that works with all type of slice. So for that, we need a slice, from witch we will remove some ...
Maps in go are not safe for concurrency. You must take a lock to read and write on them if you will be accessing them concurrently. Usually the best option is to use sync.RWMutex because you can have read and write locks. However, a sync.Mutex could also be used. type RWMap struct { sync.RWMut...
Example: Get a Stream of 30 elements, containing 21st to 50th (inclusive) element of a collection. final long n = 20L; // the number of elements to skip final long maxSize = 30L; // the number of elements the stream should be limited to final Stream<T> slice = collection.stream().skip(n).li...
3.0 In Swift 3 there are multiple access-levels. This example uses them all except for open: public struct Car { public let make: String let model: String //Optional keyword: will automatically be "internal" private let fullName: String fileprivate var otherName...
To add a reference to a team to the users table, run this command: $ rails generate migration AddTeamRefToUsers team:references This generates the following migration: class AddTeamRefToUsers < ActiveRecord::Migration[5.0] def change add_reference :users, :team, foreign_key: true ...
Use the : operator to create sequences of numbers, such as for use in vectorizing larger chunks of your code: x <- 1:5 x ## [1] 1 2 3 4 5 This works both ways 10:4 # [1] 10 9 8 7 6 5 4 and even with floating point numbers 1.25:5 # [1] 1.25 2.25 3.25 4.25 or negatives -4:4 ...
The services lifecycle has the following callbacks onCreate() : Executed when the service is first created in order to set up the initial configurations you might need. This method is executed only if the service is not already running. onStartCommand() : Executed every time startService...
Some convenience functions to manipulate data.frames are subset(), transform(), with() and within(). subset The subset() function allows you to subset a data.frame in a more convenient way (subset also works with other classes): subset(mtcars, subset = cyl == 6, select = c("mpg", "...
This will delete all rows that match the WHERE criteria. DELETE FROM Employees WHERE FName = 'John'
Once you've got all your settings, you'll want to use them in your code. To do so, add the following import to your file: from django.conf import settings You may then access your settings as attributes of the settings module, for example: if not settings.DEBUG: email_user(user, message) ...
This snippet will grab a JSON formatted resource, decode it and print it in PHP array format. // Fetch $response = wp_remote_get( 'http://www.example.com/resource.json' ); if ( ! is_wp_error( $response ) ) { $headers = wp_remote_retrieve_headers( $response ); if ( isset( $headers[ 'con...
Trim is used to remove write-space at the beginning or end of selection In MSSQL there is no single TRIM() SELECT LTRIM(' Hello ') --returns 'Hello ' SELECT RTRIM(' Hello ') --returns ' Hello' SELECT LTRIM(RTRIM(' Hello ')) --returns 'Hello' MySql and Oracle SELECT TRIM(' Hello ') ...
Inject and reduce are different names for the same thing. In other languages these functions are often called folds (like foldl or foldr). These methods are available on every Enumerable object. Inject takes a two argument function and applies that to all of the pairs of elements in the Array. For...
You can access the elements of an array by their indices. Array index numbering starts at 0. %w(a b c)[0] # => 'a' %w(a b c)[1] # => 'b' You can crop an array using range %w(a b c d)[1..2] # => ['b', 'c'] (indices from 1 to 2, including the 2) %w(a b c d)[1...2] # => ['b'] (indic...
Here is an example of a service that greets people by the given name, and keeps track of how many users it encountered. See usage below. %% greeter.erl %% Greets people and counts number of times it did so. -module(greeter). -behaviour(gen_server). %% Export API Functions -export([start_link/0...
If the variable contains a value of an immutable type (e.g. a string) then it is okay to assign a default value like this class Rectangle(object): def __init__(self, width, height, color='blue'): self.width = width self.height = height self.color = color d...
The MATLAB Profiler is a tool for software profiling of MATLAB code. Using the Profiler, it is possible to obtain a visual representation of both execution time and memory consumption. Running the Profiler can be done in two ways: Clicking the "Run and Time" button in the MATLAB GUI...
The module cmath includes additional functions to use complex numbers. import cmath This module can calculate the phase of a complex number, in radians: z = 2+3j # A complex number cmath.phase(z) # 0.982793723247329 It allows the conversion between the cartesian (rectangular) and polar repr...
This a basic example aimed at new users. It does not focus on explaining the difference between char and cellstring. It might happen that you want to get rid of the ' in your strings, although you never added them. In fact, those are artifacts that the command window uses to distinguish between ...
if ($PSCmdlet.ShouldProcess("Target of action")) { # Do the thing } When using -WhatIf: What if: Performing the action "Invoke-MyCmdlet" on target "Target of action" When using -Confirm: Are you sure you want to perform this action? Performing operation &qu...

Page 14 of 134