You can send a block to your method and it can call that block multiple times. This can be done by sending a proc/lambda or such, but is easier and faster with yield:
def simple(arg1,arg2)
puts "First we are here: #{arg1}"
yield
puts "Finally we are here: #{arg2}"
...
See this Q&A question if you don't know what race conditions are.
The following code may be subject to race conditions :
article = Article.objects.get(pk=69)
article.views_count += 1
article.save()
If views_count is equal to 1337, this will result in such query:
UPDATE app_article SET vi...
Orders Table
CustomerIdProductIdQuantityPrice12510013220014150021450356700
To check for customers who have ordered both - ProductID 2 and 3, HAVING can be used
select customerId
from orders
where productID in (2,3)
group by customerId
having count(distinct productID) = 2
Return value:...
package main
import (
"fmt"
"io/ioutil"
)
func main() {
files, err := ioutil.ReadDir(".")
if err != nil {
panic(err)
}
fmt.Println("Folders in the current directory:")
for _, fileInfo := range files {
...
The most feasible way is to use, the DateTime class.
An example:
<?php
// Create a date time object, which has the value of ~ two years ago
$twoYearsAgo = new DateTime("2014-01-18 20:05:56");
// Create a date time object, which has the value of ~ now
$now = new DateTime("2016...
Usually data sent in a POST request is structured key/value pairs with a MIME type of application/x-www-form-urlencoded. However many applications such as web services require raw data, often in XML or JSON format, to be sent instead. This data can be read using one of two methods.
php://input is a...
This illustrates that union members shares memory and that struct members does not share memory.
#include <stdio.h>
#include <string.h>
union My_Union
{
int variable_1;
int variable_2;
};
struct My_Struct
{
int variable_1;
int variable_2;
};
int main (void)
{
...
Invoking a function as a method of an object the value of this will be that object.
var obj = {
name: "Foo",
print: function () {
console.log(this.name)
}
}
We can now invoke print as a method of obj. this will be obj
obj.print();
This will thus log:
Foo...
The apply and call methods in every function allow it to provide a custom value for this.
function print() {
console.log(this.toPrint);
}
print.apply({ toPrint: "Foo" }); // >> "Foo"
print.call({ toPrint: "Foo" }); // >> "Foo"
You mig...
The bind method of every function allows you to create new version of that function with the context strictly bound to a specific object. It is specially useful to force a function to be called as a method of an object.
var obj = { foo: 'bar' };
function foo() {
return this.foo;
}
fooOb...
Let's extend our template from above and include content from header.php and footer.php
Including header:
We will include header right after Template name comment
There are two common ways to do this. Both are right and work same, it's just about your style and how code looks
First way:
<?ph...
Values can be given names using let:
# let a = 1;;
val a : int = 1
You can use similar syntax to define a function. Just provide additional parameters for the arguments.
# let add arg1 arg2 = arg1 + arg2;;
val add : int -> int -> int = <fun>
We can call it like this:
# add 1...
[1, 2, [[3, 4], [5]], 6].flatten # => [1, 2, 3, 4, 5, 6]
If you have a multi-dimensional array and you need to make it a simple (i.e. one-dimensional) array, you can use the #flatten method.
If targeting Flash Player 11+, the built-in removeChildren method is the best way to remove all children:
removeChildren(); //a start and end index can be passed
For legacy applications, the same can be accomplished with a loop:
while (numChildren > 0) {
removeChildAt(0);
}
We prepare a file called reverser.ml with the following contents:
let acc = ref [] in
try
while true do
acc := read_line () :: !acc;
done
with
End_of_file -> print_string (String.concat "\n" !acc)
We then compile our program using ...
There are several additional attributes that the Volley NetworkImageView adds to the standard ImageView. However, these attributes can only be set in code. The following is an example of how to make an extension class that will pick up the attributes from your XML layout file and apply them to the N...
A simple example on how to read a UTF text file synchronously.
import flash.filesystem.File;
import flash.filesystem.FileMode;
import flash.filesystem.FileStream;
//First, get a reference to the file you want to load
var myFile:File = File.documentsDirectory.resolvePath("lifestory.txt&...
Nine-patch images allow optional definition of the padding lines in the image. The padding lines are the lines on the right and at the bottom.
If a View sets the 9-patch image as its background, the padding lines are used to define the space for the View's content (e.g. the text input in an EditTex...
Early bound (requires a reference to Microsoft Scripting Runtime):
Public Sub EnumerateDirectory()
Dim fso As Scripting.FileSystemObject
Set fso = New Scripting.FileSystemObject
Dim targetFolder As Folder
Set targetFolder = fso.GetFolder("C:\")
Dim foundFi...
A helper function to create a bitmap copy of an object. This can be used to convert vector objects, text or complex nested Sprite's to a flattened bitmap.
function makeBitmapCopy(displayObj:IBitmapDrawable, transparent:Boolean = false, bgColor:uint = 0x00000000, smooth:Boolean = true):Bitmap {
...