Tutorial by Examples: c

To execute a Redis command using Jedis, you make method calls against the Jedis object you created from the pool. Jedis exposes Redis commands as method calls, some example are: - String get(String key) - Long geoadd(String key, double longitude, double latitude, String member) - List<String...
Many C++ libraries use enums and return/receive data using vectors that contain enums. As C enums are not Objective-C objects, Objective-C collections cannot be used directly with C enums. The example below deals with this by using a combination of an NSArray and generics and a wrapper object for th...
List<Integer> immutableEmptyList = List.of(); Initializes an empty, immutable List<Integer>. List<Integer> immutableList = List.of(1, 2, 3, 4, 5); Initializes an immutable List<Integer> with five initial elements. List<Integer> mutableList = new ArrayL...
Set<Integer> immutableEmptySet = Set.of(); Initializes an empty, immutable Set<Integer>. Set<Integer> immutableSet = Set.of(1, 2, 3, 4, 5); Initializes an immutable Set<Integer> with five initial elements. Set<Integer> mutableSet = new HashSet<>(...
Map<Integer, Integer> immutableEmptyMap = Map.of(); Initializes an empty, immutable Map<Integer, Integer>. Map<Integer, Integer> immutableMap = Map.of(1, 2, 3, 4); Initializes an immutable Map<Integer, Integer> with two initial key-value entries. Map<Inte...
Service that is used for communication: import { Injectable } from '@angular/core'; import { Subject } from 'rxjs/Subject'; @Injectable() export class ComponentCommunicationService { private componentChangeSource = new Subject(); private newDateCreationSource = new Subject<Date&...
Factory pattern decouples object creation and allows creation by name using a common interface: class Animal{ public: virtual std::shared_ptr<Animal> clone() const = 0; virtual std::string getname() const = 0; }; class Bear: public Animal{ public: virtual std::shared_ptr...
Node.js is a Javascript engine (Google's V8 engine for Chrome, written in C++) that allows to run Javascript outside the browser. While numerous libraries are available for extending Node's functionalities, the engine comes with a set of core modules implementing basic functionalities. There's curr...
Sometimes you need to create your own Event, one that other plugins can listen to (Vault, among other plugins, does this) and even cancel. Bukkit's Event API allows this to be possible. All you need to do is make a new class, have it extend Event, add the handlers and the attributes your event needs...
#include <mutex> #include <condition_variable> class Semaphore { public: Semaphore (int count_ = 0) : count(count_) { } inline void notify( int tid ) { std::unique_lock<std::mutex> lock(mtx); count++; cout <...
If you have a lot of commands, you shouldn't put them all in the main class. Make a new class and have it implement CommandExecutor Add the following to the class: @Override public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { } In your...
The following function adds four threads. Three threads compete for the semaphore, which is set to a count of one. A slower thread calls notify_one(), allowing one of the waiting threads to proceed. The result is that s1 immediately starts spinning, causing the Semaphore's usage count to remain be...
Introduction Julia uses the following syntax for dictionaries: Dict({k₁ => v₁, k₂ => v₂, …, kₙ₋₁ => vₙ₋₁, kₙ => vₙ) While Python and JSON looks like this: {k₁: v₁, k₂: v₂, …, kₙ₋₁: vₙ₋₁, kₙ: vₙ} For illustrative purposes we could also use this syntax in Julia and add new seman...
JavaScript uses reference counting technique to detect unused objects. When reference count to an object is zero, that object will be released by the garbage collector. Weakmap uses weak reference that does not contribute to reference count of an object, therefore it is very useful to solve memory l...
To create our own MessageBox control simply follow the guide below... Open up your instance of Visual Studio (VS 2008/2010/2012/2015/2017) Go to the toolbar at the top and click File -> New Project --> Windows Forms Application --> Give the project a name and then click ok. O...
public FontFamily Maneteke = GetResourceFontFamily(Properties.Resources.manteka);
Signals are only available to GObject classes. They can only be public, which means that any part of the code can connect handlers and trigger them. public class Emitter : Object { // A signal is declared like a method, // but with the signal keyword. public signal void my_signal ();...
Signals can have a default handler. All you need to do is to give it a body when you declare it. public class Emitter : Object { public signal void my_signal () { print ("Hello from the default handler!\n"); } } This handler will always be called after the connected...
You can declare a UIFont as follows: var font: UIFont! UIFont has more init() methods: UIFont.init(descriptor: UIFontDescriptor, size: CGFloat) UIFont.init(name: String, size: CGFloat) Therefore, you can initialize a UIFont like this: let font = UIFont(name: "Helvetica Neue", s...
To change a label's text font, you need to access its font property: label.font = UIFont(name:"Helvetica Neue", size: 15) The code above will change the font of the label to Helvetica Neue, size 15. Beware that you must spell the font name correctly, otherwise it will throw this error,...

Page 761 of 826