Tutorial by Examples: c

You can setup your client browser to listen in incoming server events using the EventSource object. You will need to supply the constructor a string of the path to the server' API enpoint the will subscribe the client to the server events. Example: var eventSource = new EventSource("api/my-ev...
An event stream to the server can be closed using the EventSource.close() method var eventSource = new EventSource("api/my-events"); // do things ... eventSource.close(); // you will not receive anymore events from this object The .close() method does nothing is the stream is already...
Requirements: PHP 5.6.0 or greater mbstring PHP extension (default works in WAMP/XAMPP, if not then enable it) intl PHP extension (Available in WAMP/XAMPP, you have to enable it from php.ini) CakePHP will run on a variety of web servers such as nginx, LightHTTPD, or Microsoft IIS. Befor...
Suppose that we have the following text file: jekyll_hyde.txt How do we convert it to a PDF that looks like this: When using iText 5, you'd need code like this: public void createPdf(String dest) throws DocumentException, IOException { Document document = new Document(); PdfWriter wr...
Suppose that you have the following text file: jekyll_hyde.txt How do we convert it to a PDF that looks like this: When using iText 7, you'd need code like this: public void createPdf(String dest) throws IOException { PdfDocument pdf = new PdfDocument(new PdfWriter(dest)); Document do...
Executable JAR files are the simplest way to assemble Java code into a single file that can be executed. *(Editorial Note: Creation of JAR files should be covered by a separate Topic.) * Assuming that you have an executable JAR file with pathname <jar-path>, you should be able to run it as f...
To Initialize a session, you can simply load it in your controller, this us usually placed inside the controller constructs, but it also can be autoloaded into the array found inside application/config/autoload.php: $this->load->library('session');
This example illustrates the AES 256 symmetric cipher in CBC mode. An initialization vector is needed, so we generate one using an openssl function. The variable $strong is used to determine whether the IV generated was cryptographically strong. Encryption $method = "aes-256-cbc"; // cip...
In the .bashrc or .bash_profile, adding: export MYSQL_PS1="\u@\h [\d]>" make the MySQL client PROMPT show current user@host [database].
Objective-C NSPredicate *predicate = [NSPredicate predicateWithBlock:^BOOL(id item, NSDictionary *bindings) { return [item isKindOfClass:[UILabel class]]; }]; Swift let predicate = NSPredicate { (item, bindings) -> Bool...
Objective-C NSPredicate *predicate = [NSPredicate predicateWithFormat: @"self[SIZE] = %d", 5)]; Swift let predicate = NSPredicate(format: "self[SIZE] >= %d", 5) In this example, the predicate will match items that are arrays with length of at least 5.
An NSPredicate can use substitution variables to allow values to be bound on the fly. Objective-C NSPredicate *template = [NSPredicate predicateWithFormat: @"self BEGINSWITH $letter"]; NSDictionary *variables = @{ @"letter": @"r" }; NSPredicate *beginsWithR = [templ...
Objective-C NSArray *heroes = @[@"tracer", @"bastion", @"reaper", @"junkrat", @"roadhog"]; NSPredicate *template = [NSPredicate predicateWithFormat:@"self BEGINSWITH $letter"]; NSDictionary *beginsWithRVariables = @{ @"letter&qu...
To prevent memory leaks, one should not forget to close an input stream or an output stream whose job is done. This is usually done with a try-catch-finally statement without the catch part: void writeNullBytesToAFile(int count, String filename) throws IOException { FileOutputStream out = null...
You can bind event listeners to the EventSource object to listen to different events channels using the .addEventListener method. EventSource.addEventListener(name: String, callback: Function, [options]) name: The name related to the name of the channel the server is emitting events to. callb...
It is always a good practice to test how push notifications work even before you have your server side ready for them, just to make sure that everything is set up correctly on your side. It is quite easy to send yourself a push notification using a following PHP script. Save the script as a file ...
Save aps.cer to a folder Open "Keychain access" and export the key that is under that certificate to a .p12 file (call it key.p12). To do that right click on it and choose Export. Save it to the same folder as step 1. On export you will be prompted for a password. Make something u...
JAXB can be used to generate classes from an model defined in XSD. It will then be possible to read XML document made against this XSD directly as java instances and inversly save these instances as XML document. Take the following XSD saved in a file named SimpleModel.xsd <?xml version="...
When an application has not been packaged as an executable JAR, you need to provide the name of an entry-point class on the java command line. Running the HelloWorld class The "HelloWorld" example is described in Creating a new Java program . It consists of a single class called HelloWo...
A Java entry-point class has a main method with the following signature and modifiers: public static void main(String[] args) Sidenote: because of how arrays work, it can also be (String args[]) When the java command starts the virtual machine, it loads the specified entry-point classes and...

Page 497 of 826