To set up a controller with user authentication using devise, add this before_action: (assuming your devise model is 'User'):
before_action :authenticate_user!
To verify if a user is signed in, use the following helper:
user_signed_in?
For the current signed-in user, use this helper:
current_us...
This design pattern is useful for generating a sequence of asynchronous actions from a list of elements.
There are two variants :
the "then" reduction, which builds a chain that continues as long as the chain experiences success.
the "catch" reduction, which builds a chain t...
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...
Events that work with most form elements (e.g., change, keydown, keyup, keypress) do not work with contenteditable.
Instead, you can listen to changes of contenteditable contents with the input event. Assuming contenteditableHtmlElement is a JS DOM object that is contenteditable:
contenteditableH...
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...
public class UnsafeLoader {
public static Unsafe loadUnsafe() {
return Unsafe.getUnsafe();
}
}
While this example will compile, it is likely to fail at runtime unless the Unsafe class was loaded with the primary classloader. To ensure that happens the JVM should be loaded with...
MySQL3.19
DROP TABLE IF EXISTS MyTable;
PostgreSQL8.x
DROP TABLE IF EXISTS MyTable;
SQL Server2005
If Exists(Select * From Information_Schema.Tables
Where Table_Schema = 'dbo'
And Table_Name = 'MyTable')
Drop Table dbo.MyTable
SQLite3.0
DROP TABLE IF EXI...
To get started programming with CUDA, download and install the CUDA Toolkit and developer driver. The toolkit includes nvcc, the NVIDIA CUDA Compiler, and other software necessary to develop CUDA applications. The driver ensures that GPU programs run correctly on CUDA-capable hardware, which you'll ...
You can install Json.Net into your Visual Studio Project in 1 of 2 ways.
Install Json.Net using the Package Manager Console.
Open the Package Manager Console window in Visual Studio either by typing package manager console in the Quick Launch box and selecting it
or by clicking View -> O...
A dotfile is a file whose names begin with a .. These are normally hidden by ls and not listed unless requested.
For example the following output of ls:
$ ls
bin pki
The -a or --all option will list all files, including dotfiles.
$ ls -a
. .ansible .bash_logout .bashrc .lesshst ...
Create a DataFrame from multiple lists by passing a dict whose values lists. The keys of the dictionary are used as column labels. The lists can also be ndarrays. The lists/ndarrays must all be the same length.
import pandas as pd
# Create DF from dict of lists/ndarrays
df = pd.DataFrame({'...
To modify an existing column in Rails with a migration, run the following command:
rails g migration change_column_in_table
This will create a new migration file in db/migration directory (if it doesn’t exist already), which will contain the file prefixed with timestamp and migration file name w...
Let's use *norm as an example. From the documentation:
dnorm(x, mean = 0, sd = 1, log = FALSE)
pnorm(q, mean = 0, sd = 1, lower.tail = TRUE, log.p = FALSE)
qnorm(p, mean = 0, sd = 1, lower.tail = TRUE, log.p = FALSE)
rnorm(n, mean = 0, sd = 1)
So if I wanted to know the value of a standard no...
When Flash makes a request for data from an external source, that operation is asynchronous. The most basic explanation of what this means is that the data loads "in the background" and triggers the event handler you allocate to Event.COMPLETE when it is received. This can happen at any po...