Tutorial by Examples: c

Another use case for filters is to format a single value. In this example, we pass in a value and we are returned an appropriate true boolean value. function convertToBooleanValue() { return function(input) { if (typeof input !== 'undefined' && input !== null ...
:root { --red: #b00; --blue: #4679bd; --grey: #ddd; } .Bx1 { color: var(--red); background: var(--grey); border: 1px solid var(--red); }
Trailing spaces \s*$: This will match any (*) whitespace (\s) at the end ($) of the text Leading spaces ^\s*: This will match any (*) whitespace (\s) at the beginning (^) of the text Remarks \s is a common metacharacter for several RegExp engines, and is meant to capture whitespace characters (...
Raw direct IO file_get_contents and file_put_contents provide the ability to read/write from/to a file to/from a PHP string in a single call. file_put_contents can also be used with the FILE_APPEND bitmask flag to append to, instead of truncate and overwrite, the file. It can be used along with LO...
child.py import time def main(): print "starting work" time.sleep(1) print "work work work work work" time.sleep(1) print "done working" if __name__ == '__main__': main() parent.py import os def main(): for i in range(5):...
Suppose we have a list of teams, named like this: Team A, Team B, ..., Team Z. Then: Team [AB]: This will match either either Team A or Team B Team [^AB]: This will match any team except Team A or Team B We often need to match characters that "belong" together in some context or ano...
This example starts Notepad, waits for it to be closed, then gets its exit code. #include <Windows.h> int main() { STARTUPINFOW si = { 0 }; si.cb = sizeof(si); PROCESS_INFORMATION pi = { 0 }; // Create the child process BOOL success = CreateProcessW( L"C:...
Pass dynamic inventory to ansible-playbook: ansible-playbook -i inventory/dyn.py -l targethost my_playbook.yml python inventory/dyn.py should print out something like this: { "_meta": { "hostvars": { "10.1.0.10": { "ansible_user": ...
Available in Django 1.9+ from django.contrib.postgres.fields import JSONField from django.db import models class IceCream(models.Model): metadata = JSONField() You can add the normal **options if you wish. ! Note that you must put 'django.contrib.postgres' in INSTALLED_APPS in your s...
Pass data in native Python form, for example list, dict, str, None, bool, etc. IceCream.objects.create(metadata={ 'date': '1/1/2016', 'ordered by': 'Jon Skeet', 'buyer': { 'favorite flavor': 'vanilla', 'known for': ['his rep on SO', 'writing a book'] }, ...
Get all ice cream cones that were ordered by people liking chocolate: IceCream.objects.filter(metadata__buyer__favorite_flavor='chocolate') See the note in the "Remarks" section about chaining queries.
Python 3.x3.0 Python 3 added a new keyword called nonlocal. The nonlocal keyword adds a scope override to the inner scope. You can read all about it in PEP 3104. This is best illustrated with a couple of code examples. One of the most common examples is to create function that can increment: def c...
To iterate all files, including in sub directories, use os.walk: import os for root, folders, files in os.walk(root_dir): for filename in files: print root, filename root_dir can be "." to start from current directory, or any other path to start from. Python 3.x3.5 If ...
vimtutor is an interactive tutorial covering the most basic aspects of text editing. On UNIX-like system, you can start the tutorial with: $ vimtutor On Windows, “Vim tutor” can be found in the “Vim 7.x” directory under “All Programs” in the Windows menu. See :help vimtutor for further details...
You can create a TCP server using the socketserver library. Here's a simple echo server. Server side from sockerserver import BaseRequestHandler, TCPServer class EchoHandler(BaseRequestHandler): def handle(self): print('connection from:', self.client_address) while True:...
A UDP server is easily created using the socketserver library. a simple time server: import time from socketserver import BaseRequestHandler, UDPServer class CtimeHandler(BaseRequestHandler): def handle(self): print('connection from: ', self.client_address) # Get message and cli...
The vast majority of Python memory management is handled with reference counting. Every time an object is referenced (e.g. assigned to a variable), its reference count is automatically increased. When it is dereferenced (e.g. variable goes out of scope), its reference count is automatically decreas...
The only time the garbage collector is needed is if you have a reference cycle. The simples example of a reference cycle is one in which A refers to B and B refers to A, while nothing else refers to either A or B. Neither A or B are accessible from anywhere in the program, so they can safely be dest...
Removing a variable name from the scope using del v, or removing an object from a collection using del v[item] or del[i:j], or removing an attribute using del v.name, or any other way of removing references to an object, does not trigger any destructor calls or any memory being freed in and of itsel...
use std::io::{Read, Result as IoResult}; use std::fs::File; struct Config(u8); fn read_config() -> IoResult<String> { let mut s = String::new(); let mut file = File::open(&get_local_config_path()) // or_else closure is invoked if Result is Err. .or_els...

Page 133 of 826