Tutorial by Examples: v

HTML <div class="wrap"> <img src="http://lorempixel.com/400/200/" /> </div> CSS .wrap { height: 50px;/* max image height */ width: 100px; border: 1px solid blue; text-align: center; } .wrap:before { content:""; di...
By injecting $filter, any defined filter in your Angular module may be used in controllers, services, directives or even other filters. angular.module("app") .service("users", usersService) .controller("UsersController", UsersController); function usersService...
3.0 let someString = " Swift Language \n" let trimmedString = someString.stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceAndNewlineCharacterSet()) // "Swift Language" Method stringByTrimmingCharactersInSet returns a new string made by removing from both ends of t...
A method can be converted to a closure using the & operator. def add(def a, def b) { a + b } Closure addClosure = this.&add assert this.add(4, 5) == addClosure(4, 5)
Early Bound (with a reference to Microsoft Scripting Runtime) Sub EnumerateFilesAndFolders( _ FolderPath As String, _ Optional MaxDepth As Long = -1, _ Optional CurrentDepth As Long = 0, _ Optional Indentation As Long = 2) Dim FSO As Scripting.FileSystemObject Set ...
Declaring an array is very similar to declaring a variable, except you need to declare the dimension of the Array right after its name: Dim myArray(9) As String 'Declaring an array that will contain up to 10 strings By default, Arrays in VBA are indexed from ZERO, thus, the number inside the par...
When using non-lazy translation, strings are translated immediately. >>> from django.utils.translation import activate, ugettext as _ >>> month = _("June") >>> month 'June' >>> activate('fr') >>> _("June") 'juin' >>> a...
MySQL does not provide a built-in way to create pivot queries. However, these can be created using prepared statements. Assume the table tbl_values: IdNameGroupValue1PeteA102PeteB203JohnA10 Request: Create a query that shows the sum of Value for each Name; the Group must be column header and Name...
1) Create a Contract Class A contract class defines constants that help applications work with the content URIs, column names, intent actions, and other features of a content provider. Contract classes are not included automatically with a provider; the provider's developer has to define them and t...
globalize gem is a great solution to add translations to your ActiveRecord models. You can install it adding this to your Gemfile: gem 'globalize', '~> 5.0.0' If you're using Rails 5 you will also need to add activemodel-serializers-xml gem 'activemodel-serializers-xml' Model translations...
You will often find yourself with a collection of data where you are only interested in parts of the data. In the example below we got a list of participants at an event and we want to provide a the tour guide with a simple list of names. // First we collect the participants $participants = colle...
Collections also provide you with an easy way to do simple statistical calculations. $books = [ ['title' => 'The Pragmatic Programmer', 'price' => 20], ['title' => 'Continuous Delivery', 'price' => 30], ['title' => 'The Clean Coder', 'price' => 10], ] $min = col...
Simple recursion Using recursion and the ternary conditional operator, we can create an alternative implementation of the built-in factorial function: myfactorial(n) = n == 0 ? 1 : n * myfactorial(n - 1) Usage: julia> myfactorial(10) 3628800 Working with trees Recursive functions are o...
A long-form syntax is available for defining multi-line functions. This can be useful when we use imperative structures such as loops. The expression in tail position is returned. For instance, the below function uses a for loop to compute the factorial of some integer n: function myfactorial(n) ...
C++11 It's possible to write a generic function (for example min) which accepts various numerical types and arbitrary argument count by template meta-programming. This function declares a min for two arguments and recursively for more. template <typename T1, typename T2> auto min(const T1 &...
std::function can cause significant overhead. Because std::function has [value semantics][1], it must copy or move the given callable into itself. But since it can take callables of an arbitrary type, it will frequently have to allocate memory dynamically to do this. Some function implementations h...
Using credentials from your local computer: Enter-PSSession 192.168.1.1 Prompting for credentials on the remote computer Enter-PSSession 192.168.1.1 -Credential $(Get-Credential)
static void Main(string[] args) { string url = "www.stackoverflow.com"; var pingTask = PingUrlAsync(url); Console.WriteLine($"Waiting for response from {url}"); Task.WaitAll(pingTask); Console.WriteLine(pingTask.Re...
A basic AppComponent that depends on a single AppModule to provide application-wide singleton objects. @Singleton @Component(modules = AppModule.class) public interface AppComponent { void inject(App app); Context provideContext(); Gson provideGson(); } A module to use to...
java.util.Date to java.sql.Date conversion is usually necessary when a Date object needs to be written in a database. java.sql.Date is a wrapper around millisecond value and is used by JDBC to identify an SQL DATE type In the below example, we use the java.util.Date() constructor, that creates a D...

Page 82 of 296