Tutorial by Examples

2.3 The Percent Support Library provides PercentFrameLayout and PercentRelativeLayout, two ViewGroups that provide an easy way to specify View dimensions and margins in terms of a percentage of the overall size. You can use the Percent Support Library by adding the following to your dependencies. ...
When working with dictionaries, it's often necessary to access all the keys and values in the dictionary, either in a for loop, a list comprehension, or just as a plain list. Given a dictionary like: mydict = { 'a': '1', 'b': '2' } You can get a list of keys using the keys() method: ...
HTML comments can be used to leave notes to yourself or other developers about a specific point in code. They can be initiated with <!-- and concluded with -->, like so: <!-- I'm an HTML comment! --> They can be incorporated inline within other content: <h1>This part will be d...
Conditional comments can be used to customize code for different versions of Microsoft Internet Explorer. For example, different HTML classes, script tags, or stylesheets can be provided. Conditional comments are supported in Internet Explorer versions 5 through 9. Older and newer Internet Explorer ...
When you make a subclass of a base class, you can construct the base class by using : base after the subclass constructor's parameters. class Instrument { string type; bool clean; public Instrument (string type, bool clean) { this.type = type; this.clean = c...
Basic implementation: <script src= "http://player.twitch.tv/js/embed/v1.js"></script> <div id="PLAYER_DIV_ID"></div> <script type="text/javascript"> var options = { width: 854, height: 480, channel: "...
List Assignment If you are familiar with Perl, C, or Java, you might think that Bash would use commas to separate array elements, however this is not the case; instead, Bash uses spaces: # Array in Perl my @array = (1, 2, 3, 4); # Array in Bash array=(1 2 3 4) Create an array with new ...
Print element at index 0 echo "${array[0]}" 4.3 Print last element using substring expansion syntax echo "${arr[@]: -1 }" 4.3 Print last element using subscript syntax echo "${array[-1]}" Print all elements, each quoted separately echo "${array[@...
In helloWorld.sh #!/bin/bash # Define a function greet greet () { echo "Hello World!" } # Call the function greet greet In running the script, we see our message $ bash helloWorld.sh Hello World! Note that sourcing a file with functions makes them available in your ...
$.ajax({ url: 'https://api.dropboxapi.com/2/sharing/add_folder_member', type: 'POST', processData: false, data: JSON.stringify({"shared_folder_id": "84528192421","members": [{"member": {".tag": "email","email":...
// This creates an array with 5 values. const int array[] = { 1, 2, 3, 4, 5 }; #ifdef BEFORE_CPP11 // You can use `sizeof` to determine how many elements are in an array. const int* first = array; const int* afterLast = first + sizeof(array) / sizeof(array[0]); // Then you can iterate ov...
def call_the_block(&calling); calling.call; end its_a = proc do |*args| puts "It's a..." unless args.empty? "beautiful day" end puts its_a #=> "beautiful day" puts its_a.call #=> "beautiful day" puts its_a[1, 2] #=> "It'...
# lambda using the arrow syntax hello_world = -> { 'Hello World!' } hello_world[] # 'Hello World!' # lambda using the arrow syntax accepting 1 argument hello_world = ->(name) { "Hello #{name}!" } hello_world['Sven'] # "Hello Sven!" the_thing = lambda do |magic, ...
2.0 Guard checks for a condition, and if it is false, it enters the branch. Guard check branches must leave its enclosing block either via return, break, or continue (if applicable); failing to do so results in a compiler error. This has the advantage that when a guard is written it's not possible ...
An if statement checks whether a Bool condition is true: let num = 10 if num == 10 { // Code inside this block only executes if the condition was true. print("num is 10") } let condition = num == 10 // condition's type is Bool if condition { print("num is 10&...
Optionals must be unwrapped before they can be used in most expressions. if let is an optional binding, which succeeds if the optional value was not nil: let num: Int? = 10 // or: let num: Int? = nil if let unwrappedNum = num { // num has type Int?; unwrappedNum has type Int print(&quo...
To allow the use of in for custom classes the class must either provide the magic method __contains__ or, failing that, an __iter__-method. Suppose you have a class containing a list of lists: class ListList: def __init__(self, value): self.value = value # Create a set of al...
var favoriteColors: Set = ["Red", "Blue", "Green"] //favoriteColors = {"Blue", "Green", "Red"} You can use the insert(_:) method to add a new item into a set. favoriteColors.insert("Orange") //favoriteColors = {"Red&q...
from collections import Counter c = Counter(["a", "b", "c", "d", "a", "b", "a", "c", "d"]) c # Out: Counter({'a': 3, 'b': 2, 'c': 2, 'd': 2}) c["a"] # Out: 3 c[7] # not in the list (7 oc...
Counting the keys of a Mapping isn't possible with collections.Counter but we can count the values: from collections import Counter adict = {'a': 5, 'b': 3, 'c': 5, 'd': 2, 'e':2, 'q': 5} Counter(adict.values()) # Out: Counter({2: 2, 3: 1, 5: 3}) The most common elements are avaiable by the m...

Page 57 of 1336