Tutorial by Examples

There isn't much to add to Nokogiri's "Parsing an HTML/XML Document" tutorial, which is an easy introduction to the subject, so start there, then return to this page to help fill in some gaps. Nokogiri's basic parsing attempts to clean up a malformed document, sometimes adding missing clo...
Nokogiri is somewhat like a browser, in that it will attempt to provide something useful even if the incoming HTML or XML is malformed. Unfortunately it usually does it silently, but we can ask for a list of the errors using errors: require 'nokogiri' doc = Nokogiri::XML('<node><foo/&gt...
How to correctly extract text from nodes is one of the most popular questions we see, and almost invariably is made more difficult by misusing Nokogiri's "searching" methods. Nokogiri supports using CSS and XPath selectors. These are equivalent: doc.at('p').text # => "foo"...
To read an array from the device back to the host, one calls clEnqueueReadBuffer($queue, $memobj, $blocking, $offset, $size, $target, 0, null, null); The $queue is the CommandQueue which was used to allocate the memory on the device. The $memobj contains the address to the device memory, $offset...
Reading an image is almost like reading an array. The only difference beeing that the size and offset need to be three-dimensional. clEnqueueReadImage($queue, $memobj, $blocking, $offset, $size, $stride, $slice_pitch, $target, 0, null, null); The $stride defines how many bytes a row has. Normall...
To copy a texture to the device there are two steps necessary Allocate the memory on the device Copy the image to the device _mem = clCreateImage2D($context, $mem_flags, $image_format, $width, $height, $stride, $source, &err); The $mem_flags define how the memory is allocated. It can...
When allocating Memory you have the option to choose between different modes: Read only memory Write only memory Read/Write memory Read-only memory is allocated in the __constant memory region, while the other two are allocated in the normal __global region. In addition to the accessibility...
Writing an array consists of two steps: Allocating the memory Copying the data To allocate the memory, a simple call to _mem = clCreateBuffer($queue, $mem_flags, $size, $host_ptr, &err); is enough. If you decided to copy the host pointer via the mem_flags, you are done. Otherwise you ...
Lets build a kernel to generate a grayscale image. We will use image data which is defined using uints for each component and with order RGBA. __constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | C...
Lets walk through the most simple kernel there is and some variations of it __kernel void myKernel() { } A kernel which can be started from your main code is identified by the __kernel keyword. A Kernel function can only have return type void. __kernel void myKernel(float a, uint b, byte c) { ...
To properly work with the data each thread needs to know its position in the threadblock/global thread pool. This can be archieved with get_local_id($dim); get_global_id($dim); Those two functions return the position of the thread relative to the threadblock or all threads. get_working_dim(); ...
Each fundamental opencl type has a vector version. You can use the vector type by appending the number of desired components after the type. Supported number of components are 2,3,4,8 and 16. OpenCL 1.0 does not offer three components. You can initialize any vector using two ways: Provide a sing...
Lets look at a gamma correction kernel __constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_LINEAR; __kernel void Gamma(__read_only image2d_t input, __write_only image2d_t output, __c...
Recent versions of Delphi ships with the TStopwatch record which is for time interval measurement. Example usage: uses System.Diagnostics; var StopWatch: TStopwatch; ElapsedMillseconds: Int64; begin StopWatch := TStopwatch.StartNew; // do something that requires measurement El...
trait Show[T] { def show(t: T): String } object Show extends ProductTypeClassCompanion[Show] { def apply[T](implicit T: Show[T]) = T def from[T](f: T => String): Show[T] = new Show[T] { def show(t: T): String = f(t) } implicit val string = from[String](_.reverse) ...
Dart allows to easily filter a list using where. var fruits = ['apples', 'oranges', 'bananas']; fruits.where((f) => f.startsWith('a')).toList(); //apples Of course you can use some AND or OR operators in your where clause.
DRF offers the chance to further customize the behavior of the generic views/viewsets by allowing the creation of custom mixins. How to: To define a custom mixin we just need to create a class inheriting from object. Let's assume that we want to define two separate views for a model named MyM...
To make your APK file as small as possible, you should enable shrinking to remove unused code and resources in your release build. This page describes how to do that and how to specify what code and resources to keep or discard during the build. Code shrinking is available with ProGuard, which dete...
An inner class which is visible to any outside class can be created from this class as well. The inner class depends on the outside class and requires a reference to an instance of it. To create an instance of the inner class, the new operator only needs to be called on an instance of the outer cla...

Page 1275 of 1336