From guides.rubyonrails.org:
Instead of generating a model directly . . . let's set up a scaffold. A scaffold in Rails is a full set of model, database migration for that model, controller to manipulate it, views to view and manipulate the data, and a test suite for each of the above.
Here's a...
git config --global merge.conflictstyle diff3
Sets the diff3 style as default: instead of the usual format in conflicted sections, showing the two files:
<<<<<<< HEAD
left
=======
right
>>>>>>> master
it will include an additional section containi...
PowerShell, unlike some other scripting languages, sends objects through the pipeline. What this means is that when you send data from one command to another, it's essential to be able to create, modify, and collect objects.
Creating an object is simple. Most objects you create will be custom obj...
Each time WordPress loads the page, it will run main loop.
The loop is the way to iterate over all elements related to the page you are currently on.
Main loop will work on a global WP_Query object. The query has a globalized method have_posts(), that allows us to loop through all results. Finally...
The following code will show week of the year number on the left side of the datepicker. By default the week start on Monday, but it can be customized using firstDay option. The first week of the year contains the first Thursday of the year, following the ISO 8601 definition.
<input type="t...
Redis is an in-memory remote database that offers high performance, replication, and a unique data model to produce a platform for solving problems. Redis is an open source (BSD licensed), in-memory data structure , used as database, cache and message broker. It is categorized as a NoSQL key-value s...
Bitwise operators perform operations on bit values of data. These operators convert operands to signed 32-bit integers in two's complement.
Conversion to 32-bit integers
Numbers with more than 32 bits discard their most significant bits. For example, the following integer with more than 32 bits i...
int *ptr = nullptr;
*ptr = 1; // Undefined behavior
This is undefined behavior, because a null pointer does not point to any valid object, so there is no object at *ptr to write to.
Although this most often causes a segmentation fault, it is undefined and anything can happen.
Omitting the return statement in a function which is has a return type that is not void is undefined behavior.
int function() {
// Missing return statement
}
int main() {
function(); //Undefined Behavior
}
Most modern day compilers emit a warning at compile time for this kind o...
It is best practice in any programming language to avoid premature optimization. However, if testing reveals that your code is running too slowly, you may gain some speed by switching off some of the application’s properties while it runs. Add this code to a standard module:
Public Sub SpeedUp( _
...
Here is an example class which has a couple of instance variables, without using properties:
@interface TestClass : NSObject {
NSString *_someString;
int _someInt;
}
-(NSString *)someString;
-(void)setSomeString:(NSString *)newString;
-(int)someInt;
-(void)setSomeInt:(NSString *)...
The program outputs Hello World! to standard output.
module HELLO_WORLD(); // module doesn't have input or outputs
initial begin
$display("Hello World");
$finish; // stop the simulator
end
endmodule
Module is a basic building block in Verilog. It represent a collection...
The syntax for Java generics bounded wildcards, representing the unknown type by ? is:
? extends T represents an upper bounded wildcard. The unknown type represents a type that must be a subtype of T, or type T itself.
? super T represents a lower bounded wildcard. The unknown type repres...
For programmers coming from GCC or Clang to Visual Studio, or programmers more comfortable with the command line in general, you can use the Visual C++ compiler from the command line as well as the IDE.
If you desire to compile your code from the command line in Visual Studio, you first need to set...
When using labels, both the start and the stop are included in the results.
import pandas as pd
import numpy as np
np.random.seed(5)
df = pd.DataFrame(np.random.randint(100, size=(5, 5)), columns = list("ABCDE"),
index = ["R" + str(i) for i in range(5)])
...
Extension methods can be used for writing strongly typed wrappers for dictionary-like objects. For example a cache, HttpContext.Items at cetera...
public static class CacheExtensions
{
public static void SetUserInfo(this Cache cache, UserInfo data) =>
cache["UserInfo"] ...
Often when programming it is necessary to make some distinction between a variable that has a value and one that does not. For reference types, such as C Pointers, a special value such as null can be used to indicate that the variable has no value. For intrinsic types, such as an integer, it is mo...
You can also receive regular updates of the user's location; for example, as they move around while using a mobile device. Location tracking over time can be very sensitive, so be sure to explain to the user ahead of time why you're requesting this permission and how you'll use the data.
if (naviga...