Tutorial by Examples: code

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):...
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:...
Python is a hybrid interpreter. When running a program, it first assembles it into bytecode which can then be run in the Python interpreter (also called a Python virtual machine). The dis module in the standard library can be used to make the Python bytecode human-readable by disassembling classes, ...
When adding indented code blocks inside a list you first need a blank line, then to indent the code further. Different flavours of Markdown have different rules for this. StackExchange requires code to be indented by 8 characters instead of the usual 4. (Spaces replaced with * for clarity): 1...
Python 2.x2.7 "1deadbeef3".decode('hex') # Out: '\x1d\xea\xdb\xee\xf3' '\x1d\xea\xdb\xee\xf3'.encode('hex') # Out: 1deadbeef3 Python 3.x3.0 "1deadbeef3".decode('hex') # Traceback (most recent call last): # File "<stdin>", line 1, in <module> ...
If a sentence contains computer code (for example, the name of an HTML element), use the code element to mark it up: <p>The <code>a</code> element creates a hyperlink.</p>
If the formatting (white space, new lines, indentation) of the code matters, use the pre element in combination with the code element: <pre> <code> x = 42 if x == 42: print "x is … … 42" </code> </pre> You still have to esc...
Mage::app()->getStore()->getCode(); This returns store code, e.g. 'en' for a storefront that is setup for English and called 'en', and not the numerical id.
chrome.runtime.getManifest() returns the extension's manifest in a form of a parsed object. This method works both on content scripts and all extension pages, it requires no permissions, Example, obtaining the extension's version string: var version = chrome.runtime.getManifest().version;
You can easily add a breakpoint to your code by clicking on the grey column to the left of the line of your VBA code where you want execution to stop. A red dot appears in the column and the breakpoint code is also highlighted in red. You can add multiple breakpoints throughout your code and resumi...
using System.Net; ... string serverResponse; try { // Call a method that performs an HTTP request (per the above examples). serverResponse = PerformHttpRequest(); } catch (WebException ex) { if (ex.Status == WebExceptionStatus.ProtocolError) { HttpWebResponse...
Layout Unity basic editor will look like below. Basic functionalities of some default windows/tabs are described in the image. Linux Layout There is a little difference in menu layout of linux version, like the screenshot below, Basic Usage Create an empty GameObject by right clicking in th...
Consider this simple class: class SmsUtil { public bool SendMessage(string from, string to, string message, int retryCount, object attachment) { // Some code } } Before C# 3.0 it was: var result = SmsUtil.SendMessage("Mehran", "Maryam", "Hello...
If you ever wanted to determine the html content to be printed on a page during run time then, rails has a very good solution for that. It has something called the content_for which allows us to pass a block to a rails view. Please check the below example, Declare content_for <div> <%=...
By default, ui-router encodes the slash / inside parameters. If you want to send a path in the URL, you need to define a custom parameter type. Define: module.config(['$urlMatcherFactoryProvider', function($urlMatcherFactory) { $urlMatcherFactory.type('path', { decode: function(val) { retu...
You can diff UTF-16 encoded files (localization strings file os iOS and macOS are examples) by specifying how git should diff these files. Add the following to your ~/.gitconfig file. [diff "utf16"] textconv = "iconv -f utf-16 -t utf-8" iconv is a program to convert differe...
Differences in subsetting syntax A data.table is one of several two-dimensional data structures available in R, besides data.frame, matrix and (2D) array. All of these classes use a very similar but not identical syntax for subsetting, the A[rows, cols] schema. Consider the following data stored i...
It is not possible to use eval or exec to execute code from untrusted user securely. Even ast.literal_eval is prone to crashes in the parser. It is sometimes possible to guard against malicious code execution, but it doesn't exclude the possibility of outright crashes in the parser or the tokenizer....
The case modifier causes the Scala compiler to automatically generate common boilerplate code for the class. Implementing this code manually is tedious and a source of errors. The following case class definition: case class Person(name: String, age: Int) ... will have the following code automati...
If you want to see the generated bytecode for a Java program, you can use the provided javap command to view it. Assuming that we have the following Java source file: package com.stackoverflow.documentation; import org.springframework.stereotype.Service; import java.io.IOException; import j...

Page 3 of 21