Signup/Sign In

Answers

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

This can now be done in Chrome, Safari, Firefox 4+, and Internet Explorer 10pp4+!
See this question's answer for more information: **Updating address bar with new URL without hash or reloading the page**
Example:
***function processAjaxData(response, urlPath){
document.getElementById("content").innerHTML = response.html;
document.title = response.pageTitle;
window.history.pushState({"html":response.html,"pageTitle":response.pageTitle},"", urlPath);
}***
You can then use **window.onpopstate** to detect the back/forward button navigation:
***window.onpopstate = function(e){
if(e.state){
document.getElementById("content").innerHTML = e.state.html;
document.title = e.state.pageTitle;
}
};***
3 years ago
You can force Android to hide the virtual keyboard using the **InputMethodManager**, calling **hideSoftInputFromWindow**, passing in the token of the window containing your focused view.

***// Check if no view has focus:
View view = this.getCurrentFocus();
if (view != null) {
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}***
This will force the keyboard to be hidden in all situations. In some cases, you will want to pass in **InputMethodManager.HIDE_IMPLICIT_ONLY** as the second parameter to ensure you only hide the keyboard when the user didn't explicitly force it to appear (by holding down the menu).
Note: If you want to do this in Kotlin, use:
**context?.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager**

Kotlin Syntax

**// Only runs if there is a view that is currently focused
this.currentFocus?.let { view ->
val imm = getSystemService(Context.INPUT_METHOD_SERVICE) as? InputMethodManager
imm?.hideSoftInputFromWindow(view.windowToken, 0)
}**
3 years ago
The **.tables**, and **.schema** "helper" functions don't look into ATTACHed databases: they just query the **SQLITE_MASTER** table for the "main" database. Consequently, if you used

**ATTACH some_file.db AS my_db;**
then you need to do

**SELECT name FROM my_db.sqlite_master WHERE type='table';**
Note that temporary tables don't show up with **.tables** either: you have to list **sqlite_temp_master** for that:

**SELECT name FROM sqlite_temp_master WHERE type='table';**
3 years ago
Try:
**INSERT INTO table1 ( column1 )
SELECT col1
FROM table2 **
This is standard ANSI SQL and should work on any DBMS
It definitely works for:
Oracle
MS SQL Server
MySQL
Postgres
SQLite v3
Teradata
DB2
Sybase
Vertica
HSQLDB
H2
AWS RedShift
SAP HANA
Google Spanner
3 years ago
If you look at the docs for **bytes**, it points you to **bytearray:**

***bytearray([source[, encoding[, errors]]])
Return a new array of bytes. The bytearray type is a mutable sequence of integers in the range 0 <= x < 256. It has most of the usual methods of mutable sequences, described in Mutable Sequence Types, as well as most methods that the bytes type has, see Bytes and Byte Array Methods.
The optional source parameter can be used to initialize the array in a few different ways:
If it is a string, you must also give the encoding (and optionally, errors) parameters; bytearray() then converts the string to bytes using str.encode().
If it is an integer, the array will have that size and will be initialized with null bytes.
If it is an object conforming to the buffer interface, a read-only buffer of the object will be used to initialize the bytes array.
If it is an iterable, it must be an iterable of integers in the range 0 <= x < 256, which are used as the initial contents of the array.
Without an argument, an array of size 0 is created.***

So bytes can do much more than just encode a string. It's Pythonic that it would allow you to call the constructor with any type of source parameter that makes sense.
For encoding a string, I think that **some_string.encode(encoding)** is more Pythonic than using the constructor, because it is the most self documenting -- "take this string and encode it with this encoding" is clearer than **bytes(some_string, encoding)** -- there is no explicit verb when you use the constructor.

Edit: Checked the Python source. If you pass a unicode string to **bytes** using CPython, it calls **PyUnicode_AsEncodedString**, which is the implementation of encode; so you're just skipping a level of indirection if you call **encode** yourself.
3 years ago
Try **list(newdict.keys()).**
This will convert the **dict_keys** object to a list.
On the other hand, you should ask yourself whether or not it matters. The Pythonic way to code is to assume duck typing (if it looks like a duck and it quacks like a duck, it's a duck). The **dict_keys** object will act like a list for most purposes. For instance:
***for key in newdict.keys():
print(key)***
Obviously, insertion operators may not work, but that doesn't make much sense for a list of dictionary keys anyway.
3 years ago
*require vs. include*
The difference between include and require arises when the file being included cannot be found: include will emit a warning ( E_WARNING ) and the script will continue, whereas require will emit a fatal error ( E_COMPILE_ERROR ) and halt the script.

**Use require when the file is required by the application.
Use include when the file is not required and application should continue when file is not found.**

*require_once vs. include_once*
include_once will throw a warning, but will not stop PHP from executing the rest of the script. require_once will throw an error and will stop PHP from executing the rest of the script.

**The include_once keyword is used to embed PHP code from another file. If the file is not found, a warning is shown and the program continues to run. If the file was already included previously, this statement will not include it again.
The require_once keyword is used to embed PHP code from another file. If the file is not found, a fatal error is thrown and the program stops. If the file was already included previously, this statement will not include it again.**
3 years ago
*You can try this basic approach:*
**div {
height: 100px;
line-height: 100px;
text-align: center;
border: 2px dashed #f69c55;
}

Hello World!

**
3 years ago
Either use a semi-transparent PNG image or use CSS 3:
**background-color: rgba(255, 0, 0, 0.5);**
Here's an article from css3.info, Opacity, RGBA and compromise (2007-06-03).
**


Hello, World!

**
3 years ago