Tutorial by Examples: ed

This type of Singleton is thread safe, and prevents unnecessary locking after the Singleton instance has been created. Java SE 5 public class MySingleton { // instance of class private static volatile MySingleton instance = null; // Private constructor private MySingleton()...
When defining discriminated unions you can name elements of tuple types and use these names during pattern matching. type Shape = | Circle of diameter:int | Rectangle of width:int * height:int let shapeIsTenWide = function | Circle(diameter=10) | Rectangle(width=10) -> t...
Ruby can inject an array of values into a string by replacing any placeholders with the values from the supplied array. "Hello %s, my name is %s!" % ['World', 'br3nt'] # => Hello World, my name is br3nt! The place holders are represented by two %s and the values are supplied by the...
// Modify some of the attributes of the attributed string. let attributedText = NSMutableAttributedString(attributedString: textView.attributedText!) // Use NSString so the result of rangeOfString is an NSRange. let text = textView.text! as NSString // Find the range of each element to modif...
Auto-implemented properties were introduced in C# 3. An auto-implemented property is declared with an empty getter and setter (accessors): public bool IsValid { get; set; } When an auto-implemented property is written in your code, the compiler creates a private anonymous field that can only be...
Overview In order to debug Java classes that are called during MATLAB execution, it is necessary to perform two steps: Run MATLAB in JVM debugging mode. Attach a Java debugger to the MATLAB process. When MATLAB is started in JVM debugging mode, the following message appears in the command wi...
C++17 C++17 introduces structured bindings, which makes it even easier to deal with multiple return types, as you do not need to rely upon std::tie() or do any manual tuple unpacking: std::map<std::string, int> m; // insert an element into the map and check if insertion succeeded auto [i...
To get a verbose list of all devices connected to adb, write the following command in your terminal: adb devices -l Example Output List of devices attached ZX1G425DC6 device usb:336592896X product:shamu model:Nexus_6 device:shamu 013e4e127e59a868 device usb:337641472X produc...
After creating a new model or modifying existing models, you will need to generate migrations for your changes and then apply the migrations to the specified database. This can be done by using the Django's built-in migrations system. Using the manage.py utility when in the project root directory: ...
We can name our loops and break the specific one when necessary. outerloop: for (var i = 0;i<3;i++){ innerloup: for (var j = 0;j <3; j++){ console.log(i); console.log(j); if (j == 1){ break outerloop; } } } Output: 0 0...
For security reasons, PowerShell is set up by default to only allow signed scripts to execute. Executing the following command will allow you to run unsigned scripts (you must run PowerShell as Administrator to do this). Set-ExecutionPolicy RemoteSigned Another way to run PowerShell scripts is t...
Success output stream: cmdlet > file # Send success output to file, overwriting existing content cmdlet >> file # Send success output to file, appending to existing content cmdlet 1>&2 # Send success and error output to error stream Error output stream: cmdlet 2&g...
class Animal def method_missing(method, *args, &block) "Cannot call #{method} on Animal" end end => Animal.new.say_moo > "Cannot call say_moo on Animal"
When a column name matches a reserved keyword, standard SQL requires that you enclose it in double quotation marks: SELECT "ORDER", ID FROM ORDERS Note that it makes the column name case-sensitive. Some DBMSes have proprietary ways of quoting names. For example, SQL Serve...
Some convenience functions to manipulate data.frames are subset(), transform(), with() and within(). subset The subset() function allows you to subset a data.frame in a more convenient way (subset also works with other classes): subset(mtcars, subset = cyl == 6, select = c("mpg", "...
When pattern matching an object whose type is a sealed trait, Scala will check at compile-time that all cases are 'exhaustively matched': sealed trait Shape case class Square(height: Int, width: Int) extends Shape case class Circle(radius: Int) extends Shape case object Point extends Shape ...
Media Queries in Bootstrap allow you to move, show and hide content based on the viewport size. The following media queries are used in LESS files to create the key breakpoints in the Bootstrap grid system: /* Small devices (tablets, 768px and up) */ @media (min-width: @screen-sm-min) { ... } /...
You may add your new Seeder to the DatabaseSeeder class. /** * Run the database seeds. * * @return void */ public function run() { $this->call(UserTableSeeder::class); } To run a database seeder, use the Artisan command php artisan db:seed ...
Database seeds are stored in the /database/seeds directory. You can create a seed using an Artisan command. php artisan make:seed UserTableSeeder Alternatively you can create a new class which extends Illuminate\Database\Seeder. The class must a public function named run().
You can reference models in a seeder. use DB; use App\Models\User; class UserTableSeeder extends Illuminate\Database\Seeder{ public function run(){ # Remove all existing entrie DB::table('users')->delete() ; User::create([ 'name' => 'Admin', ...

Page 13 of 145