Objects can be centered by using margin: 0 auto; if they are block elements and have a defined width.
HTML
<div class="containerDiv">
<div id="centeredDiv"></div>
</div>
<div class="containerDiv">
<p id="centeredPara...
The auto keyword by itself represents a value type, similar to int or char. It can be modified with the const keyword and the & symbol to represent a const type or a reference type, respectively. These modifiers can be combined.
In this example, s is a value type (its type will be inferred as s...
Lets use the same code as above for this example.
#include <iostream>
void fail() {
int *p1;
int *p2(NULL);
int *p3 = p1;
if (p3) {
std::cout << *p2 << std::endl;
}
}
int main() {
fail();
}
First lets compile it
g++ -g -o main m...
Some devices connected through a serial port send data to your program at a constant rate (streaming data) or send data at unpredictable intervals. You can configure the serial port to execute a function automatically to handle data whenever it arrives. This is called the "callback function&quo...
from bs4 import BeautifulSoup
import requests
# Use the requests module to obtain a page
res = requests.get('https://www.codechef.com/problems/easy')
# Create a BeautifulSoup object
page = BeautifulSoup(res.text, 'lxml') # the text field contains the source of the page
# Now use a CSS ...
When committing changes it is possible to specify that the commit will in future be squashed to another commit and this can be done like so,
git commit --squash=[commit hash of commit to which this commit will be squashed to]
One might also use, --fixup=[commit hash] alternatively to fixup.
It is...
If you want to clear your current Activity stack and launch a new Activity (for example, logging out of the app and launching a log in Activity), there appears to be two approaches.
1. Target (API >= 16)
Calling finishAffinity() from an Activity
2. Target (11 <= API < 16)
Intent intent ...
//Here self.webView is the view whose screenshot I need to take
//The screenshot is saved in jpg format in the application directory to avoid any loss of quality in retina display devices i.e. all current devices running iOS 10
UIGraphicsBeginImageContextWithOptions(self.webView.bounds.size, N...
ActiveRecord includes default_scope, to automatically scope a model by default.
class Post
default_scope ->{ where(published: true).order(created_at: :desc) }
end
The above code will serve posts which are already published when you perform any query on the model.
Post.all # will only lis...
Sometimes auto may behave not quite as was expected by a programmer. It type deduces the expression, even when type deduction is not the right thing to do.
As an example, when proxy objects are used in the code:
std::vector<bool> flags{true, true, false};
auto flag = flags[0];
flags.push_...
Suppose you want to prevent unauthorized users to access the page then you have to put barrier to them by authorizing access. We can do this by using spring-security which provides basic authentication by securing all HTTP end points. For that you need to add spring-security dependency to your proje...
git config --global help.autocorrect 17
This enables autocorrect in git and will forgive you for your minor mistakes (e.g. git stats instead of git status). The parameter you supply to help.autocorrect determines how long the system should wait, in tenths of a second, before automatically applyin...
Sometimes it may be useful to have a specific asBoolean definition in your own program for some kind of objects.
/** an oversimplified robot controller */
class RunController {
def complexCondition
int position = 0
def asBoolean() {
return complexCondition(this...
The following example will log all of your collection queries to the server console in realtime.
Meteor.startup(
function () {
var wrappedFind = Meteor.Collection.prototype.find;
// console.log('[startup] wrapping Collection.find')
Meteor.Collection.prot...
The using of net.sf.jasperreports.export.xls.auto.filter property allow to add autofilter in generated xls file.
<columnHeader>
<band height="30" splitType="Stretch">
<staticText>
<reportElement x="0" y="0" widt...
public static async Task<WriteableBitmap> RenderUIElement(UIElement element)
{
var bitmap = new RenderTargetBitmap();
await bitmap.RenderAsync(element);
var pixelBuffer = await bitmap.GetPixelsAsync();
var pixels = pixelBuffer.ToArray();
var writeableBitmap = new W...