Tutorial by Examples: c

In the new Angular framework, Components are the main building blocks that compose the user interface. So one of the first steps that helps an AngularJS app to be migrated to the new Angular is to refactor it into a more component-oriented structure. Components were also introduced in the old Angu...
This snippet will list all the filenames of a zip archive. The filenames are relative to the zip root. using (FileStream fs = new FileStream("archive.zip", FileMode.Open)) using (ZipArchive archive = new ZipArchive(fs, ZipArchiveMode.Read)) { for (int i = 0; i < archive.Entries....
Extracting all the files into a directory is very easy: using (FileStream fs = new FileStream("archive.zip", FileMode.Open)) using (ZipArchive archive = new ZipArchive(fs, ZipArchiveMode.Read)) { archive.ExtractToDirectory(AppDomain.CurrentDomain.BaseDirectory); } When the file...
If you want to use Swift3.0 or Bitcode you can add this code in your podfile. post_install do |installer| installer.pods_project.targets.each do |target| target.build_configurations.each do |config| config.build_settings['ENABLE_BITCODE'] = 'YES' config.build_settings['SWIFT...
For this example we will test the sum method of a simple calculator. In this example we will test the application: ApplicationToTest. This one has a class called Calc. This class has a method Sum(). The method Sum() looks like this: public void Sum(int a, int b) { return a + b; } The un...
Java Singleton Pattern To implement Singleton pattern, we have different approaches but all of them have following common concepts. Private constructor to restrict instantiation of the class from other classes. Private static variable of the same class that is the only instance of the class. P...
In order to set the pagination style for the entire project, you need to set the DEFAULT_PAGINATION_CLASS and PAGE_SIZE on the project settings. To do so, go to settings.py and on the REST_FRAMEWORK variable, add the following: REST_FRAMEWORK = { 'DEFAULT_PAGINATION_CLASS': 'rest_fr...
Decoding the chunks of a PNG file demonstrates Okio in practice. private static final ByteString PNG_HEADER = ByteString.decodeHex("89504e470d0a1a0a"); public void decodePng(InputStream in) throws IOException { try (BufferedSource pngSource = Okio.buffer(Okio.source(in))) { Byt...
Open the C# project Right-click on the solution -> Add -> New Project… (Figure 1) Go to Installed -> Visual C# -> Test Click on Unit Test Project Give it a name and click OK (Figure 2) The unit test project is added to the solution (Figure 3) Adding the referen...
Method 1 Go to your unit test class in the unit test project Write a unit test [Testclass] public class UnitTest1 { [TestMethod] public void TestMethod1() { //Arrange ApplicationToTest.Calc ClassCalc = new ApplicationToTest.Calc(); int expectedResul...
To see you unit tests go to Test -> Windows -> Code Coverage Results (Figure 1) It will open the following window (Figure 2) The window is now empty Go to the Test menu -> Analyze Code Coverage (Figure 3) The tests will now be run as well (See the results in the T...
Override Pagination Style: Every available pagination style can be overridden by creating a new class that inherits from one of the available styles and then alters its parameters: class MyPagination(PageNumberPagination): page_size = 20 page_size_query_param = 'page_size' max_page...
The nil-coalescing operator <OPTIONAL> ?? <DEFAULT VALUE> unwraps the <OPTIONAL> if it contains a value, or returns <DEFAULT VALUE> if is nil. <OPTIONAL> is always of an optional type. <DEFAULT VALUE> must match the type that is stored inside <OPTIONAL>. T...
We can perform a GROUP BY ... COUNT or a GROUP BY ... SUM SQL equivalent queries on Django ORM, with the use of annotate(), values(), order_by() and the django.db.models's Count and Sum methods respectfully: Let our model be: class Books(models.Model): title = models.CharField() ...
Lets assume that we have a complex api, with many generic views and some generic viewsets. We want to enable PageNumberPagination to every view, except one (either generic view or viewset, does not make a difference) for which we want a customized case of LimitOffsetPagination. To achieve that we n...
A generalization of std::condition_variable, std::condition_variable_any works with any type of BasicLockable structure. std::cv_status as a return status for a condition variable has two possible return codes: std::cv_status::no_timeout: There was no timeout, condition variable was notified st...
Function definition: def run_training(train_X, train_Y): Inputs variables: X = tf.placeholder(tf.float32, [m, n]) Y = tf.placeholder(tf.float32, [m, 1]) Weight and bias representation W = tf.Variable(tf.zeros([n, 1], dtype=np.float32), name="weight") b = tf.Variable(tf.zeros([...
This is an advanced subject, do not attempt without first understanding the other examples of this page. As stated in the official Django Rest Framework on pagination: Pagination is only performed automatically if you're using the generic views or viewsets. If you're using a regular APIView, you...
By using a module loader like Webpack we can benefit the built-in module system available in ES6 (as well as in TypeScript). We can then use the import and export features that allow us to specify what pieces of code can we are going to share between different parts of the application. When we then...
Laravel Scout - Laravel Scout provides a simple, driver-based solution for adding full-text search to your Eloquent models. Laravel Passport - API authentication without a headache. Passport is an OAuth2 server that's ready in minutes. Homestead - The official Laravel development environment. Po...

Page 773 of 826