Tutorial by Examples: au

Hash has a default value for keys that are requested but don't exist (nil): a = {} p a[ :b ] # => nil When creating a new Hash, one can specify the default: b = Hash.new 'puppy' p b[ :b ] # => 'puppy' Hash.new also takes a block, which allows you to automatically create n...
You can reference models in a seeder. use DB; use App\Models\User; class UserTableSeeder extends Illuminate\Database\Seeder{ public function run(){ # Remove all existing entrie DB::table('users')->delete() ; User::create([ 'name' => 'Admin', ...
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 Default keyword is used to execute an action when no other conditions match the input value. Example: switch('Condition') { 'Skip Condition' { 'First Action' } 'Skip This Condition Too' { 'Second Action' } Default { 'Default Action' } } Output: D...
The Objective-C runtime allows you to change the implementation of a method at runtime. This is called method swizzling and is often used to exchange the implementations of two methods. For example, if the methods foo and bar are exchanged, sending the message foo will now execute the implementation...
git shortlog summarizes git log and groups by author If no parameters are given, a list of all commits made per committer will be shown in chronological order. $ git shortlog Committer 1 (<number_of_commits>): Commit Message 1 Commit Message 2 ... Committer 2 (<number_of_...
Given the following history, imagine you make a change that you want to squash into the commit bbb2222 A second commit: $ git log --oneline --decorate ccc3333 (HEAD -> master) A third commit bbb2222 A second commit aaa1111 A first commit 9999999 Initial commit Once you've made your change...
The default value for an enum is zero. If an enum does not define an item with a value of zero, its default value will be zero. public class Program { enum EnumExample { one = 1, two = 2 } public void Main() { var e =...
def my_mix(name,valid=true, *opt) puts name puts valid puts opt end Call as follows: my_mix('me') # 'me' # true # [] my_mix('me', false) # 'me' # false # [] my_mix('me', true, 5, 7) # 'me' # true # [5,7]
The simple answer is that it allows you to evolve an existing interface without breaking existing implementations. For example, you have Swim interface that you published 20 years ago. public interface Swim { void backStroke(); } We did a great job, our interface is very popular, there ar...
function sayHello(name) print("Hello, " .. name .. "!") end That function is a simple function, and it works well. But what would happen if we just called sayHello()? stdin:2: attempt to concatenate local 'name' (a nil value) stack traceback: stdin:2: in function ...
To refresh the page every five seconds, add this meta element in the head element: <meta http-equiv="refresh" content="5"> CAUTION! While this is a valid command, it is recommended that you do not use it because of its negative effects on user experience. Refreshing the...
Create a .gitattributes file in the project root containing: * text=auto This will result in all text files (as identified by Git) being committed with LF, but checked out according to the host operating system default. This is equivalent to the recommended core.autocrlf defaults of: input o...
Django's default authentication works on username and password fields. Email authentication backend will authenticate users based on email and password. from django.contrib.auth import get_user_model class EmailBackend(object): """ Custom Email Backend to perform authent...
When implementing more than one interface that have methods of the same name that include default implementations, it is ambiguous to the compiler which implementation should be used. In the case of a conflict, the developer must override the conflicting method and provide a custom implementation. ...
Don't forget to import the necessary framework first. import SafariServices //Objective-C @import SafariServices; Instantiate a SafariViewController instance. let safariVC = SFSafariViewController(URL: URL(string: "your_url")!) //Objective-C @import SafariServices; NSURL *URL = [...
Imagine you have the following HTML: <div> <label>Name:</label> John Smith </div> And you need to locate the text "John Smith" after the label element. In this case, you can locate the label element by text and then use .next_sibling property: from ...
BeautifulSoup has a limited support for CSS selectors, but covers most commonly used ones. Use select() method to find multiple elements and select_one() to find a single element. Basic example: from bs4 import BeautifulSoup data = """ <ul> <li class="item&quo...
Swift let webview = UIWebView(frame: CGRect(x: 0, y: 0, width: 320, height: 480)) Objective-C UIWebView *webview = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)]; //Alternative way of defining frame for UIWebView UIWebView *webview = [[UIWebView alloc] init]; CGRect webviewFr...
Load content in webview from the url Swift webview.loadRequest(NSURLRequest(URL: NSURL(string: "http://www.google.com")!)) Objective-C [webview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.google.com"]]];

Page 5 of 37