Tutorial by Examples: c

A simple context tree (containing some common values that might be request scoped and included in a context) built from Go code like the following: // Pseudo-Go ctx := context.WithValue( context.WithDeadline( context.WithValue(context.Background(), sidKey, sid), time.Now().A...
A database is created with the following SQL command: CREATE DATABASE myDatabase; This would create an empty database named myDatabase where you can create tables.
Matplotlib supports both object-oriented and imperative syntax for plotting. The imperative syntax is intentionally designed to be very close to Matlab syntax. The imperative syntax (sometimes called 'state-machine' syntax) issues a string of commands all of which act on the most recent figure or a...
First, ensure you have imported sessions from flask from flask import session To use session, a Flask application needs a defined SECRET_KEY. app = Flask(__name__) app.secret_key = 'app secret key' Sessions are implemented by default using a cookie signed with the secret key. This ensures t...
props are used to pass data and methods from a parent component to a child component. Interesting things about props They are immutable. They allow us to create reusable components. Basic example class Parent extends React.Component{ doSomething(){ console.log("Parent comp...
When a React component is created, a number of functions are called: If you are using React.createClass (ES5), 5 user defined functions are called If you are using class Component extends React.Component (ES6), 3 user defined functions are called getDefaultProps() (ES5 only) This is the firs...
componentWillReceiveProps(nextProps) This is the first function called on properties changes. When component's properties change, React will call this function with the new properties. You can access to the old props with this.props and to the new props with nextProps. With these variables, you c...
componentWillUnmount() This method is called before a component is unmounted from the DOM. It is a good place to perform cleaning operations like: Removing event listeners. Clearing timers. Stopping sockets. Cleaning up redux states. componentWillUnmount(){ ... } An example of remo...
With automatic reference counting (ARC), the compiler inserts retain, release, and autorelease statements where they are needed, so you don't have to write them yourself. It also writes dealloc methods for you. The sample program from Manual Memory Management looks like this with ARC: @interface M...
Modern A weak reference looks like one of these: @property (weak) NSString *property; NSString *__weak variable; If you have a weak reference to an object, then under the hood: You're not retaining it. When it gets deallocated, every reference to it will automatically be set to nil Obje...
A word of caution: AsyncTask has many gotcha's apart from the memory leak described here. So be careful with this API, or avoid it altogether if you don't fully understand the implications. There are many alternatives (Thread, EventBus, RxAndroid, etc). One common mistake with AsyncTask is to c...
The isEqual: method is the only reliable way to determine whether two images contain the same image data. The image objects you create may be different from each other, even when you initialize them with the same cached image data. The only way to determine their equality is to use the isEqual...
Send an HTTP response with status code 200 to indicate a successful request. The HTTP response status line is then: HTTP/1.1 200 OK The status text OK is only informative. The response body (message payload) should contain a representation of the requested resource. If there is no representation...
NOTE: In most cases, it is better to use a UIButton instead of making a UILabel you can tap on. Only use this example, if you are sure, that you don't want to use a UIButton for some reason. Create label Enable user interaction Add UITapGestureRecognizer The key to create a clickable UIL...
Leaflet is an open-source JavaScript library for making dynamic maps for the web. RStudio wrote R bindings for Leaflet, available through its leaflet package, built with htmlwidgets. Leaflet maps integrate well with the RMarkdown and Shiny ecosystems. The interface is piped, using a leaflet() funct...
Switch statements use non-strict comparison to determine matches. This can lead to some nasty surprises. For example, consider the following statement: switch ($name) { case 'input 1': $mode = 'output_1'; break; case 'input 2': $mode = 'output_2'; bre...
Load an image, decode it into a bitmap, and display the bitmap in an ImageView (or any other view which implements the ImageAware interface): ImageLoader.getInstance().displayImage(imageUri, imageView); Load an image, decode it into a bitmap, and return the bitmap to a callback: ImageLo...
To change MySQL's root user password: Step 1: Stop the MySQL server. in Ubuntu or Debian: sudo /etc/init.d/mysql stop in CentOS, Fedora or Red Hat Enterprise Linux: sudo /etc/init.d/mysqld stop Step 2: Start the MySQL server without the privilege system. sudo mysqld_safe --skip-grant-tab...
strsplit is a useful function for breaking up a vector into an list on some character pattern. With typical R tools, the whole list can be reincorporated to a data.frame or part of the list might be used in a graphing exercise. Here is a common usage of strsplit: break a character vector along a co...
Haskell has list comprehensions, which are a lot like set comprehensions in math and similar implementations in imperative languages such as Python and JavaScript. At their most basic, list comprehensions take the following form. [ x | x <- someList ] For example [ x | x <- [1..4] ] -...

Page 215 of 826