Tutorial by Examples: clos

Manually open and close a file. # Using new method f = File.new("test.txt", "r") # reading f = File.new("test.txt", "w") # writing f = File.new("test.txt", "a") # appending # Using open method f = open("test.txt", "r&...
def noParam = { "I have $it" } def noParamCurry = noParam.curry(2) assert noParamCurry() == 'I have 2'
def honestlyNoParam = { -> "I Don't have it" } // The following all throw IllegalArgumentException honestlyNoParam.curry('whatever') honestlyNoParam.rcurry('whatever') honestlyNoParam.ncurry(0, 'whatever')
this topic is a classical issue in iOS development, and its solution is various as other example already shown. In this example I'll show another daily common use one: passing data using closure by adapting delegate pattern example on this page into callback closure! one thing this method is superi...
Normal mode Ctrl-wo Ex mode :only or short :on
If you like to show the dialog without the close button (i.e. the x button in the upper-right corner of the dialog), perhaps because you want to force the user to select one of options or buttons in the dialog itself: 1- Give your dialog a CSS class: $("#selector").dialog({ closeOnE...
The QueryClose event is raised whenever a form is about to be closed, whether it's via user action or programmatically. The CloseMode parameter contains a VbQueryClose enum value that indicates how the form was closed: ConstantDescriptionValuevbFormControlMenuForm is closing in response to user act...
Given the 4 points of a cubic Bezier curve the following function returns its length. Method: The length of a cubic Bezier curve does not have a direct mathematical calculation. This "brute force" method finds a sampling of points along the curve and calculates the total distance spanne...
core.async is about making processes that take values from and put values into channels. (require [clojure.core.async :as a]) Creating channels with chan You create a channel using the chan function: (def chan-0 (a/chan)) ;; unbuffered channel: acts as a rendez-vous point. (def chan-1 (a/chan...
The evaluation of a closure is the evaluation of the result of the closure. All rules applies : if the closure returns a null , zero number or empty String, Collection, Map or Array it evaluates to false otherwise to true. // Closure return non zero number => true assert { 42 }() // closure ...
There are frequent behavior patterns that can result in a lot of boilerplate code. By declaring a method that takes a Closure as a parameter, you can simplify your program. As an example, it is a common pattern to retrieve a database connection, start a transaction, do work, and then either commit ...
You can close a notification by using the .close() method. let notification = new Notification(title, options); // do some work, then close the notification notification.close() You can utilize the setTimeout function to auto-close the notification sometime in the future. let notification = n...
An event stream to the server can be closed using the EventSource.close() method var eventSource = new EventSource("api/my-events"); // do things ... eventSource.close(); // you will not receive anymore events from this object The .close() method does nothing is the stream is already...
To prevent memory leaks, one should not forget to close an input stream or an output stream whose job is done. This is usually done with a try-catch-finally statement without the catch part: void writeNullBytesToAFile(int count, String filename) throws IOException { FileOutputStream out = null...
The simplest shortcode is the self-closing one. We’re going to create a simple link to our Twitter account, and then add it in a blog post. All the code goes in functions.php, which is located in /wp-content/themes/your-theme/. If you don’t have one, just create it and put the code in it. <?php...
Creating a self-closing shortcode with parameters <?php function button_shortcode( $type ) { extract( shortcode_atts( array( 'type' => 'value' ), $type ) ); // check what type user entered switch ($type) { case 'twitter': ...
enclosing shortcode The enclosing shortcode allows you to embed content within your shortcode, just like BBCode if you’ve ever used that. <?php function button_shortcode( $attr, $content = null ) { return '<a href="http://twitter.com/filipstefansson" class="twitter-button&qu...
jQuery('body').bind('click', function(e) { if(jQuery(e.target).closest('#navbar').length == 0) { // click happened outside of .navbar, so hide var opened = jQuery('.navbar-collapse').hasClass('collapse in'); if ( opened === true ) { jQuery('#navbar2 .navb...
Since Groovy 1.8 a convenient memoize() method is added on closures: // normal closure def sum = { int x, int y -> println "sum ${x} + ${y}" return x + y } sum(3, 4) sum(3, 4) // prints // sum 3 + 4 // sum 3 + 4 // memoized closure def sumMemoize = sum.memoize() ...
The pyplot interface to matplotlib might be the simplest way to close a figure. import matplotlib.pyplot as plt plt.plot([0, 1], [0, 1]) plt.close()

Page 3 of 5