// Checks a string to see if it is a palindrome
bool function IsPalindrome(string input) {
if (input.size() <= 1) {
return true;
}
else if (input[0] == input[input.size() - 1]) {
return IsPalindrome(input.substr(1,input.size() - 2));
}
else {
r...
Custom events usually need custom event arguments containing information about the event. For example MouseEventArgs which is used by mouse events like MouseDown or MouseUp events, contains information about Location or Buttons which used to generate the event.
When creating new events, to create a...
If you have a list, and you want to use the elements of that list as the arguments to a function, what you want is apply:
> (apply string-append (list "hello" " " "and hi" " " "are both words"))
"hello and hi are both words"
> (app...
Functions in Racket can be created with the lambda form. The form takes a list of arguments and a body.
(lambda (x y) (* x y))
In the example above, the function takes in two arguments and returns the result of multiplying them.
> ((lambda (x y) (* x y)) 4 4)
16
> ((lambda (x y) (* x y)...
Download and install Visual Studio Community 2015
Open Visual Studio Community
Click File -> New -> Project
Click Templates -> Visual C++ -> Win32 Console Application and then name the project MyFirstProgram.
Click Ok
Click Next in the following window.
Check the Empty proj...
Thread.sleep causes the current thread to suspend execution for a specified period. This is an efficient means of making processor time available to the other threads of an application or other applications that might be running on a computer system. There are two overloaded sleep methods in the Thr...
One of the most useful queries for end users of large RDBMS's is a search of an information schema.
Such a query allows users to rapidly find database tables containing columns of interest, such as when attempting to relate data from 2 tables indirectly through a third table, without existing knowl...
The function angular.isFunction determines and returns true if and only if the value passed to is a reference to a function.
The function returns a reference to the now extended destination object
angular.isFunction(fn)
Examples
var onClick = function(e) {return e};
angular.isFunction(onCli...
Be careful, this approach might be considered as a bad design for angular apps, since it requires programmers to remember both where functions are placed in the scope tree, and to be aware of scope inheritance. In many cases it would be preferred to inject a service (Angular practice - using scope ...
In medical imaging, spectroscopy, image processing, cryptography and other areas of science and engineering it is often the case that one wishes to compute multidimensional Fourier transforms of images. This is quite straightforward in Matlab: (multidimensional) images are just n-dimensional matrice...
_mycompletion() {
local command_name="$1" # not used in this example
local current_word="$2"
local previous_word="$3" # not used in this example
# COMPREPLY is an array which has to be filled with the possible completions
# compgen is used to fi...
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?yourdomain.com/.*$ [NC]
RewriteRule \.(gif|jpg|css)$ - [F]
This blocks all the links to '.gif', '.jpg' and '.css' files which are not from the domain name http://www.yourdomain.com.
Display alterna...
When files are not available, the require family will throw a LoadError. This is an example which illustrates loading optional modules only if they exist.
module TidBits
@@unavailableModules = []
[
{ name: 'CoreExtend', file: 'core_extend/lib/core_extend' } \
, { name: 'Fs' ...
This function returns the floating-point remainder of the division of x/y. The returned value has the same sign as x.
#include <math.h> /* for fmod() */
#include <stdio.h> /* for printf() */
int main(void)
{
double x = 10.0;
double y = 5.1;
double modulus = fmod(x,...
Visual Studio Code is an open-source and feature-rich code editor from Microsoft. To set it up it for NativeScript development, open the Command Palette (F1 or ⌘+Shift+P) and type ext install NativeScript.
Once the NativeScript extension is installed, the debugger should allow you to set breakpoint...
Named Functions
defmodule Math do
# one way
def add(a, b) do
a + b
end
# another way
def subtract(a, b), do: a - b
end
iex> Math.add(2, 3)
5
:ok
iex> Math.subtract(5, 2)
3
:ok
Private Functions
defmodule Math do
def sum(a, b) do
a...
A sequence is a series of elements that can be enumerated. It is an alias of System.Collections.Generic.IEnumerable and lazy. It stores a series of elements of the same type (can be any value or object, even another sequence). Functions from the Seq.module can be used to operate on it.
Here is a s...
Autoboxing can come at a substantial memory overhead. For example:
Map<Integer, Integer> square = new HashMap<Integer, Integer>();
for(int i = 256; i < 1024; i++) {
square.put(i, i * i); // Autoboxing of large integers
}
will typically consume substantial amount of memory (...