Signup/Sign In

Answers

All questions must be answered. Here are the Answers given by this user in the Forum.

The minimal setup for an HTTPS server in Node.js would be something like this :
***
var https = require('https');
var fs = require('fs');

var httpsOptions = {
key: fs.readFileSync('path/to/server-key.pem'),
cert: fs.readFileSync('path/to/server-crt.pem')
};

var app = function (req, res) {
res.writeHead(200);
res.end("hello world\n");
}

https.createServer(httpsOptions, app).listen(4433);
***
If you also want to support http requests, you need to make just this small modification :
***
var http = require('http');
var https = require('https');
var fs = require('fs');

var httpsOptions = {
key: fs.readFileSync('path/to/server-key.pem'),
cert: fs.readFileSync('path/to/server-crt.pem')
};

var app = function (req, res) {
res.writeHead(200);
res.end("hello world\n");
}

http.createServer(app).listen(8888);
https.createServer(httpsOptions, app).listen(4433);
***
3 years ago
It also handles window resizing
***
constructor(props) {
super(props);
this.state = { width: 0, height: 0 };
this.updateWindowDimensions = this.updateWindowDimensions.bind(this);
}

componentDidMount() {
this.updateWindowDimensions();
window.addEventListener('resize', this.updateWindowDimensions);
}

componentWillUnmount() {
window.removeEventListener('resize', this.updateWindowDimensions);
}

updateWindowDimensions() {
this.setState({ width: window.innerWidth, height: window.innerHeight });
}
***
3 years ago
ou could use something like this. ReactDom is for react.14. Just React otherwise.
***
componentDidUpdate = () => { ReactDom.findDOMNode(this).scrollIntoView(); }
***
for React 16+
***
constructor(props) {
super(props)
this.childDiv = React.createRef()
}

componentDidMount = () => this.handleScroll()

componentDidUpdate = () => this.handleScroll()

handleScroll = () => {
const { index, selected } = this.props
if (index === selected) {
setTimeout(() => {
this.childDiv.current.scrollIntoView({ behavior: 'smooth' })
}, 500)
}
}
***
3 years ago
**event.target** gives you the native DOM node, then you need to use the regular DOM APIs to access attributes. Here are docs on how to do that:Using data attributes.

You can do either **event.target.dataset.tag** or **event.target.getAttribute('data-tag');** either one works.
3 years ago
You should pass the event object when calling the function :
***
{ this.toggle(e)}>Details}
***
If you don't need to handle onClick event you can also type :
***
{ this.toggle()}>Details}
***
Now you can also add your parameters within the function.
3 years ago
We can extend jQuery to make shortcuts for PUT and DELETE:
***
jQuery.each( [ "put", "delete" ], function( i, method ) {
jQuery[ method ] = function( url, data, callback, type ) {
if ( jQuery.isFunction( data ) ) {
type = type || callback;
callback = data;
data = undefined;
}

return jQuery.ajax({
url: url,
type: method,
dataType: type,
data: data,
success: callback
});
};
});
***
3 years ago
The .live() method is deprecated as of jQuery 1.7.



As of jQuery 1.7, the .live() method is deprecated. Use .on() to attach event handlers. Users of older versions of jQuery should use .delegate() in preference to .live().

For jQuery 1.7+ you can attach an event handler to a parent element using .on(), and pass the a selector combined with 'myclass' as an argument.



So instead of...
***
$(".myclass").click( function() {
// do something
});
***
You can write...
***
$('body').on('click', 'a.myclass', function() {
// do something
});
***
This will work for all a tags with 'myclass' in the body, whether already present or dynamically added later.

The body tag is used here as the example had no closer static surrounding tag, but any parent tag that exists when the .on method call occurs will work. For instance a ul tag for a list which will have dynamic elements added would look like this:
***
$('ul').on('click', 'li', function() {
alert( $(this).text() );
});
***
As long as the ul tag exists this will work (no li elements need to exist yet).
3 years ago
The way to accept license agreements from the command line has changed. You can use the SDK manager which is located at: $ANDROID_SDK_ROOT/tools/bin

e.g on linux:
***
cd ~/Library/Android/sdk/tools/bin/
***
Run the sdkmanager as follows:
***
./sdkmanager --licenses
***
e.g on Windows:
***
cd /d "%ANDROID_SDK_ROOT%/tools/bin"
***
Run the sdkmanager as follows:
***
sdkmanager --licenses
***
And accept the licenses you did not accept yet (but need to).

For more details see the Android Studio documentation, although the current documentation is missing any description on the --licenses option.

Warning
You might have two Android SDKs on your machine. Make sure to check both ** ~/Library/Android/sdk **and** /usr/local/share/android-sdk! **If unsure, fully uninstall Android Studio from your machine and start with a clean slate.

Update: ANDROID_HOME is deprecated, ANDROID_SDK_ROOT is now the correct variable
3 years ago
If you are using an ActionBarActivity then you can tell Android to use the Toolbar as the ActionBar like so:
***
Toolbar toolbar = (Toolbar) findViewById(R.id.my_awesome_toolbar);
setSupportActionBar(toolbar);
***
And then calls to
***
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
***
3 years ago
In Layout
***
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textCursorDrawable="@drawable/color_cursor"
/>
***
Then create drawalble xml: color_cursor
***





***
You have a white color cursor on the EditText property.
3 years ago
org.apache.http.impl.client.DefaultHttpClient comes in the Android SDK by default. That'll get you connected to the WSDL.
***
HttpClient httpClient = new DefaultHttpClient();
HttpContext localContext = new BasicHttpContext();
HttpGet httpGet = new HttpGet("example url" + URL);
HttpResponse response = httpClient.execute(httpGet, localContext);
***
3 years ago
You can check your g++ by command:
***
which g++
g++ --version
***
this will tell you which compiler is currently it is pointing.

To switch to g++ 4.7 (assuming that you have installed it in your machine),run:
***
sudo update-alternatives --config gcc
***
There are 2 choices for the alternative gcc (providing /usr/bin/gcc).
***
Selection Path Priority Status
------------------------------------------------------------
0 /usr/bin/gcc-4.6 60 auto mode
1 /usr/bin/gcc-4.6 60 manual mode
* 2 /usr/bin/gcc-4.7 40 manual mode
***
Then select 2 as selection(My machine already pointing to g++ 4.7,so the *)

Once you switch the complier then again run g++ --version to check the switching has happened correctly.

Now compile your program with
***
g++ -std=c++11 your_file.cpp -o main
***
3 years ago