Tutorial by Examples: c

Counting references on strings is thread-safe. Locks and exception handlers are used to safeguard the process. Consider the following code, with comments indicating where the compiler inserts code at compile time to manage reference counts: procedure PassWithNoModifier(S: string); // prologue: Inc...
Java provides the instanceof operator to test if an object is of a certain type, or a subclass of that type. The program can then choose to cast or not cast that object accordingly. Object obj = Calendar.getInstance(); long time = 0; if(obj instanceof Calendar) { time = ((Calendar)obj).ge...
It can be useful to load a resource (image, text file, properties, KeyStore, ...) that is packaged inside a JAR. For this purpose, we can use the Class and ClassLoaders. Suppose we have the following project structure : program.jar | \-com \-project | |-file.txt \-Test.class ...
One potential implementation of Redis as a backend caching utility is the django-redis-cache package. This example assumes you already have a Redis server operating. $ pip install django-redis-cache Edit your settings.py to include a CACHES object (see Django documentation on caching). CACHES ...
SimpleDateFormatter is great in a pinch, but like the name suggests it doesn't scale well. If you hard-code "MM/dd/yyyy" all over your application your international users won't be happy. Let Java do the work for you Use the static methods in DateFormat to retrieve the right formatting ...
dput() and dget() The easiest way to share a (preferable small) data frame is to use a basic function dput(). It will export an R object in a plain text form. Note: Before making the example data below, make sure you're in an empty folder you can write to. Run getwd() and read ?setwd if you need t...
Package reproducibility is a very common issue in reproducing some R code. When various packages get updated, some interconnections between them may break. The ideal solution for the problem is to reproduce the image of the R code writer's machine on your computer at the date when the code was writt...
When you show a location to your users, you might want the MKMapView to display a coordinate at a zoom-level instead of setting a region to show. This functionality is not implemented by default, so you need to extend MKMapView with a methods that do the complex calculation from a coordinate and zoo...
In Python 2, writing directly to a file handle returns None: Python 2.x2.3 hi = sys.stdout.write('hello world\n') # Out: hello world type(hi) # Out: <type 'NoneType'> In Python 3, writing to a handle will return the number of characters written when writing text, and the number of by...
Prerequisites Have Maven installed. Have an IDE installed such as Intellij, Eclipse, or NetBeans. Create a Maven project Create a Maven project with the standard project structure (i.e. Group ID as com.organization.app and Artifact ID as SpringBatchExample: SpringBatchExample |-- pom.xml ...
Interface: public interface FooService { public int doSomething(); } Class: @Service public class FooServiceImpl implements FooService { @Override public int doSomething() { //Do some stuff here return 0; } } It should be noted that a class must imple...
Often times you will need to be able to manage your notifications, by being able to keep track of them and cancel them. Track a notification You can assign a UUID (universally unique identifier) to a notification, so you can track it: Swift let notification = UILocalNotification() let uuid = NS...
public void iterate(final String dirPath) throws IOException { final DirectoryStream<Path> paths = Files.newDirectoryStream(Paths.get(dirPath)); for (final Path path : paths) { if (Files.isDirectory(path)) { System.out.println(path.getFileName()); } } ...
Each gem has a file in the format of <gem name>.gemspec which contains metadata about the gem and it's files. The format of a gemspec is as follows: Gem::Specification.new do |s| # Details about gem. They are added in the format: s.<detail name> = <detail value> end The ...
MY_CONSTANT = "Hello, world" # constant Constant = 'This is also constant' # constant my_variable = "Hello, venus" # not constatn Constant name start with capital letter. Everything that start with capital letter are considered as constant in Ruby. So class and module are al...
MY_CONSTANT = "Hello, world" MY_CONSTANT = "Hullo, world" The above code results in a warning, because you should be using variables if you want to change their values. However it is possible to change one letter at a time in a constant without a warning, like this: MY_CONST...
def say_hi MESSAGE = "Hello" puts MESSAGE end The above code results in an error: SyntaxError: (irb):2: dynamic constant assignment.
class Message DEFAULT_MESSAGE = "Hello, world" def speak(message = nil) if message puts message else puts DEFAULT_MESSAGE end end end The constant DEFAULT_MESSAGE can be changed with the following code: Message::DEFAULT_MESSAGE = "Hullo, wo...
Local variables (unlike the other variable classes) do not have any prefix local_variable = "local" p local_variable # => local Its scope is dependent on where it has been declared, it can not be used outside the "declaration containers" scope. For example, if a local va...
Class variables have a class wide scope, they can be declared anywhere in the class. A variable will be considered a class variable when prefixed with @@ class Dinosaur @@classification = "Like a Reptile, but like a bird" def self.classification @@classification ...

Page 341 of 826