Tutorial by Examples: n

io-streams is Stream-based library that focuses on the Stream abstraction but for IO. It exposes two types: InputStream: a read-only smart handle OutputStream: a write-only smart handle We can create a stream with makeInputStream :: IO (Maybe a) -> IO (InputStream a). Reading from ...
Let's create an Enumerator for Fibonacci numbers. fibonacci = Enumerator.new do |yielder| a = b = 1 loop do yielder << a a, b = b, a + b end end We can now use any Enumerable method with fibonacci: fibonacci.take 10 # => [1, 1, 2, 3, 5, 8, 13, 21, 34, 55]
If an iteration method such as each is called without a block, an Enumerator should be returned. This can be done using the enum_for method: def each return enum_for :each unless block_given? yield :x yield :y yield :z end This enables the programmer to compose Enumerable operati...
Use rewind to restart the enumerator. ℕ = Enumerator.new do |yielder| x = 0 loop do yielder << x x += 1 end end ℕ.next # => 0 ℕ.next # => 1 ℕ.next # => 2 ℕ.rewind ℕ.next # => 0
There are two approaches for influencing when a memory cleanup is performed. They are influencing how often the automatic process is performed and the other is manually triggering a cleanup. The garbage collector can be manipulated by tuning the collection thresholds which affect the frequency at w...
To manipulate colors we will modify the argb (Alpha, Red, Green and Blue) values of a color. First extract RGB values from your color. int yourColor = Color.parse("#ae1f67"); int red = Color.red(yourColor); int green = Color.green(yourColor); int blue = Color.blue(yourColor); Now...
If you want to clear your current Activity stack and launch a new Activity (for example, logging out of the app and launching a log in Activity), there appears to be two approaches. 1. Target (API >= 16) Calling finishAffinity() from an Activity 2. Target (11 <= API < 16) Intent intent ...
Get the current date and time. public class Program { static void Main() { // create empty pipeline PowerShell ps = PowerShell.Create(); // add command ps.AddCommand("Get-Date"); // run command(s) Console.WriteLine(&quot...
HTML email is the use of a subset of HTML and CSS to format an email message like a web page using colors, graphics, table columns and links. When you send an email it’s important to send both plain text and HTML. You do this by sending your email as multi-part MIME. Most email service providers ha...
(Caveat emptor: there are many, many programmers who go into absolute conniptions if they meet code that uses recordsets instead of commands and stored procedures.) <% dim rs, sql dim SelectedUser SelectedUser = request.form("user") if IsNumeric(SelectedUser) then SelectedUser...
Using UISettings, the appearance of the Google Map can be modified. Here is an example of some common settings: mGoogleMap.setMapType(GoogleMap.MAP_TYPE_HYBRID); mGoogleMap.getUiSettings().setMapToolbarEnabled(true); mGoogleMap.getUiSettings().setZoomControlsEnabled(true); mGoog...
The syntax for using the aws cli is as follows: aws [options] <command> <subcommand> [parameters] Some examples using the 'ec2' command and the 'describe-instances' subcommand: aws ec2 describe-instances aws ec2 describe-instances --instance-ids <your-id> Example with a ...
You can do a permissions check when sending an Intent to a registered broadcast receiver. The permissions you send are cross-checked with the ones registered under the tag. They restrict who can send broadcasts to the associated receiver. To send a broadcast request with permissions, specify the p...
A function declared inline may be defined in multiple translation units, provided that all definitions are identical. It also must be defined in every translation unit in which it is used. Therefore, inline functions should be defined in headers and there is no need to mention them in the implementa...
Once you understand how to create an HTTP Server with node, it's important to understand how to make it "do" things based on the path that a user has navigated to. This phenomenon is called, "routing". The most basic example of this would be to check if (request.url === 'some/pa...
C++11 Note: in all the following, the existence of the C++11 constant nullptr is assumed. For earlier versions, replace nullptr with NULL, the constant that used to play a similar role. Creating a pointer variable A pointer variable can be created using the specific * syntax, e.g. int *pointer_...
$ mkdir backup_download_directory && cd !#:1 mkdir backup_download_directory && cd backup_download_directory This will substitute the Nth argument of the current command. In the example !#:1 is replaced with the first argument, i.e. backup_download_directory.
$ mplayer Lecture_video_part1.mkv $ ^1^2^ mplayer Lecture_video_part2.mkv This command will replace 1 with 2 in the previously executed command. It will only replace the first occurrence of the string and is equivalent to !!:s/1/2/. If you want to replace all occurrences, you have to use !!:gs...
$ apt-get install r-base E: Could not open lock file /var/lib/dpkg/lock - open (13: Permission denied) E: Unable to lock the administration directory (/var/lib/dpkg/), are you root? $ sudo !! sudo apt-get install r-base [sudo] password for <user>:
This is a TCP daytime client kept as simple as possible. #include <unistd.h> /* unix standard library */ #include <arpa/inet.h> /* IP addresses manipulation utilities */ #include <netinet/in.h> /* sockaddr_in structure definition */ #include <sys/socket.h> /* ber...

Page 556 of 1088