Tutorial by Examples: ad

Downloading a file from the internet is a very common task required by almost every application your likely to build. To accomplish this, you can use the "System.Net.WebClient" class. The simplest use of this, using the "using" pattern, is shown below: using (var webClient = n...
The Kernel#require method will load files only once (several calls to require will result in the code in that file being evaluated only once). It will search your ruby $LOAD_PATH to find the required file if the parameter is not an absolute path. Extensions like .rb, .so, .o or .dll are optional. Re...
The method Kernel#autoload registers filename to be loaded (using Kernel::require) the first time that module (which may be a String or a symbol) is accessed. autoload :MyModule, '/usr/local/lib/modules/my_module.rb' The method Kernel#autoload? returns filename to be loaded if name is registere...
When files are not available, the require family will throw a LoadError. This is an example which illustrates loading optional modules only if they exist. module TidBits @@unavailableModules = [] [ { name: 'CoreExtend', file: 'core_extend/lib/core_extend' } \ , { name: 'Fs' ...
The Kernel#load method will evaluate the code in the given file. The search path will be constructed as with require. It will re-evaluate that code on every subsequent call unlike require. There is no load_relative. load `somefile`
You can use any ruby technique to dynamically create a list of files to load. Illustration of globbing for files starting with test, loaded in alphabetical order. Dir[ "#{ __dir__ }**/test*.rb" ) ].sort.each do |source| require_relative source end
Autoboxing can come at a substantial memory overhead. For example: Map<Integer, Integer> square = new HashMap<Integer, Integer>(); for(int i = 256; i < 1024; i++) { square.put(i, i * i); // Autoboxing of large integers } will typically consume substantial amount of memory (...
As we know that we should use synchronized keyword to make execution of a method or block exclusive. But few of us may not be aware of one more important aspect of using synchronized and volatile keyword: apart from making a unit of code atomic, it also provides read / write barrier. What is this re...
Corner radius for all 4 edges: UIBezierPath* rectanglePath = [UIBezierPath bezierPathWithRoundedRect: CGRectMake(x,y,width,height) cornerRadius: 11]; [UIColor.grayColor setFill]; [rectanglePath fill]; Corner radius for top-left edge: UIBezierPath* rectanglePath = [UIBezierPath bezierPat...
Consider a simple rectangle that is drawn by the bezier path. UIBezierPath* rectanglePath = [UIBezierPath bezierPathWithRect: CGRectMake(x,y,width,height)]; [UIColor.grayColor setFill]; [rectanglePath fill]; Basic Outer-fill shadow: CGContextRef context = UIGraphicsGetCurrentContext();...
Add the following dependency to your project level build.gradle file. dependencies { classpath "io.realm:realm-gradle-plugin:3.1.2" } Add the following right at the top of your app level build.gradle file. apply plugin: 'realm-android' Complete a gradle sync and you now have ...
You have to point Gradle to the location of your plugins so Gradle can find them. Do this by adding a repositories { ... } to your build.gradle. Here's an example of adding three repositories, JCenter, Maven Repository, and a custom repository that offers dependencies in Maven style. repositories...
Rules for creating a dictionary: Every key must be unique (otherwise it will be overridden) Every key must be hashable (can use the hash function to hash it; otherwise TypeError will be thrown) There is no particular order for the keys. # Creating and populating it with values stock = {'egg...
def foobar(foo=None, bar=None): return "{}{}".format(foo, bar) values = {"foo": "foo", "bar": "bar"} foobar(**values) # "foobar"
A singleton is a pattern that restricts the instantiation of a class to one instance/object. Using a decorator, we can define a class as a singleton by forcing the class to either return an existing instance of the class or create a new instance (if it doesn't exist). def singleton(cls): i...
var degrees:Number = radians * 180 / Math.PI;
var radians:Number = degrees / 180 * Math.PI;
A whole circle is 360 degrees or Math.PI * 2 radians. Half of those values follows to be 180 degrees or Math.PI radians. A quarter is then 90 degrees or Math.PI / 2 radians. To get a segment as a percentage of a whole circle in radians: function getSegment(percent:Number):Number { retur...
The @Header and @Body annotations can be placed into the method signatures and Retrofit will automatically create them based on your models. public interface MyService { @POST("authentication/user") Call<AuthenticationResponse> authenticateUser(@Body AuthenticationReques...
By Assembly Name, add library Add-Type -AssemblyName "System.Math" or by file path: Add-Type -Path "D:\Libs\CustomMath.dll" To Use added type: [CustomMath.NameSpace]::Method(param1, $variableParam, [int]castMeAsIntParam)

Page 34 of 114