Tutorial by Examples: conte

public class Person { //Id property can be read by other classes, but only set by the Person class public int Id {get; private set;} //Name property can be retrieved or assigned public string Name {get; set;} private DateTime dob; //Date of Birth property is st...
Maps provide methods which let you access the keys, values, or key-value pairs of the map as collections. You can iterate through these collections. Given the following map for example: Map<String, Integer> repMap = new HashMap<>(); repMap.put("Jon Skeet", 927_654); repMap.p...
The preferred method of file i/o is to use the with keyword. This will ensure the file handle is closed once the reading or writing has been completed. with open('myfile.txt') as in_file: content = in_file.read() print(content) or, to handle closing the file manually, you can forgo with...
with open(input_file, 'r') as in_file, open(output_file, 'w') as out_file: for line in in_file: out_file.write(line) Using the shutil module: import shutil shutil.copyfile(src, dst)
Sometimes it's necessary to set an array to zero, after the initialization has been done. #include <stdlib.h> /* for EXIT_SUCCESS */ #define ARRLEN (10) int main(void) { int array[ARRLEN]; /* Allocated but not initialised, as not defined static or global. */ size_t i; for(i ...
cat file.txt will print the contents of a file. If the file contains non-ASCII characters, you can display those characters symbolically with cat -v. This can be quite useful for situations where control characters would otherwise be invisible. cat -v unicode.txt Very often, for interactive ...
do './config.pl'; This will read in the contents of the config.pl file and execute it. (See also: perldoc -f do.) N.B.: Avoid do unless golfing or something as there is no error checking. For including library modules, use require or use.
const fs = require('fs'); // Read the contents of the directory /usr/local/bin asynchronously. // The callback will be invoked once the operation has either completed // or failed. fs.readdir('/usr/local/bin', (err, files) => { // On error, show it and return if(err) return console.er...
in myapp/context_processors.py: from django.conf import settings def debug(request): return {'DEBUG': settings.DEBUG} in settings.py: TEMPLATES = [ { ... 'OPTIONS': { 'context_processors': [ ... 'myapp.context_processor...
Swift //Align contents to the left of the frame button.contentHorizontalAlignment = .left //Align contents to the right of the frame button.contentHorizontalAlignment = .right //Align contents to the center of the frame button.contentHorizontalAlignment = .center //Make contents fill th...
Output buffering allows you to store any textual content (Text, HTML) in a variable and send to the browser as one piece at the end of your script. By default, php sends your content as it interprets it. <?php // Turn on output buffering ob_start(); // Print some output to the buffer (via...
ob_start(); $user_count = 0; foreach( $users as $user ) { if( $user['access'] != 7 ) { continue; } ?> <li class="users user-<?php echo $user['id']; ?>"> <a href="<?php echo $user['link']; ?>"> <?php echo $user...
<?php ob_start(); ?> <html> <head> <title>Example invoice</title> </head> <body> <h1>Invoice #0000</h1> <h2>Cost: £15,000</h2> ... </body> </html> <?php...
If you want to use a pipe character (|) in the content of a cell you'll need to escape it with a backslash. Column | Column ------ | ------ \| Cell \|| \| Cell \| This results in the following table: ColumnColumn| Cell || Cell |
main = do input <- getContents putStr input Input: This is an example sentence. And this one is, too! Output: This is an example sentence. And this one is, too! Note: This program will actually print parts of the output before all of the input has been fully read in. This m...
A context manager is an object that is notified when a context (a block of code) starts and ends. You commonly use one with the with statement. It takes care of the notifying. For example, file objects are context managers. When a context ends, the file object is closed automatically: open_file = ...
A context manager is any object that implements two magic methods __enter__() and __exit__() (although it can implement other methods as well): class AContextManager(): def __enter__(self): print("Entered") # optionally return an object return "A-ins...
If you wish to copy the contents of a slice into an initially empty slice, following steps can be taken to accomplish it- Create the source slice: var sourceSlice []interface{} = []interface{}{"Hello",5.10,"World",true} Create the destination slice, with: Length =...
Sometimes, your template need a bit more of information. For example, we would like to have the user in the header of the page, with a link to their profile next to the logout link. In these cases, use the get_context_data method. views.py class BookView(DetailView): template_name = "boo...
Assuming you have a model called Post defined in your models.py file that contains blog posts, and has a date_published field. Step 1: Write the context processor Create (or add to) a file in your app directory called context_processors.py: from myapp.models import Post def recent_blog_posts...

Page 1 of 9