Tutorial by Examples: sin

If you have an existing class that you'd like to use, perform Step 2 and then skip to Step 5. (For some cases, I had to add an explicit #import <Foundation/Foundation.h to an older ObjC File) Step 1: Add Objective-C Implementation -- .m Add a .m file to your class, and name it CustomObje...
Step 1: Create New Swift Class Add a .swift file to your project, and name it MySwiftObject.swift In MySwiftObject.swift: import Foundation class MySwiftObject : NSObject { var someProperty: AnyObject = "Some Initializer Val" init() {} func someFunction(someArg...
Java-like enumerations can be created by extending Enumeration. object WeekDays extends Enumeration { val Mon, Tue, Wed, Thu, Fri, Sat, Sun = Value } def isWeekend(day: WeekDays.Value): Boolean = day match { case WeekDays.Sat | WeekDays.Sun => true case _ => false } isWeekend...
An alternative to extending Enumeration is using sealed case objects: sealed trait WeekDay object WeekDay { case object Mon extends WeekDay case object Tue extends WeekDay case object Wed extends WeekDay case object Thu extends WeekDay case object Fri extends WeekDay case objec...
When accessing arrays with pointers, there are no bounds check and therefore no IndexOutOfRangeException will be thrown. This makes the code faster. Assigning values to an array with a pointer: class Program { static void Main(string[] args) { unsafe { int...
You can use the !$ to reduce repetition when using the command line: $ echo ping ping $ echo !$ ping You can also build upon the repetition $ echo !$ pong ping pong $ echo !$, a great game pong, a great game Notice that in the last example we did not get ping pong, a great game because...
Examples below are given in Ruby, but same matchers should be available in any modern language. Let’s say we have the string "AℵNaïve", produced by Messy Artificial Intelligence. It consists of letters, but generic \w matcher won’t match much: ▶ "AℵNaïve"[/\w+/] #⇒ "A&q...
The splice()method can be used to remove elements from an array. In this example, we remove the first 3 from the array. var values = [1, 2, 3, 4, 5, 3]; var i = values.indexOf(3); if (i >= 0) { values.splice(i, 1); } // [1, 2, 4, 5, 3] The splice() method can also be used to add elemen...
Use the Bash shell's filename expansion and brace expansion capabilities to obtain the filenames: # display the files and directories that are in the current directory printf "%s\n" * # display only the directories in the current directory printf "%s\n" */ # display only...
Although D3 is not specific for handling SVG elements, it is widely used for creating and manipulating complex SVG based data visualizations. D3 provides many powerful methods which helps to create various geometrical SVG structures with ease. It is recommended to understand basic concepts of SVG s...
The random number generator can (and should) be used for multiple distributions. #include <iostream> #include <random> int main() { std::default_random_engine pseudo_random_generator; std::uniform_int_distribution<int> int_distribution(0, 9); std::uniform_real_dis...
To use the IronPython command line, open ipy.exe or ipy64.exe. Both files are located in the path that was selected during installation. By default they will be located at C:\Program Files\IronPython 2.7\. Then start writing your statements directly in the IronPython command line. For example: pr...
There are two types of using keyword usage, using statement and using directive: using statement: The using keyword ensures that objects that implement the IDisposable interface are properly disposed after usage. There is a separate topic for the using statement using directive The using...
public class Singleton { private static final Singleton INSTANCE = new Singleton(); private Singleton() {} public static Singleton getInstance() { return INSTANCE; } } It can be argued that this example is effectively lazy initialization. Section 12.4.1 of ...
Start with an iterable which needs to be grouped lst = [("a", 5, 6), ("b", 2, 4), ("a", 2, 5), ("c", 2, 6)] Generate the grouped generator, grouping by the second element in each tuple: def testGroupBy(lst): groups = itertools.groupby(lst, key=lambda...
CSS can be applied in multiple places: inline (Node.setStyle) in a stylesheet to a Scene as user agent stylesheet (not demonstrated here) as "normal" stylesheet for the Scene to a Node This allows to change styleable properties of Nodes. The following example demonst...
a reference to seq_name.NEXTVAL is used to get the next value in a sequence. A single statement can only generate a single sequence value. If there are multiple references to NEXTVAL in a statement, they use will use the same generated number. NEXTVAL can be used for INSERTS INSERT INTO Orders (Or...
const int July = 7; const int Feb = 2; int daysInJuly = System.DateTime.DaysInMonth(2001, July); Console.WriteLine(daysInJuly); // daysInFeb gets 28 because the year 1998 was not a leap year. int daysInFeb = System.DateTime.DaysInMonth(1998, Feb); Console.WriteLine(daysInFeb); // daysIn...
The following example demonstrates the use of a BackgroundWorker to update a WinForms ProgressBar. The backgroundWorker will update the value of the progress bar without blocking the UI thread, thus showing a reactive UI while work is done in the background. namespace BgWorkerExample { public...
Python supports a translate method on the str type which allows you to specify the translation table (used for replacements) as well as any characters which should be deleted in the process. str.translate(table[, deletechars]) ParameterDescriptiontableIt is a lookup table that defines the mappin...

Page 22 of 161