Tutorial by Examples: c

# For Python 2 compatibility. from __future__ import print_function import lxml.html import requests def main(): r = requests.get("https://httpbin.org") html_source = r.text root_element = lxml.html.fromstring(html_source) # Note root_element.xpath() gives a *...
Given a String and a Character let text = "Hello World" let char: Character = "o" We can count the number of times the Character appears into the String using let sensitiveCount = text.characters.filter { $0 == char }.count // case-sensitive let insensitiveCount = text.low...
Add gem to the Gemfile: gem 'devise' Then run the bundle install command. Use command $ rails generate devise:install to generate required configuration file. Set up the default URL options for the Devise mailer in each environment In development environment add this line: config.action_mailer...
Boolean(0) === false Boolean(0) will convert the number 0 into a boolean false. A shorter, but less clear, form: !!0 === false
To convert a string to boolean use Boolean(myString) or the shorter but less clear form !!myString All strings except the empty string (of length zero) are evaluated to true as booleans. Boolean('') === false // is true Boolean("") === false // is true Boolean('0') === fals...
If the values in a container have certain operators already overloaded, std::sort can be used with specialized functors to sort in either ascending or descending order: C++11 #include <vector> #include <algorithm> #include <functional> std::vector<int> v = {5,1,2,4,3};...
If you have created a table with some wrong schema, then the easiest way to change the columns and their properties is change_table. Review the following example: change_table :orders do |t| t.remove :ordered_at # removes column ordered_at t.string :skew_number # adds a new column t.index...
Managed resources are resources that the runtime's garbage collector is aware and under control of. There are many classes available in the BCL, for example, such as a SqlConnection that is a wrapper class for an unmanaged resource. These classes already implement the IDisposable interface -- it's u...
It's important to let finalization ignore managed resources. The finalizer runs on another thread -- it's possible that the managed objects don't exist anymore by the time the finalizer runs. Implementing a protected Dispose(bool) method is a common practice to ensure managed resources do not have t...
Iterating over List List<String> names = new ArrayList<>(Arrays.asList("Clementine", "Duran", "Mike")); Java SE 8 names.forEach(System.out::println); If we need parallelism use names.parallelStream().forEach(System.out::println); Java SE 5 fo...
class UsersController < ApplicationController def index respond_to do |format| format.html { render html: "Hello World" } end end end This is a basic controller, with the addition of the following route (in routes.rb): resources :users, only: [:index] Will...
class UsersController < ApplicationController def index respond_to do |format| format.html do render html: "Hello #{ user_params[:name] } user_params[:sentence]" end end end private def user_params if params[:name] == "john&quo...
Assuming the route: resources :users, only: [:index] You can redirect to a different URL using: class UsersController def index redirect_to "http://stackoverflow.com/" end end You can go back to the previous page the user visited using: redirect_to :back Note that i...
resources :photos do member do get 'preview' end collection do get 'dashboard' end end This creates the following routes in addition to default 7 RESTful routes: get '/photos/:id/preview', to: 'photos#preview' get '/photos/dashboards', to: '...
From guides.rubyonrails.org: Instead of generating a model directly . . . let's set up a scaffold. A scaffold in Rails is a full set of model, database migration for that model, controller to manipulate it, views to view and manipulate the data, and a test suite for each of the above. Here's a...
The StringBuffer, StringBuilder, Formatter and StringJoiner classes are Java SE utility classes that are primarily used for assembling strings from other information: The StringBuffer class has been present since Java 1.0, and provides a variety of methods for building and modifying a "buf...
git config --global merge.conflictstyle diff3 Sets the diff3 style as default: instead of the usual format in conflicted sections, showing the two files: <<<<<<< HEAD left ======= right >>>>>>> master it will include an additional section containi...
parseFloat accepts a string as an argument which it converts to a float/ parseFloat("10.01") // = 10.01
// Generic types are declared using the <T> annotation struct GenericType<T> { pub item: T } enum QualityChecked<T> { Excellent(T), Good(T), // enum fields can be generics too Mediocre { product: T } }
// Only accept T and U generic types that also implement Debug fn print_objects<T: Debug, U: Debug>(a: T, b: U) { println!("A: {:?} B: {:?}", a, b); } print_objects(13, 44); // or annotated explicitly print_objects::<usize, u16>(13, 44); The bounds must cover a...

Page 136 of 826