Tutorial by Examples: cer

var collection = new BlockingCollection<int>(5); var random = new Random(); var producerTask = Task.Run(() => { for(int item=1; item<=10; item++) { collection.Add(item); Console.WriteLine("Produced: " + item); Thread.Sleep(random.Next(1...
A simple example of producer-consumer problem solution. Notice that JDK classes (AtomicBoolean and BlockingQueue) are used for synchronization, which reduces the chance of creating an invalid solution. Consult Javadoc for various types of BlockingQueue; choosing different implementation may drastica...
format() from SimpleDateFormat class helps to convert a Date object into certain format String object by using the supplied pattern string. Date today = new Date(); SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MMM-yy"); //pattern is specified here System.out.println(date...
Routes are defined in config/routes.rb. They are often defined as a group of related routes, using the resources or resource methods. resources :users creates the following seven routes, all mapping to actions of UsersController: get '/users', to: 'users#index' post '/users', ...
A replacer function can be used to filter or transform values being serialized. const userRecords = [ {name: "Joe", points: 14.9, level: 31.5}, {name: "Jane", points: 35.5, level: 74.4}, {name: "Jacob", points: 18.5, level: 41.2}, {name: "Jessie",...
#include <stdio.h> #define is_const_int(x) _Generic((&x), \ const int *: "a const int", \ int *: "a non-const int", \ default: "of other type") int main(void) { const int i = 1; int j = 1; double...
This data is collected by the http_unit and scollector. It warns when an alert is going to expire within a certain amount of days, and then goes critical if the cert has passed the expiration date. This follows the recommended default of warn and crit usage in Bosun (warn: something is going to fail...
This will delete all rows that match the WHERE criteria. DELETE FROM Employees WHERE FName = 'John'
To avoid repetition in nested routes, concerns provide a great way of sharing common resources that are reusable. To create a concern use the method concern within the routes.rb file. The method expects a symbol and block: concern :commentable do resources :comments end While not creating a...
There are two ways to achieve that, the first and most known is the following: docker attach --sig-proxy=false <container> This one literally attaches your bash to the container bash, meaning that if you have a running script, you will see the result. To detach, just type: Ctl-P Ctl-Q Bu...
In this approach, the single is accessed via the static method: Singleton.getInstance(); To enforce only one instance of the singleton, a private static variable retains the instance, while any additional attempts to instantiate an instance are enforced within the constructor. package { publ...
Imagine the following XML: <root> <element>hello</element> <another> hello </another> <example>Hello, <nested> I am an example </nested>.</example> </root> The following XPath expression: //*[text() = 'hel...
Output can be restricted by specifying line ranges as git blame -L <start>,<end> Where <start> and <end> can be: line number git blame -L 10,30 /regex/ git blame -L /void main/, git blame -L 46,/void foo/ +offset, -offset (only for <end>) git blame -...
A common problem is having a collection of items that all need to meet a certain criteria. In the example below we have collected two items for a diet plan and we want to check that the diet doesn't contain any unhealthy food. // First we create a collection $diet = collect([ ['name' => ...
You will often find yourself with a collection of data where you are only interested in parts of the data. In the example below we got a list of participants at an event and we want to provide a the tour guide with a simple list of names. // First we collect the participants $participants = colle...
If you have both Python 3 and Python 2 installed, you can specify which version of Python you would like pip to use. This is useful when packages only support Python 2 or 3 or when you wish to test with both. If you want to install packages for Python 2, run either: pip install [package] or: p...
Case classes provide a copy method that creates a new object that shares the same fields as the old one, with certain changes. We can use this feature to create a new object from a previous one that has some of the same characteristics. This simple case class to demonstrates this feature: case cla...
I have the following list: 1. Alon Cohen 2. Elad Yaron 3. Yaron Amrani 4. Yogev Yaron I want to select the first name of the guys with the Yaron surname. Since I don't care about what number it is I'll just put it as whatever digit it is and a matching dot and space after it from the beginni...
perl -lane'print "$F[0] $F[-1]"' data.txt # prints the first and the last fields of a space delimited record CSV example: perl -F, -lane'print "$F[0] $F[-1]"' data.csv
Below code showcases multiple Producer/Consumer program. Both Producer and Consumer threads share same global queue. import java.util.concurrent.*; import java.util.Random; public class ProducerConsumerWithES { public static void main(String args[]) { BlockingQueue<Integer> ...

Page 1 of 4