qid int64 1 74.7M | question stringlengths 0 58.3k | date stringlengths 10 10 | metadata list | response_j stringlengths 2 48.3k | response_k stringlengths 2 40.5k |
|---|---|---|---|---|---|
61,982,866 | I'm wondering if it's possible to make a class object iterable in Python (ie. a subclass of `type`, NOT an instance of a class).
I've tried the following code:
```
class Foo:
@classmethod
def __iter__(cls):
yield 1
print(next(Foo.__iter__())) # prints 1
print(next(iter(Foo))) # TypeError: 'type' ob... | 2020/05/24 | [
"https://Stackoverflow.com/questions/61982866",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2650622/"
] | Turns out it's possible with metaclasses.
```
class Foo(type):
def __iter__(self):
yield self.baz
class Bar(metaclass=Foo):
baz = 1
print(type(Bar)) # prints "<class '__main__.Foo'>"
print(next(Bar.__iter__())) # prints "1"
print(next(iter(Bar))) # prints "1"
```
Thanks @DanielB for pointing me ... | This isn't possible, as it would imply that all `type` objects are iterable - as you stated, classes are of type `type`. The underlying reason for this is that the `__iter__` method is looked up on the type, not the value. E.g., in:
```
for i in Foo:
print(i)
```
Python will look up `type(Foo).__iter__`, not `Fo... |
9,480 | I hear phrases like
>
> I very almost fell over!
>
>
>
often and to me they sound awkward. Is the word, "very", wrong, just superfluous or completely valid? Should this wording be avoided? | 2011/01/21 | [
"https://english.stackexchange.com/questions/9480",
"https://english.stackexchange.com",
"https://english.stackexchange.com/users/3272/"
] | You can say
>
> "I very nearly fell over!"
>
>
>
but to say
>
> "I very almost fell over!"
>
>
>
will brand you as very nearly a beginning speaker of English. This is a bit harsh for English learners, since *nearly* and *almost* mean almost the same thing. But that's how it goes sometimes. | Consider the relevant definitions of the adverbs, *very* and *almost*, from the New Oxford American Dictionary (2nd Edition):
>
> * **very** — in a high degree
> * **almost** — not quite; very nearly
>
>
>
Now, it is standard to modify one adverb with another. Examples:
>
> * *very*: He dragged the chair very ... |
9,480 | I hear phrases like
>
> I very almost fell over!
>
>
>
often and to me they sound awkward. Is the word, "very", wrong, just superfluous or completely valid? Should this wording be avoided? | 2011/01/21 | [
"https://english.stackexchange.com/questions/9480",
"https://english.stackexchange.com",
"https://english.stackexchange.com/users/3272/"
] | You can say
>
> "I very nearly fell over!"
>
>
>
but to say
>
> "I very almost fell over!"
>
>
>
will brand you as very nearly a beginning speaker of English. This is a bit harsh for English learners, since *nearly* and *almost* mean almost the same thing. But that's how it goes sometimes. | I have never heard "very almost", and would find it odd.
Which makes me wonder if you are in another part of the world, where perhaps it is more common? |
9,480 | I hear phrases like
>
> I very almost fell over!
>
>
>
often and to me they sound awkward. Is the word, "very", wrong, just superfluous or completely valid? Should this wording be avoided? | 2011/01/21 | [
"https://english.stackexchange.com/questions/9480",
"https://english.stackexchange.com",
"https://english.stackexchange.com/users/3272/"
] | You can say
>
> "I very nearly fell over!"
>
>
>
but to say
>
> "I very almost fell over!"
>
>
>
will brand you as very nearly a beginning speaker of English. This is a bit harsh for English learners, since *nearly* and *almost* mean almost the same thing. But that's how it goes sometimes. | yes!! it is wrong to use "very almost" together. It may be accepted colloquially in informal conversations but it is not correct
In general "very" would add value to the noun/ action in question.
She runs very fast
i like her very much
He is very talented
"Almost" would more appropriately describe the "status" of t... |
9,480 | I hear phrases like
>
> I very almost fell over!
>
>
>
often and to me they sound awkward. Is the word, "very", wrong, just superfluous or completely valid? Should this wording be avoided? | 2011/01/21 | [
"https://english.stackexchange.com/questions/9480",
"https://english.stackexchange.com",
"https://english.stackexchange.com/users/3272/"
] | You can say
>
> "I very nearly fell over!"
>
>
>
but to say
>
> "I very almost fell over!"
>
>
>
will brand you as very nearly a beginning speaker of English. This is a bit harsh for English learners, since *nearly* and *almost* mean almost the same thing. But that's how it goes sometimes. | I would consider the use of 'very' as shown in these examples to be superfluous and redundant. Certainly the use of 'very almost' together not only sounds wrong but is grammatically incorrect. In the Oxford Advanced Learner's Dictionary which I use for my students, various examples are given; one has to be extremely ca... |
9,480 | I hear phrases like
>
> I very almost fell over!
>
>
>
often and to me they sound awkward. Is the word, "very", wrong, just superfluous or completely valid? Should this wording be avoided? | 2011/01/21 | [
"https://english.stackexchange.com/questions/9480",
"https://english.stackexchange.com",
"https://english.stackexchange.com/users/3272/"
] | Consider the relevant definitions of the adverbs, *very* and *almost*, from the New Oxford American Dictionary (2nd Edition):
>
> * **very** — in a high degree
> * **almost** — not quite; very nearly
>
>
>
Now, it is standard to modify one adverb with another. Examples:
>
> * *very*: He dragged the chair very ... | I have never heard "very almost", and would find it odd.
Which makes me wonder if you are in another part of the world, where perhaps it is more common? |
9,480 | I hear phrases like
>
> I very almost fell over!
>
>
>
often and to me they sound awkward. Is the word, "very", wrong, just superfluous or completely valid? Should this wording be avoided? | 2011/01/21 | [
"https://english.stackexchange.com/questions/9480",
"https://english.stackexchange.com",
"https://english.stackexchange.com/users/3272/"
] | Consider the relevant definitions of the adverbs, *very* and *almost*, from the New Oxford American Dictionary (2nd Edition):
>
> * **very** — in a high degree
> * **almost** — not quite; very nearly
>
>
>
Now, it is standard to modify one adverb with another. Examples:
>
> * *very*: He dragged the chair very ... | yes!! it is wrong to use "very almost" together. It may be accepted colloquially in informal conversations but it is not correct
In general "very" would add value to the noun/ action in question.
She runs very fast
i like her very much
He is very talented
"Almost" would more appropriately describe the "status" of t... |
9,480 | I hear phrases like
>
> I very almost fell over!
>
>
>
often and to me they sound awkward. Is the word, "very", wrong, just superfluous or completely valid? Should this wording be avoided? | 2011/01/21 | [
"https://english.stackexchange.com/questions/9480",
"https://english.stackexchange.com",
"https://english.stackexchange.com/users/3272/"
] | Consider the relevant definitions of the adverbs, *very* and *almost*, from the New Oxford American Dictionary (2nd Edition):
>
> * **very** — in a high degree
> * **almost** — not quite; very nearly
>
>
>
Now, it is standard to modify one adverb with another. Examples:
>
> * *very*: He dragged the chair very ... | I would consider the use of 'very' as shown in these examples to be superfluous and redundant. Certainly the use of 'very almost' together not only sounds wrong but is grammatically incorrect. In the Oxford Advanced Learner's Dictionary which I use for my students, various examples are given; one has to be extremely ca... |
144,769 | Is it normal to catch exception in concept of MVVM inside model? Or how should it be? How to improve this code?
This is simple application that allows user to drop .pfx certificate on the label. `LoginModel` checks the password for validity and check the publisher. if the validation fails throws an exception that is c... | 2016/10/20 | [
"https://codereview.stackexchange.com/questions/144769",
"https://codereview.stackexchange.com",
"https://codereview.stackexchange.com/users/88521/"
] | There is nothing inherently wrong with catching exceptions in viewmodel. The rule of the thumb is that you catch exceptions at level where you can handle them. Sometimes this level is viewmodel level.
That being said, exceptions should not be used to control flow. This topic is covered on the Internet pretty well. For... | No. ViewModel - as the name itself indicates - should only model the view. Business logic, such as validating a certificate, should be extracted to another class (a service), adhering to the Single Responsibility Principle. This includes handling any errors that occur. Extract `CheckUserCertificate` elsewhere. |
37,665,308 | I have some strings that I have extracted using protractor/jasmine/angularJS and converted into integers. I am now trying to add these together and compare in an expect statement. But I am getting some promise errors in doing so.
```
var result0 = element.all(by.binding('Inboxes.Inbox.Count')).first().getText().then(... | 2016/06/06 | [
"https://Stackoverflow.com/questions/37665308",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2347816/"
] | You are *trying to add promises together, not actual resolved values*.
In this case, I would solve that using the `protractor.promise.all()` to resolve all the promises needed to make the expectation, at once:
```
protractor.promise.all([result0, result1, result2, result3]).then(function (values) {
expect(values[... | I would use `.map` to keep it simple and efficient:
```
var total = element(by.binding('Inboxes.Inbox.Count'))
.getText()
.then(parseInt);
element.all(by.binding('InboxItem.Count')) // get the elements
.map((e, i) => e.getText().then(parseInt)) // parse each text
.then((values) => { ... |
21,093 | In the *Supernatural* universe burying your photo with some hoodoo items at a crossroads summons a demon, said demon offers you a deal normally offers you a deal.
>
> "You can have that thing you wanted, and in exchange for your soul in ten years.
>
>
>
What if you die early? Does your soul go to hell anyway? Do ... | 2012/07/26 | [
"https://scifi.stackexchange.com/questions/21093",
"https://scifi.stackexchange.com",
"https://scifi.stackexchange.com/users/3804/"
] | Yes it happens in one episode. Crowley gets furious with a demon who had made this kind of deal. He actually says:
>
> *This isn't Wall Street, this is Hell. We have a little something called integrity.*
>
>
>
[Link to YouTube](http://www.youtube.com/watch?v=nNAvGfh-Uvg)
If the human who did the deal dies before... | The demons don't promise you'll live for 10 years, unless that's specifically part of the deal. But as can be seen in a recent episode, they strongly discourage their own from cheating and killing those with whom deals are made... it's considered bad for business. |
21,093 | In the *Supernatural* universe burying your photo with some hoodoo items at a crossroads summons a demon, said demon offers you a deal normally offers you a deal.
>
> "You can have that thing you wanted, and in exchange for your soul in ten years.
>
>
>
What if you die early? Does your soul go to hell anyway? Do ... | 2012/07/26 | [
"https://scifi.stackexchange.com/questions/21093",
"https://scifi.stackexchange.com",
"https://scifi.stackexchange.com/users/3804/"
] | The demons don't promise you'll live for 10 years, unless that's specifically part of the deal. But as can be seen in a recent episode, they strongly discourage their own from cheating and killing those with whom deals are made... it's considered bad for business. | They would be sent to Hell early if the demon holding their contract takes their soul. Most of the time that's the case.
But sometimes, however, if the deed the crossroads demon promised as part of the deal is not fulfilled and the owner of deal dies, then the soul would not be taken to Hell. |
21,093 | In the *Supernatural* universe burying your photo with some hoodoo items at a crossroads summons a demon, said demon offers you a deal normally offers you a deal.
>
> "You can have that thing you wanted, and in exchange for your soul in ten years.
>
>
>
What if you die early? Does your soul go to hell anyway? Do ... | 2012/07/26 | [
"https://scifi.stackexchange.com/questions/21093",
"https://scifi.stackexchange.com",
"https://scifi.stackexchange.com/users/3804/"
] | Yes it happens in one episode. Crowley gets furious with a demon who had made this kind of deal. He actually says:
>
> *This isn't Wall Street, this is Hell. We have a little something called integrity.*
>
>
>
[Link to YouTube](http://www.youtube.com/watch?v=nNAvGfh-Uvg)
If the human who did the deal dies before... | They would be sent to Hell early if the demon holding their contract takes their soul. Most of the time that's the case.
But sometimes, however, if the deed the crossroads demon promised as part of the deal is not fulfilled and the owner of deal dies, then the soul would not be taken to Hell. |
25,451,649 | I'm attempting to retrieve both email and phone via a single cursor described below. I'm using the `Email.CONTENT_URI`, hence I don't retrieve the phone number, so my `phoneColumn` is returning email. I tried using `Phone.CONTENT_URI` but it only returns a smaller subset of contacts (possibly because it only fetches on... | 2014/08/22 | [
"https://Stackoverflow.com/questions/25451649",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1649472/"
] | Please have a look [here](http://developer.android.com/reference/android/provider/ContactsContract.Data.html). You should find all the necessary examples for such kind of querying.
For an example, you can fetch all information of a contactId in this way:
```
Cursor data = context.getContentResolver().query(
Data.CO... | I have created this library to solve all your queries. It will only save contacts with at least one email or phone number. Also it will remove duplicates from emails and phone numbers from same contacts (created by 3rd party apps like whatsapp).
Please have a look at it.
Link : <https://github.com/raghavsatyadev/Cont... |
22,085,341 | You would think this would not be a common use case, but I create new `git` repos pretty frequently. Essentially, I have a shell script that stores the current branch into `$CURRENT_BRANCH` via:
```
#!/bin/sh -e
git rev-parse --is-inside-work-tree 2>/dev/null > /dev/null
git rev-parse --abbrev-ref HEAD
```
This work... | 2014/02/28 | [
"https://Stackoverflow.com/questions/22085341",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/454533/"
] | In an empty repo, `HEAD` is attached to a branch that doesn't exist, so `git rev-parse` can't get a rev [that explanation isn't necessarily what causes the code to complain]. But `git symbolic-ref` doesn't ever care about the SHA, so
```
git symbolic-ref -q --short HEAD || echo HEAD
```
with an attached `HEAD` won't... | Why not using the `__git_ps1` command?
It was initially made to add these kind of information to PS1, nut you can use it from prompt as well.
I'm using this to show the current git branch in my prompt:
```
PS1="\$(__git_ps1 '(%s) ')${PS1}"
```
Just call this to print the current branch:
```
__git_ps1 '%s\n'
``... |
22,085,341 | You would think this would not be a common use case, but I create new `git` repos pretty frequently. Essentially, I have a shell script that stores the current branch into `$CURRENT_BRANCH` via:
```
#!/bin/sh -e
git rev-parse --is-inside-work-tree 2>/dev/null > /dev/null
git rev-parse --abbrev-ref HEAD
```
This work... | 2014/02/28 | [
"https://Stackoverflow.com/questions/22085341",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/454533/"
] | In an empty repo, `HEAD` is attached to a branch that doesn't exist, so `git rev-parse` can't get a rev [that explanation isn't necessarily what causes the code to complain]. But `git symbolic-ref` doesn't ever care about the SHA, so
```
git symbolic-ref -q --short HEAD || echo HEAD
```
with an attached `HEAD` won't... | What kind of repository you have created ? Is it a bare repository and is it that you are running these commands in the bare repository? Does running "git branch" show you any branch ?
In a bare repository, it won't fetch you any useful information and is not advisable to run any direct operation in it.Ideally, I woul... |
54,958,793 | I am trying to **REPLACE** some values on a certain column in my data set.
\*(*Notice the presence of NaN entries)*
**Column**: `Name`
**Values**:
```
OLIVER
HARRY
OLIVER
NaN
HARRY
NaN
```
By performing the following:
```
df['Name'] = 'User' + pd.Series(pd.factorize(df['Name'])[0] + 1).astype(str)
```
I get... | 2019/03/02 | [
"https://Stackoverflow.com/questions/54958793",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10224063/"
] | How about
```
import numpy as np
df['Name'] = np.where(df['Name'].isna(), df['Name'],'User' + pd.Series(pd.factorize(df['Name'])[0] + 1).astype(str))
```
This will not replace the `nan`-entries but simply leave them as they were.
Basically the `where`function takes an array of boolean values, in this case `df['Na... | An alternative is to create a dict from your `Name` column and map it:
```
names = {n:"User{}".format(i) for i, n in enumerate(df["Name"].unique())}
df["Name"] = df["Name"].map(names)
``` |
21,528,960 | I am reading a section about closures in a JS book, and reached an example in the section showing 'getter/Stetter' functions...
```
var getValue, setValue;
(function (){
var secret = 0;
getValue = function(){
return secret;
}
setValue = function(v){
secret = v;
}
})();
setValue(5);
get... | 2014/02/03 | [
"https://Stackoverflow.com/questions/21528960",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1315857/"
] | >
> Why is the 'secret' variable not global?
>
>
>
Because it is declared using `var`.
```
var secret = 0;
```
>
> I thought omitting 'var' made variables global?
>
>
>
One use of `var` in a function will make all variables declared in that statement local. | Because it's defined within `(function() { ... })`. If you want to make it global, declare it alongside your `getValue` and `setValue`.
The `var` keyword simply declares a variable, it doesn't make it global:
```
var secret = "Global"; // Global variable declaration
function myFunction() {
var secret; ... |
21,528,960 | I am reading a section about closures in a JS book, and reached an example in the section showing 'getter/Stetter' functions...
```
var getValue, setValue;
(function (){
var secret = 0;
getValue = function(){
return secret;
}
setValue = function(v){
secret = v;
}
})();
setValue(5);
get... | 2014/02/03 | [
"https://Stackoverflow.com/questions/21528960",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1315857/"
] | Why isn't it global?
====================
Javascript has [functional scope](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions_and_function_scope), so the `secret` variable exists only within the scope of the function.
```
var iAmGlobal = true;
iAmGlobalToo = true; // no var made this an impl... | Because it's defined within `(function() { ... })`. If you want to make it global, declare it alongside your `getValue` and `setValue`.
The `var` keyword simply declares a variable, it doesn't make it global:
```
var secret = "Global"; // Global variable declaration
function myFunction() {
var secret; ... |
19,707,961 | i'm create a little site like a app store page, and cant align all elements in the middle of div .game-dark
```
<div class="row">
<div class="game-dark col-lg-12 col-md-12 col-sm-12 col-xs-12">
<div class="number col-lg-1 col-md-1 col-sm-1 col-xs-1">
<p>1</p>
</div>
<div class="col-lg-... | 2013/10/31 | [
"https://Stackoverflow.com/questions/19707961",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2652888/"
] | Maybe I asked in the wrong place, however (for those who will make a similar search) I post the answer I found from another part: <https://serverfault.com/questions/549961/ldap-distinguished-name-validator> | LDAP C API has a function for DN parsing that is called `ldap_explode_dn`. There are also many bindings for different languages (PHP, python, etc.). I suggest you consider using this API as a DN validation tool. |
78,558 | My setup is a Qwest PK5000 router with a Linksys router running Tomato.
I have DMZ pointed towards my router. (The server is on the tomato router).
I tried my applications that open up sockets and Utorrent (port 6883)
and I ended having to do advanced port forwarding and forward specific ports in addition to having D... | 2009/10/27 | [
"https://serverfault.com/questions/78558",
"https://serverfault.com",
"https://serverfault.com/users/24088/"
] | I don't think scp alone can do what you ask. You should investigate rsync instead.
I use it for backups with a filter to exclude files with names that don't work on NTFS volumes
```
# the exclude is to filter out files with invalid names on NTFS
/usr/bin/rsync -rgqoxD --delete --exclude='*[:\?]*' /home/andrewr/src /f... | If you already have pre-shared ssh keys, you could first create all the remote directories in the following way:
```
# get all directories in this tree
for DIR in `find . -type d`
do
# create remote directory
ssh user@host mkdir -p /path/to/start/$DIR
# copy *only* *.htm files
scp $... |
613,361 | I'm trying to understand the reason why USB and PCIe (considering a single lane) can achieve higher data rates than e.g. SPI, I2C, UART.
The reason may be the better handling of signal impairments at PHY level, so it can work at higher clock rates.
Furthermore, sometimes USB and PCIe are referred as analog serial int... | 2022/03/25 | [
"https://electronics.stackexchange.com/questions/613361",
"https://electronics.stackexchange.com",
"https://electronics.stackexchange.com/users/310074/"
] | There's a number of improvements that need to be made to get from the MHz of SPI/I2C to the GHz of PCIe/SATA/HDMI.
The low speed interfaces assume full-swing logic level signals. When the speed becomes too high for the medium to maintain a good pulse shape, they give up. The high speed signals are small swing and assu... | All interfaces do "require" a PHY. This is nearly a matter of definition. To move from low-level microscopic-size internal digital domain to a heavy-loaded long wires/board traces always require some sort of a DIFFERENT set of transistors inside a IC. In simple protocols they are usually called "driver". Just some inte... |
41,852,861 | I'm having hard time saving some polish characters like 'Ł' to a ascii file.
```
const fs = require('fs');
fs.writeFileSync('ascii.txt','Ł','ascii');
```
I would like the output file to show 'Ł' character.
I tried buffers etc no luck.
Can't figure out how to do this. | 2017/01/25 | [
"https://Stackoverflow.com/questions/41852861",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7038028/"
] | It is not possible.
Neither characters are part of the [ASCII standard](https://en.wikipedia.org/wiki/ASCII).
To save such characters to a file, you need to encode the file with a different encoding, such as [UTF-8](https://en.wikipedia.org/wiki/UTF-8). | ASCII does not have polish characters. See here:
[ASCII TABLE](http://www.asciitable.com/) |
10,361,414 | I have this XML fragment:
```
<svrl:successful-report test="."
location="/*[local-name()='ClinicalDocument']/*[local-name()='component']/*[local-name()='structuredBody']/*[local-name()='component'][1]/*[local-name()='section']">
```
I want to get the value `@location` and remove the special characters `" *[local-nam... | 2012/04/28 | [
"https://Stackoverflow.com/questions/10361414",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1021885/"
] | Few things to try...
First:
```
apachectl -t -D DUMP_MODULES | grep php
```
You should get something like:
```
php5_module (shared)
```
at the very least.
Secondly... how are you restarting apache? Are you sure it is getting killed? I have used an apache init.d script before that would actually run an `apache... | Remove the Rewrite setting might be you have return wrong.
And restart the Apache server. Hope that will resolve the issue.
Can refer to
<http://www.matthewwittering.co.uk/blog/ubuntu-tips/apache-not-running-php-files.htm>
<https://askubuntu.com/questions/59272/php-not-working-in-apache2-after-system-upgrade>
```
... |
10,361,414 | I have this XML fragment:
```
<svrl:successful-report test="."
location="/*[local-name()='ClinicalDocument']/*[local-name()='component']/*[local-name()='structuredBody']/*[local-name()='component'][1]/*[local-name()='section']">
```
I want to get the value `@location` and remove the special characters `" *[local-nam... | 2012/04/28 | [
"https://Stackoverflow.com/questions/10361414",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1021885/"
] | Few things to try...
First:
```
apachectl -t -D DUMP_MODULES | grep php
```
You should get something like:
```
php5_module (shared)
```
at the very least.
Secondly... how are you restarting apache? Are you sure it is getting killed? I have used an apache init.d script before that would actually run an `apache... | check:
* that PHP files have their executable bit set
* that "index.php" is set as one of default index files in your web
root
* that php module is loaded by apache (see apache config file, perhaps
near by enabling mod\_rewrite module) |
21,205,878 | I have a table for categories with "order" column for ordering the categories.
I'm trying to set order incrementally in trigger before insert:
```
CREATE TRIGGER `categories_set_order` BEFORE INSERT ON `categories` FOR EACH ROW BEGIN
DECLARE max_order INT DEFAULT 0;
SELECT MAX(categories.order) INTO max_order ... | 2014/01/18 | [
"https://Stackoverflow.com/questions/21205878",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/497132/"
] | You need to change the delimiter. Otherwise the DB thinks your trigger definition ends at the first `;` which would be incomplete.
Also remove the `BEGIN` from your `IF` statement and add use `END IF` to end your `IF`
```
**delimiter |**
CREATE TRIGGER `categories_set_order` BEFORE INSERT ON `categories`
FOR EACH R... | Besides delimiter you need an END IF
```
DELIMITER //
CREATE TRIGGER `categories_set_order` BEFORE INSERT ON `categories` FOR EACH ROW BEGIN
DECLARE max_order INT DEFAULT 0;
SELECT MAX(categories.order) INTO max_order FROM categories;
IF (ISNULL(@max_order)) THEN
SET max_order = 0;
END IF; ... |
52,558,214 | In a project I am working at, I have found a class which wraps all methods of its super-class in some elaborate exception handling. It looks similar to that:
```
public void method1() throws ExceptionA {
String exceptionString = "";
try {
super.method1();
} catch (ExceptionA e) {
exception... | 2018/09/28 | [
"https://Stackoverflow.com/questions/52558214",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3052438/"
] | When you expand your interface to use two type variables, i.e.
```
private static interface ThrowingMethod<E1 extends Exception,E2 extends Exception> {
void run() throws E1, E2;
}
public <E1 extends Exception,E2 extends Exception>
void wrapMethod(ThrowingMethod<E1,E2> method) throws E1,E2 {
// same as before
... | So your goal is just to wrap a bunch of methods with logging? A typical way to handle this is with [AOP](https://en.wikipedia.org/wiki/Aspect-oriented_programming). You'd just create a single pointcut that matches all those methods, and you wouldn't have a bunch of repeated boilerplate. No need for those interfaces or ... |
43,115,791 | When importing my .txt file, I am getting the following error:
```
Can't convert 'int' object to str implicitly
```
I import my .txt file as follows:
```
activityHeaders = ['Type', 'AccountID', 'ConID', 'SecurityID', 'Symbol', 'BBTicker', 'Currency', 'BaseCurrency', 'TradeDate', 'SettleDate', 'TransactionType', 'Qu... | 2017/03/30 | [
"https://Stackoverflow.com/questions/43115791",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4262057/"
] | You need change `header` to `names` if need column names by list `activityHeaders`.
```
df = pd.read_csv(StringIO(temp), names=activityHeaders, skiprows=1, error_bad_lines=False)
print (df)
Type AccountID ConID SecurityID Symbol BBTicker Currency \
D I000000 NaN NaN NaN Na... | Drop the headers parameter altogether. `headers` is used as an integer list to tell pandas which row(s) to use as your header.
Change to `skiprows=[0]` and you should be good. |
43,678,486 | Say I have a JSON like this:
```
{
"99999":{
"success":true,
"data":{
"type":"blob",
"name":"random"
}
}
}
```
How do I access the "name", where the "99999" will be different each time? | 2017/04/28 | [
"https://Stackoverflow.com/questions/43678486",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1741251/"
] | you can use below code with JSON.parse.
```
var jsondata = '{"99999":{"success":true,"data":
{"type":"blob","name":"random"}}}';
$.each(JSON.parse(jsondata), function(idx, obj) {
console.log(obj.data.name);
});
``` | Use this in your callback function (json is the json object not a string) :
```
function(json){
$.each(json,function(index,val){
var success=val.success;
var name=val.data.name;
//index = 99999 in your example
}
}
``` |
43,678,486 | Say I have a JSON like this:
```
{
"99999":{
"success":true,
"data":{
"type":"blob",
"name":"random"
}
}
}
```
How do I access the "name", where the "99999" will be different each time? | 2017/04/28 | [
"https://Stackoverflow.com/questions/43678486",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1741251/"
] | you can use below code with JSON.parse.
```
var jsondata = '{"99999":{"success":true,"data":
{"type":"blob","name":"random"}}}';
$.each(JSON.parse(jsondata), function(idx, obj) {
console.log(obj.data.name);
});
``` | **Using JavaScript :**
```js
var jsonObj = {
"99999":{
"success":true,
"data":{
"type":"blob",
"name":"random"
}
}
};
var result = Object.keys(jsonObj).map(item => {return jsonObj[item].data.name});
console.log(result[0]);
```
... |
1,726,575 | $$t\_0=-5, t\_1=\frac{11}{5} $$
$$t\_n=1-\frac{2}{t\_{n-1}} + \frac{-4}{t\_{n-2}\*t\_{n-1}} $$
I have never seen so uncommon formula for recurrence like this before. I have no idea how to solve it. Please, can anyone help me ? | 2016/04/03 | [
"https://math.stackexchange.com/questions/1726575",
"https://math.stackexchange.com",
"https://math.stackexchange.com/users/326310/"
] | The recurrence can be re-written as $t\_n t\_{n-1} t\_{n-2} = t\_{n-1}t\_{n-2} - 2t\_{n-2} -4$.
Let $x\_n = t\_0 t\_1 t\_2 \dotsb t\_n$. Then
$$\frac{x\_n}{x\_{n-3}} = \frac{x\_{n-1}}{x\_{n-3}} - 2\frac{x\_{n-2}}{x\_{n-3}} -4$$
Hence $x\_{n} = x\_{n-1} - 2x\_{n-2} - 4x\_{n-3}$ and $x\_0 = -5$, $x\_1 = -11$, $x\_2 = -... | I propose a solution utilizing the very interesting auxiliary sequence called $x\_n$ introduced by @Catalin Zara, verifying
$$x\_{n} = x\_{n-1} - 2x\_{n-2} - 4x\_{n-3}$$
The characteristic equation $r^3 - r^2 + 2r + 4 = 0$ of this recurrence relationship has the following roots $r=-1$, $r=1\pm i \sqrt{3}$.
Therefore... |
2,855,609 | Note that $X$ is a metric space and $f:(X,\rho)\rightarrow (X,\sigma)$.
Disproving: Suppose $(x\_n)$ is a Cauchy sequence, $f$ is continuous and $(f(x\_n))$ is not a Cauchy sequence, then $\exists\epsilon'>0$ such that $\forall M\in\Bbb{N}$, there exists $i,j\geq M$ where $\sigma(f(x\_i),f(x\_j))>\epsilon'$. Also, kno... | 2018/07/18 | [
"https://math.stackexchange.com/questions/2855609",
"https://math.stackexchange.com",
"https://math.stackexchange.com/users/378786/"
] | Take $$X=(0,+\infty)$$
$$x\_n=\frac 1 n$$
$$f:x\mapsto \frac{1}{x}$$
$$(x\_n) \text{ is Cauchy}$$
$$f \text{ is continuous}$$
$$f(x\_n)=n \text{ is not Cauchy}$$
Your statement will be true if $f$ is UNIFORMLY CONTINUOUS. | No, it is not correct. You start talking about $y$ without telling what $y$ is. But, above all, your approach only tells us why you think that the sequence $\bigl(f(x\_n)\bigr)\_{n\in\mathbb N}$ **might** not be a Cauchy sequence. The best approach, in this case, consists in providing a counterexample. |
2,855,609 | Note that $X$ is a metric space and $f:(X,\rho)\rightarrow (X,\sigma)$.
Disproving: Suppose $(x\_n)$ is a Cauchy sequence, $f$ is continuous and $(f(x\_n))$ is not a Cauchy sequence, then $\exists\epsilon'>0$ such that $\forall M\in\Bbb{N}$, there exists $i,j\geq M$ where $\sigma(f(x\_i),f(x\_j))>\epsilon'$. Also, kno... | 2018/07/18 | [
"https://math.stackexchange.com/questions/2855609",
"https://math.stackexchange.com",
"https://math.stackexchange.com/users/378786/"
] | Another counterexample that goes into a slightly different direction.
Choose $X=\mathbb Q$,
$$f(x)= \left\{
\begin{matrix}
0 & \text{, if } x < \sqrt{2}\\
1 & \text{, if } x > \sqrt{2}. \\
\end{matrix}
\right.
$$
This is a **continuous** function $\mathbb Q \to \mathbb Q$.
If you choose a sequence $\{x\_n\}$ of... | No, it is not correct. You start talking about $y$ without telling what $y$ is. But, above all, your approach only tells us why you think that the sequence $\bigl(f(x\_n)\bigr)\_{n\in\mathbb N}$ **might** not be a Cauchy sequence. The best approach, in this case, consists in providing a counterexample. |
41,613,331 | Hi sorry I've been stuck on this code for a while and both seem to work I just don't really understand the differences.
```
struct faveThings{
const char *favFood;
const char *faveFriend;
};
struct dog{
const char name[20];
const char breed[20];
int height;
int weight;
struct faveThings dogFaves;
};
... | 2017/01/12 | [
"https://Stackoverflow.com/questions/41613331",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | `favFood` doesn't hold a string. It points somewhere. And one can make it point to a character that is the first one *in* a string. By convention, since the c strings can have different length, they are terminated with a `'\0'` character. That way, even if all you have is a pointer to the first character, you can find ... | You're right that `const char *favFood;` does point to a single `char`, but it is understood that there will be a block of memory containing consecutive `char`s, and that pointer points to the first one. So the code can use that pointer to access all of the `char`s in the block.
The code that uses `favFood` will also ... |
41,613,331 | Hi sorry I've been stuck on this code for a while and both seem to work I just don't really understand the differences.
```
struct faveThings{
const char *favFood;
const char *faveFriend;
};
struct dog{
const char name[20];
const char breed[20];
int height;
int weight;
struct faveThings dogFaves;
};
... | 2017/01/12 | [
"https://Stackoverflow.com/questions/41613331",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | `favFood` doesn't hold a string. It points somewhere. And one can make it point to a character that is the first one *in* a string. By convention, since the c strings can have different length, they are terminated with a `'\0'` character. That way, even if all you have is a pointer to the first character, you can find ... | `const char *favFood[20]` is an array of pointers pointing towards a character data.
It's Like
```
*favFood[1] -------->MemLocation(0x001) = a
*favFood[2] -------->MemLocation(0x002) = b
```
and so on please take a look here also: [Can I create an Array of Char pointers in C?](https://stackoverflow.com/questions/9... |
41,613,331 | Hi sorry I've been stuck on this code for a while and both seem to work I just don't really understand the differences.
```
struct faveThings{
const char *favFood;
const char *faveFriend;
};
struct dog{
const char name[20];
const char breed[20];
int height;
int weight;
struct faveThings dogFaves;
};
... | 2017/01/12 | [
"https://Stackoverflow.com/questions/41613331",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | `favFood` doesn't hold a string. It points somewhere. And one can make it point to a character that is the first one *in* a string. By convention, since the c strings can have different length, they are terminated with a `'\0'` character. That way, even if all you have is a pointer to the first character, you can find ... | Below is an array of constant characters. It actually contains five elements, because the C language adds a '\0' at the end of the string delimited by the `"` symbols. In C, an array object, such as `MEAT` is actually a pointer to the first element of the array, so MEAT is actually a memory address not the entire array... |
41,613,331 | Hi sorry I've been stuck on this code for a while and both seem to work I just don't really understand the differences.
```
struct faveThings{
const char *favFood;
const char *faveFriend;
};
struct dog{
const char name[20];
const char breed[20];
int height;
int weight;
struct faveThings dogFaves;
};
... | 2017/01/12 | [
"https://Stackoverflow.com/questions/41613331",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | You're right that `const char *favFood;` does point to a single `char`, but it is understood that there will be a block of memory containing consecutive `char`s, and that pointer points to the first one. So the code can use that pointer to access all of the `char`s in the block.
The code that uses `favFood` will also ... | `const char *favFood[20]` is an array of pointers pointing towards a character data.
It's Like
```
*favFood[1] -------->MemLocation(0x001) = a
*favFood[2] -------->MemLocation(0x002) = b
```
and so on please take a look here also: [Can I create an Array of Char pointers in C?](https://stackoverflow.com/questions/9... |
41,613,331 | Hi sorry I've been stuck on this code for a while and both seem to work I just don't really understand the differences.
```
struct faveThings{
const char *favFood;
const char *faveFriend;
};
struct dog{
const char name[20];
const char breed[20];
int height;
int weight;
struct faveThings dogFaves;
};
... | 2017/01/12 | [
"https://Stackoverflow.com/questions/41613331",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | You're right that `const char *favFood;` does point to a single `char`, but it is understood that there will be a block of memory containing consecutive `char`s, and that pointer points to the first one. So the code can use that pointer to access all of the `char`s in the block.
The code that uses `favFood` will also ... | Below is an array of constant characters. It actually contains five elements, because the C language adds a '\0' at the end of the string delimited by the `"` symbols. In C, an array object, such as `MEAT` is actually a pointer to the first element of the array, so MEAT is actually a memory address not the entire array... |
11,950,628 | I have an array, that represents an inventory, with nearly 50 elements (items: some costum objects) and I need a readerwritelock for it (okay, i think a simple lock would be enough too). It should support both reference changing and value changing.
As reading and writing to different position of the array is threadsaf... | 2012/08/14 | [
"https://Stackoverflow.com/questions/11950628",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1021920/"
] | If you are *replacing* the references in the array, then this is already safe, since reference swaps are inherently atomic. So you can use:
```
var val = arr[index];
// now work with val
```
and
```
var newVal = ...
arr[index] = newVal;
```
perfectly safely, at least in terms of avoiding torn references. So one p... | First off, you may not need any locks. Reading and writing with an array of a type where the CPU would handle each read and write atomically, is in and of itself thread-safe (but you might want to put in a memory barrier to avoid stale reads).
That said, just like `x = 34` for an integer is threadsafe but `x++` is not... |
20,501,467 | All I want to do, is prompt a user for a yes or no answer, and validate this to ensure they haven't typed something stupid.
I thought this would be a relatively straight forward task, however after many failed attempts at it myself, and looking around online, it seems everyone has a different opinion on the best way t... | 2013/12/10 | [
"https://Stackoverflow.com/questions/20501467",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3001499/"
] | You are not returning the corrected `choice` from `validation()`:
```
void User::validation(std::string &choice) // <-- insert a & here
``` | C/C++ doesn't work like this for strings as the == operator isn't doing what you think it's doing for std::string objects and char\* arrays. Use the std::string compare() method instead. Reference: <http://www.cplusplus.com/reference/string/string/compare/> |
20,501,467 | All I want to do, is prompt a user for a yes or no answer, and validate this to ensure they haven't typed something stupid.
I thought this would be a relatively straight forward task, however after many failed attempts at it myself, and looking around online, it seems everyone has a different opinion on the best way t... | 2013/12/10 | [
"https://Stackoverflow.com/questions/20501467",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3001499/"
] | Try changing this
```
if (choice == "yes" && choice == "no")
```
For this
```
if (choice == "yes" || choice == "no")
```
Choice cannot be "yes" and "no" at the same time. | C/C++ doesn't work like this for strings as the == operator isn't doing what you think it's doing for std::string objects and char\* arrays. Use the std::string compare() method instead. Reference: <http://www.cplusplus.com/reference/string/string/compare/> |
20,501,467 | All I want to do, is prompt a user for a yes or no answer, and validate this to ensure they haven't typed something stupid.
I thought this would be a relatively straight forward task, however after many failed attempts at it myself, and looking around online, it seems everyone has a different opinion on the best way t... | 2013/12/10 | [
"https://Stackoverflow.com/questions/20501467",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3001499/"
] | You are not returning the corrected `choice` from `validation()`:
```
void User::validation(std::string &choice) // <-- insert a & here
``` | Try changing this
```
if (choice == "yes" && choice == "no")
```
For this
```
if (choice == "yes" || choice == "no")
```
Choice cannot be "yes" and "no" at the same time. |
49,915,693 | is it possible to insert a meta-tag robots->noindex in paginated pages of the list - not in the first but in all other?
typo3 8.7 - tx\_news 6.3.0
cu
Volker | 2018/04/19 | [
"https://Stackoverflow.com/questions/49915693",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3929464/"
] | the solution (for me) is to insert
```
<f:if condition="{pagination.current}>=2">
{v:page.header.meta(name: 'robots', content: 'NOINDEX,FOLLOW')}
</f:if>
```
into viewhelpers/widget/paginate/index.html
vhs-extension is allready installed.
cu
Volker | You can try to fetch the page GET params and build an condition of it:
```
[globalVar = GP:tx_news_pi1|@widget_0|currentPage > 1]
page.meta.robots = noindex
[GLOBAL]
```
Please watch at the zero of `@widget_0`. Normaly this should 0 but if you have configured another widget id you have the change the condition |
49,915,693 | is it possible to insert a meta-tag robots->noindex in paginated pages of the list - not in the first but in all other?
typo3 8.7 - tx\_news 6.3.0
cu
Volker | 2018/04/19 | [
"https://Stackoverflow.com/questions/49915693",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3929464/"
] | To modify the `<head/>` content you should install `vhs` extension which provides useful viewhelpers, also to manipulate the `<head/>` content.
VHS extension: <https://extensions.typo3.org/extension/vhs/>
VHS docs: <https://fluidtypo3.org/viewhelpers/vhs/master.html>
There you will find also how can you add this vie... | You can try to fetch the page GET params and build an condition of it:
```
[globalVar = GP:tx_news_pi1|@widget_0|currentPage > 1]
page.meta.robots = noindex
[GLOBAL]
```
Please watch at the zero of `@widget_0`. Normaly this should 0 but if you have configured another widget id you have the change the condition |
49,915,693 | is it possible to insert a meta-tag robots->noindex in paginated pages of the list - not in the first but in all other?
typo3 8.7 - tx\_news 6.3.0
cu
Volker | 2018/04/19 | [
"https://Stackoverflow.com/questions/49915693",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3929464/"
] | the solution (for me) is to insert
```
<f:if condition="{pagination.current}>=2">
{v:page.header.meta(name: 'robots', content: 'NOINDEX,FOLLOW')}
</f:if>
```
into viewhelpers/widget/paginate/index.html
vhs-extension is allready installed.
cu
Volker | To modify the `<head/>` content you should install `vhs` extension which provides useful viewhelpers, also to manipulate the `<head/>` content.
VHS extension: <https://extensions.typo3.org/extension/vhs/>
VHS docs: <https://fluidtypo3.org/viewhelpers/vhs/master.html>
There you will find also how can you add this vie... |
184,218 | Can a [swashbuckler](https://www.d20pfsrd.com/classes/hybrid-classes/swashbuckler/) parry an attack from an invisible creature or creature they cannot see if they can make AOOs while flatfooted via [combat reflexes](https://www.d20pfsrd.com/feats/combat-feats/combat-reflexes-combat/) and have [blindfight](https://www.d... | 2021/04/22 | [
"https://rpg.stackexchange.com/questions/184218",
"https://rpg.stackexchange.com",
"https://rpg.stackexchange.com/users/32546/"
] | No.
===
**Can a swashbuckler parry an attack from an invisible creature, or creature they cannot see?**
Breaking it down/apart (at the request of Erudaki).
**Precondition:** Swashbuckler class is specifically mentioned to limit the scope of "parry" to the use of the class Deed "Opportune Parry and Riposte (Ex)" (OPa... | **Yes, he can...**
First of all the invisible condition is an effect that you GAIN not a malus that you APPLY to someone else:
>
> Invisible: Invisible creatures are visually undetectable. An invisible creature gains a +2 bonus on attack rolls against a sighted opponent, and ignores its opponent’s Dexterity bonus to... |
58,450,364 | I need to serialize a c# object into xml, i could do it as in formatted section, but can we achieve it without formatting that has no indentation/extra spaces/new lines. This is required as we need to write the whole object into a csv, so we need a minified version. I tried couple of XmlWriterSettings, but it did not w... | 2019/10/18 | [
"https://Stackoverflow.com/questions/58450364",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2714882/"
] | I finally managed to fix the problem. I will post this for anyone who runs into this issue.
**What the underlying problem was?**
The problem is that although laptop and macbook and some phone browsers allow you to create multiple webcams, the browsers on iphone, don't.
**What I did to solve this problem?**
What I did... | ```
import 'zone.js/dist/zone-patch-user-media';
import 'zone.js/dist/webapis-rtc-peer-connection';
```
These polyfills solved my problem. |
30,519,036 | In Lucene.Net how do I retrive a single Document based on a Field value? The Field value will always be unique to a single document in this case.
The Field I wish to use is "Id" from this is the structure of my document:
```
var doc = new Document();
// Add lucene fields mapped to DB fields
doc.Add(new Field("Id", s... | 2015/05/29 | [
"https://Stackoverflow.com/questions/30519036",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/250254/"
] | I advise you to check the documentation on [PDO](http://php.net/manual/fr/class.pdo.php) and [PDOStatement](http://php.net/manual/fr/class.pdostatement.php) for more detailed information.
I guess you're already connected to your database through PDO ? (else see PDO::\_\_construct())
With a prepared query you better ... | The point of PDO is to prevent concatenating the query string like you're currently doing. It's supposed to be used used to prepare the statements.
```
$sthandler = $conn->prepare('SELECT userid FROM users WHERE userid= :user_id');
if($sthandler->execute(array(':user_id' => $user_id))) {
if($sthandler->rowCount() ... |
20,874,229 | In my application when i click the add button and after i enter the values and try to save the object in the database its been persisted as a null value with no error message in the log file.The primary key is generated from a sequence i am just entering the name value. Here is the code of the jsf page
```
... | 2014/01/01 | [
"https://Stackoverflow.com/questions/20874229",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2388381/"
] | I thought that at some point Rails was smart enough replacing middleware code at runtime, but I may be wrong.
Here is what I came up with, circumventing Ruby class loading craziness and leveraging Rails class reloading.
Add the middleware to the stack:
```
# config/environments/development.rb
[...]
config.middleware... | Can you not simply use [shotgun](https://github.com/rtomayko/shotgun)? If I understand your question you want to ensure the environment reloads on every change you make to your code. That is what shotgun will do. |
20,874,229 | In my application when i click the add button and after i enter the values and try to save the object in the database its been persisted as a null value with no error message in the log file.The primary key is generated from a sequence i am just entering the name value. Here is the code of the jsf page
```
... | 2014/01/01 | [
"https://Stackoverflow.com/questions/20874229",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2388381/"
] | Building up on @phoet's answer we can actually wrap any middleware with this kind of lazy loading, which I found even more useful:
```
class ReloadableMiddleware
def initialize(app, middleware_module_name, *middleware_args)
@app = app
@name = middleware_module_name
@args = middleware_args
end
def ca... | Can you not simply use [shotgun](https://github.com/rtomayko/shotgun)? If I understand your question you want to ensure the environment reloads on every change you make to your code. That is what shotgun will do. |
20,874,229 | In my application when i click the add button and after i enter the values and try to save the object in the database its been persisted as a null value with no error message in the log file.The primary key is generated from a sequence i am just entering the name value. Here is the code of the jsf page
```
... | 2014/01/01 | [
"https://Stackoverflow.com/questions/20874229",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2388381/"
] | In Rails 6 with the new default Zeitwork code loader, this works for me:
```
# at the top of config/application.rb, after Bundler.require
# Load the middleware. It will later be hot-reloaded in config.to_prepare
Dir["./app/middleware/*.rb"].each do |middleware|
load middleware
end
```
Below it in the section ... | Can you not simply use [shotgun](https://github.com/rtomayko/shotgun)? If I understand your question you want to ensure the environment reloads on every change you make to your code. That is what shotgun will do. |
20,874,229 | In my application when i click the add button and after i enter the values and try to save the object in the database its been persisted as a null value with no error message in the log file.The primary key is generated from a sequence i am just entering the name value. Here is the code of the jsf page
```
... | 2014/01/01 | [
"https://Stackoverflow.com/questions/20874229",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2388381/"
] | I thought that at some point Rails was smart enough replacing middleware code at runtime, but I may be wrong.
Here is what I came up with, circumventing Ruby class loading craziness and leveraging Rails class reloading.
Add the middleware to the stack:
```
# config/environments/development.rb
[...]
config.middleware... | Building up on @phoet's answer we can actually wrap any middleware with this kind of lazy loading, which I found even more useful:
```
class ReloadableMiddleware
def initialize(app, middleware_module_name, *middleware_args)
@app = app
@name = middleware_module_name
@args = middleware_args
end
def ca... |
20,874,229 | In my application when i click the add button and after i enter the values and try to save the object in the database its been persisted as a null value with no error message in the log file.The primary key is generated from a sequence i am just entering the name value. Here is the code of the jsf page
```
... | 2014/01/01 | [
"https://Stackoverflow.com/questions/20874229",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2388381/"
] | I thought that at some point Rails was smart enough replacing middleware code at runtime, but I may be wrong.
Here is what I came up with, circumventing Ruby class loading craziness and leveraging Rails class reloading.
Add the middleware to the stack:
```
# config/environments/development.rb
[...]
config.middleware... | In Rails 6 with the new default Zeitwork code loader, this works for me:
```
# at the top of config/application.rb, after Bundler.require
# Load the middleware. It will later be hot-reloaded in config.to_prepare
Dir["./app/middleware/*.rb"].each do |middleware|
load middleware
end
```
Below it in the section ... |
54,686,845 | Consider I have 1000 `.CSV` files with names of my employees. So there isn't any order or numbers in file names. Is there a way to say to the computer in Python language, that read files from first to end in a special folder, whit no matter what their name is?
(It's not important for me the data is for who, I only need... | 2019/02/14 | [
"https://Stackoverflow.com/questions/54686845",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3486308/"
] | You can read all csv files in a directory like this:
My csv:
```
col1,col2,col3
a,b,c
d,e,f
```
Code:
```
import glob
import csv
PATH = "/Users/stack/"
for file in glob.glob(PATH+"*.csv"):
with open(file) as csvfile:
spamreader = csv.reader(csvfile, delimiter=',')
for row in spamreader:
... | Yes you can. I would use a simple regex based tester to check the file and so essentially what you're doing is you are using a for loop to go through the directory and using the if-statement, we test the file to see if it contains '.csv'. After this we open the file and we simply append it to our output which you can e... |
54,686,845 | Consider I have 1000 `.CSV` files with names of my employees. So there isn't any order or numbers in file names. Is there a way to say to the computer in Python language, that read files from first to end in a special folder, whit no matter what their name is?
(It's not important for me the data is for who, I only need... | 2019/02/14 | [
"https://Stackoverflow.com/questions/54686845",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3486308/"
] | use code like:(replace current path (.) with your path:
```
import os, fnmatch
import csv
listOfFiles = os.listdir('.')
pattern = "*.csv"
for entry in listOfFiles:
if fnmatch.fnmatch(entry, pattern):
with open(entry, newline='') as csvfile:
spamreader = csv.reader(csvfile)
for... | You can read all csv files in a directory like this:
My csv:
```
col1,col2,col3
a,b,c
d,e,f
```
Code:
```
import glob
import csv
PATH = "/Users/stack/"
for file in glob.glob(PATH+"*.csv"):
with open(file) as csvfile:
spamreader = csv.reader(csvfile, delimiter=',')
for row in spamreader:
... |
54,686,845 | Consider I have 1000 `.CSV` files with names of my employees. So there isn't any order or numbers in file names. Is there a way to say to the computer in Python language, that read files from first to end in a special folder, whit no matter what their name is?
(It's not important for me the data is for who, I only need... | 2019/02/14 | [
"https://Stackoverflow.com/questions/54686845",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3486308/"
] | use code like:(replace current path (.) with your path:
```
import os, fnmatch
import csv
listOfFiles = os.listdir('.')
pattern = "*.csv"
for entry in listOfFiles:
if fnmatch.fnmatch(entry, pattern):
with open(entry, newline='') as csvfile:
spamreader = csv.reader(csvfile)
for... | Yes you can. I would use a simple regex based tester to check the file and so essentially what you're doing is you are using a for loop to go through the directory and using the if-statement, we test the file to see if it contains '.csv'. After this we open the file and we simply append it to our output which you can e... |
19,809,993 | I'm trying to manage a ruby script with **supervisord** but because I haven't fully understood how RVM works I have not been able to do it properly.
Normally I would just do the following:
```
# sourcing of rvm done automatically on ssh login
cd /var/rails/myapp
RAILS_ENV="production" bundle exec ./script/backgroundr... | 2013/11/06 | [
"https://Stackoverflow.com/questions/19809993",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/462707/"
] | Thanks to the suggestion of @mpapis I have been able to figure out something that works.
His suggestion unfortunately didn't, but he was right in the fact that I had to look in **/usr/local/rvm/wrappers**
This is the working config file:
```
[program:owgm]
directory=/var/rails/owgm
command=/usr/local/rvm/wrappers/re... | it should be:
```
PATH="/usr/local/rvm/wrappers/ree-1.8.7-2012.02@global:$PATH"
``` |
24,676,525 | when i was inserting the bitmap image to files directory, it showing file not found exception and it is showing Is a Directory.
Here is my code:
```
File mFolder = new File(getFilesDir() + "/sample");
if (!mFolder.exists()) {
mFolder.mkdir();
}
FileOut... | 2014/07/10 | [
"https://Stackoverflow.com/questions/24676525",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3777883/"
] | Use `file.createNewFile()` if you want to make a file and not a directory.
You may also need to use `mkDirs()` if the path doesn't exist either. | You are opening the directory itself for writing. This does not work. You need to specify a file within the directory, e.g.:
```
fos = new FileOutputStream(new File(mFolder, "myfile"));
``` |
24,676,525 | when i was inserting the bitmap image to files directory, it showing file not found exception and it is showing Is a Directory.
Here is my code:
```
File mFolder = new File(getFilesDir() + "/sample");
if (!mFolder.exists()) {
mFolder.mkdir();
}
FileOut... | 2014/07/10 | [
"https://Stackoverflow.com/questions/24676525",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3777883/"
] | you have to create file, before writing into stream.
```
File mFolder = new File(getFilesDir() + "/sample");
File imgFile = new File(mFolder.getAbsolutePath() + "/someimage.png");
if (!mFolder.exists()) {
mFolder.mkdir();
}
if (!imgFile.exists()) {
imgFile.createNewFile();
}
FileOutputStream fos = null;
try {
... | Use `file.createNewFile()` if you want to make a file and not a directory.
You may also need to use `mkDirs()` if the path doesn't exist either. |
24,676,525 | when i was inserting the bitmap image to files directory, it showing file not found exception and it is showing Is a Directory.
Here is my code:
```
File mFolder = new File(getFilesDir() + "/sample");
if (!mFolder.exists()) {
mFolder.mkdir();
}
FileOut... | 2014/07/10 | [
"https://Stackoverflow.com/questions/24676525",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3777883/"
] | Use `file.createNewFile()` if you want to make a file and not a directory.
You may also need to use `mkDirs()` if the path doesn't exist either. | ```
File sdcard = Environment.getExternalStorageDirectory();
File dir = new File(sdcard.getAbsolutePath() + "/text/");
dir.mkdir();
File file = new File(dir, "sample.txt");
FileOutputStream os = null;
try {
os = new FileOutputStream(file);
os.write(enterText.getText().toString().getBytes());
os.close();
}
c... |
24,676,525 | when i was inserting the bitmap image to files directory, it showing file not found exception and it is showing Is a Directory.
Here is my code:
```
File mFolder = new File(getFilesDir() + "/sample");
if (!mFolder.exists()) {
mFolder.mkdir();
}
FileOut... | 2014/07/10 | [
"https://Stackoverflow.com/questions/24676525",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3777883/"
] | you have to create file, before writing into stream.
```
File mFolder = new File(getFilesDir() + "/sample");
File imgFile = new File(mFolder.getAbsolutePath() + "/someimage.png");
if (!mFolder.exists()) {
mFolder.mkdir();
}
if (!imgFile.exists()) {
imgFile.createNewFile();
}
FileOutputStream fos = null;
try {
... | You are opening the directory itself for writing. This does not work. You need to specify a file within the directory, e.g.:
```
fos = new FileOutputStream(new File(mFolder, "myfile"));
``` |
24,676,525 | when i was inserting the bitmap image to files directory, it showing file not found exception and it is showing Is a Directory.
Here is my code:
```
File mFolder = new File(getFilesDir() + "/sample");
if (!mFolder.exists()) {
mFolder.mkdir();
}
FileOut... | 2014/07/10 | [
"https://Stackoverflow.com/questions/24676525",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3777883/"
] | You are opening the directory itself for writing. This does not work. You need to specify a file within the directory, e.g.:
```
fos = new FileOutputStream(new File(mFolder, "myfile"));
``` | ```
File sdcard = Environment.getExternalStorageDirectory();
File dir = new File(sdcard.getAbsolutePath() + "/text/");
dir.mkdir();
File file = new File(dir, "sample.txt");
FileOutputStream os = null;
try {
os = new FileOutputStream(file);
os.write(enterText.getText().toString().getBytes());
os.close();
}
c... |
24,676,525 | when i was inserting the bitmap image to files directory, it showing file not found exception and it is showing Is a Directory.
Here is my code:
```
File mFolder = new File(getFilesDir() + "/sample");
if (!mFolder.exists()) {
mFolder.mkdir();
}
FileOut... | 2014/07/10 | [
"https://Stackoverflow.com/questions/24676525",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3777883/"
] | you have to create file, before writing into stream.
```
File mFolder = new File(getFilesDir() + "/sample");
File imgFile = new File(mFolder.getAbsolutePath() + "/someimage.png");
if (!mFolder.exists()) {
mFolder.mkdir();
}
if (!imgFile.exists()) {
imgFile.createNewFile();
}
FileOutputStream fos = null;
try {
... | ```
File sdcard = Environment.getExternalStorageDirectory();
File dir = new File(sdcard.getAbsolutePath() + "/text/");
dir.mkdir();
File file = new File(dir, "sample.txt");
FileOutputStream os = null;
try {
os = new FileOutputStream(file);
os.write(enterText.getText().toString().getBytes());
os.close();
}
c... |
16,907,949 | I have these floating DIV boxes in which works perfectly. :)

but when the text extends more, I encounter this float problem.

How do I fill that ugly space thats' ruining my design? | 2013/06/04 | [
"https://Stackoverflow.com/questions/16907949",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2334332/"
] | This happens because floated elements fall out of the normal HTML document flow and default to this behaviour when some elements are taller than their siblings.
One way to solve this is to have fixed height elements. If they all have the same height this issue will not occur. This is not always practical, however, esp... | I would use the Vanilla Masonry plugin which won't rely on jQuery; <http://vanilla-masonry.desandro.com/> |
16,907,949 | I have these floating DIV boxes in which works perfectly. :)

but when the text extends more, I encounter this float problem.

How do I fill that ugly space thats' ruining my design? | 2013/06/04 | [
"https://Stackoverflow.com/questions/16907949",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2334332/"
] | This happens because floated elements fall out of the normal HTML document flow and default to this behaviour when some elements are taller than their siblings.
One way to solve this is to have fixed height elements. If they all have the same height this issue will not occur. This is not always practical, however, esp... | A non-JS solution for this is to use `display: inline-block; vertical-align: top;` instead of `float: left` on those boxes. That will make them all sit side by side and line up nicely, although there will be small gaps below any boxes that have a taller one beside them. `inline-block` will at least stop the float snagg... |
16,907,949 | I have these floating DIV boxes in which works perfectly. :)

but when the text extends more, I encounter this float problem.

How do I fill that ugly space thats' ruining my design? | 2013/06/04 | [
"https://Stackoverflow.com/questions/16907949",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2334332/"
] | I would use the Vanilla Masonry plugin which won't rely on jQuery; <http://vanilla-masonry.desandro.com/> | A non-JS solution for this is to use `display: inline-block; vertical-align: top;` instead of `float: left` on those boxes. That will make them all sit side by side and line up nicely, although there will be small gaps below any boxes that have a taller one beside them. `inline-block` will at least stop the float snagg... |
87,598 | Does `Stack up against` mean comparatively to level up in performance?
>
> Performance wise, junior students need to **stack up against** the seniors to set a high reputation.
>
>
>
Is it a correct construction? | 2016/04/16 | [
"https://ell.stackexchange.com/questions/87598",
"https://ell.stackexchange.com",
"https://ell.stackexchange.com/users/32576/"
] | I don't think that the idiom can be used in that way. Here are some examples:
>
> We wondered how London restaurants stacked up against Atlanta's.
>
>
> Their gift doesn't stack up against mine
>
>
> The new model of this car just doesn't stack up against previous models
>
>
>
The idiom refers to stacki... | If you took the original sentence,
>
> Performance wise, junior students need to **stack up against** the seniors to set a high reputation.
>
>
>
and replaced "stack up aganist" with this,
>
> Performance wise, junior students need to **compare to** the seniors to set a high reputation.
>
>
>
it would have ... |
53,788,898 | ```
setTimeout(function () {
console.log('timeout1')
}, 0);
setImmediate(function () {
console.log('immediate1')
});
new Promise(function (resolve, reject) {
console.log('promise1');
resolve()
}).then(function () {
console.log('then1');
setTimeout(function () {
console.log('timeout2')
... | 2018/12/15 | [
"https://Stackoverflow.com/questions/53788898",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5554036/"
] | The first few events with the promise and the synchronous code are normal and probably what you expect. (Code in the promise definition is fired synchronously, which seem surprising at first.) The difference between order of `setTimout()` with 0 delay and `setImmediate()` is is non-deterministic. This is documented her... | In Javascript the execution happens asynchronously, The event loop picks up the commands and runs it. This is as designed as and you can read it [here](https://developer.mozilla.org/en-US/docs/Web/JavaScript/EventLoop)
If you by chance want a particular order then you can use callbacks, promises or async/await.
If yo... |
10,411,416 | On updating to Kubuntu 12.04, and Emacs 24.1.50 - I can't access `/` folder in ecb's tree browser. When I try to get there, or just activate the ecb Emacs opens `*tramp/scpc C*` buffer and it says:
```
ssh: Could not resolve hostname C: Name or service not known
```
it was working fine before the update to Kubuntu ... | 2012/05/02 | [
"https://Stackoverflow.com/questions/10411416",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/788700/"
] | I am using Kubuntu 12.04 and ran into this same problem; don't know if it is specific to Kubuntu or 12.04 generally.
Somehow the "C:\nppdf32Log\debuglog.txt" file (http://askubuntu.com/questions/144408/what-is-the-file-c-nppdf32log-debuglog-txt) was being picked up by the internal ecb-filename-cache - I couldn't figu... | Weird, maybe it's reusing an old C:\ something in your old trammp file? also reading this [scpc link](http://www.gnu.org/software/tramp/#index-method-scpc-67) maybe your newly updated kubuntu doesn't support it? Try the command the link says to see if it works. Sounds more like a tramp issue than an ECB. |
10,411,416 | On updating to Kubuntu 12.04, and Emacs 24.1.50 - I can't access `/` folder in ecb's tree browser. When I try to get there, or just activate the ecb Emacs opens `*tramp/scpc C*` buffer and it says:
```
ssh: Could not resolve hostname C: Name or service not known
```
it was working fine before the update to Kubuntu ... | 2012/05/02 | [
"https://Stackoverflow.com/questions/10411416",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/788700/"
] | Weird, maybe it's reusing an old C:\ something in your old trammp file? also reading this [scpc link](http://www.gnu.org/software/tramp/#index-method-scpc-67) maybe your newly updated kubuntu doesn't support it? Try the command the link says to see if it works. Sounds more like a tramp issue than an ECB. | I ran into the same problem, and found that customizing the source path (as noted in [ECB First Steps](http://ecb.sourceforge.net/docs/First-steps.html)) fixed the problem for me. |
10,411,416 | On updating to Kubuntu 12.04, and Emacs 24.1.50 - I can't access `/` folder in ecb's tree browser. When I try to get there, or just activate the ecb Emacs opens `*tramp/scpc C*` buffer and it says:
```
ssh: Could not resolve hostname C: Name or service not known
```
it was working fine before the update to Kubuntu ... | 2012/05/02 | [
"https://Stackoverflow.com/questions/10411416",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/788700/"
] | I am using Kubuntu 12.04 and ran into this same problem; don't know if it is specific to Kubuntu or 12.04 generally.
Somehow the "C:\nppdf32Log\debuglog.txt" file (http://askubuntu.com/questions/144408/what-is-the-file-c-nppdf32log-debuglog-txt) was being picked up by the internal ecb-filename-cache - I couldn't figu... | I ran into the same problem, and found that customizing the source path (as noted in [ECB First Steps](http://ecb.sourceforge.net/docs/First-steps.html)) fixed the problem for me. |
617,544 | I'm trying to solve this problem: What is the quotient if we divide the LCM of the first 116 positive integers by the LCM of the first 113 positive integers?
Actually I thought if approaching it by going through the numbers one by one to find the LCMs, but it makes the problem too large. Will you please help me with ... | 2013/12/24 | [
"https://math.stackexchange.com/questions/617544",
"https://math.stackexchange.com",
"https://math.stackexchange.com/users/117546/"
] | I take "natural number" in your question to mean "positive integer" (which is not the standard usage in mathematics), since the LCM of any set containing $0$ is $0$, and the quotient of $0$ by $0$ is undefined. So you want:
$$ \frac{\operatorname{LCM}\{1,\dots,116\}}{\operatorname{LCM}\{1,\dots,113\}} $$
Let $X$ deno... | I find the answer to be 1. Since the LCM of the first 113 natural numbers is also a multiple of the remaining three: 114, 115, and 116 (why ?) |
26,880,623 | I have a Xamdatagrid having hierarchical data.I want to display all such records expended automatically.So that user doesn't have to click on + icon for each record. | 2014/11/12 | [
"https://Stackoverflow.com/questions/26880623",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3181491/"
] | You can handle the XamDataGrid's InitializeRecord event (or override OnInitializeRecord) like so:
```
void grid_InitializeRecord(object sender, Infragistics.Windows.DataPresenter.Events.InitializeRecordEventArgs e)
{
grid.ExecuteCommand(DataPresenterCommands.ToggleRecordIsExpanded, e.Record);
}
``... | The above answer is good but for those who prefer to see this as a defined behavior, here's another take at it:
```
public class AutoExpandXamDataGridRecordBehavior : Behavior<XamDataGrid>
{
protected override void OnAttached()
{
if (AssociatedObject is XamDataGrid grid)
{
grid.Init... |
26,880,623 | I have a Xamdatagrid having hierarchical data.I want to display all such records expended automatically.So that user doesn't have to click on + icon for each record. | 2014/11/12 | [
"https://Stackoverflow.com/questions/26880623",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3181491/"
] | You can handle the XamDataGrid's InitializeRecord event (or override OnInitializeRecord) like so:
```
void grid_InitializeRecord(object sender, Infragistics.Windows.DataPresenter.Events.InitializeRecordEventArgs e)
{
grid.ExecuteCommand(DataPresenterCommands.ToggleRecordIsExpanded, e.Record);
}
``... | Here is the simpler solution that worked for me.
In the XAML:
```
<!-- namespace -->
xmlns:ig="http://schemas.infragistics.com/xaml/wpf"
<ig:XamDataGrid>
<ig:XamDataGrid.FieldSettings>
<ig:FieldSettings ExpandGroupByRecordsByDefault="True" />
</ig:XamDataGrid.FieldSettings>
</ig:XamDataGrid>
```
However, n... |
33,847,790 | Trying to insert records from one table into another. The destination table (@TableName) has three extra columns than the source table (@Sourcetable). These three columns are float columns and are set to NULL.
It doesn't matter if a zero is inserted or the NULL is left as is, as long as the insert works
The procedur... | 2015/11/21 | [
"https://Stackoverflow.com/questions/33847790",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4665424/"
] | You cannot use the asterisk to include all fields if the table definitions are not identical:
You must use something like
```
INSERT INTO table1 (col1, col2, col3, ...) SELECT col1, col2, col3, ... FROM table2
```
As you are trying to fill the tables generically you could try to create their column lists like this
... | If you don't have the same columns, then you have to explicitly list them. If the target table has more, then you can just list them in the insert side, if source table has more, then in the select, but best would be to list them in both.
You can also use views for both select and insert, so that the number of columns... |
43,297,564 | I've been trying to figure out a way to recursively remove all of the `xattr` for some files, however, none of the [previous methods](https://stackoverflow.com/questions/4833052/how-do-i-remove-the-extended-attributes-on-a-file-in-mac-os-x) seem to work anymore; there might be a newly introduced bug too?
```
$ xattr -... | 2017/04/08 | [
"https://Stackoverflow.com/questions/43297564",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/499581/"
] | You appear to have a nonstandard `xattr` command installed in /usr/local/bin/xattr (the standard one that ships with macOS is /usr/bin/xattr). Those are Python errors, so maybe it's [this one](https://pypi.python.org/pypi/xattr/)? Anyway, it doesn't use the same syntax as the standard one, so having it installed is goi... | This happened to me as well. and I believe is due to my `$PATH`
```
/usr/local/bin:/usr/bin
```
My `user local bin` comes before my `system usr/bin`.
Thanks to these posts I figured out the problem.
xattr was installed in two locations.
>
> Show whether the target is a builtin, a function, an alias or an extern... |
11,136,289 | I have made a simple chat application in PHP/Ajax/MySQL.
I am regularly calling these two methods-
```
setInterval("GetChatParticipants()",5000);
setInterval("GetChatMessages()",1000);
```
Now as per client design, there's no Logout or Sign Out button, so I want to detect when user closes the browser and at that t... | 2012/06/21 | [
"https://Stackoverflow.com/questions/11136289",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/842616/"
] | The [Choosing an API](http://es.php.net/manual/en/mysqlinfo.api.choosing.php) chapter in the PHP manual says this:
>
> The overall
> performance of all three extensions is considered to be about the
> same. Although the performance of the extension contributes only a
> fraction of the total run time of a PHP web r... | In my opinion PDO is better than mysqli and there are no doubts. There are support for another databases, named parameters, easier SQL-Injection security (using prepared statements).
Mysqli is slightly faster, but i think it cannot be main reason in this case. |
72,539,311 | How do I change the class of sleep\_time and wake\_time columns from character to POSIXct?(Dataset clip is attached below)
I tried this but it didn't work
```
data$sleep_time <- as.Date(data$sleep_time, format = "%h.%m.%s")
```
 | 2022/06/08 | [
"https://Stackoverflow.com/questions/72539311",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17114921/"
] | First provide reproducible data using `dput()`:
```
data <- structure(list(date = "16-03-2022", sleep_time = "01.01", wake_time = "06.02"), class = "data.frame", row.names = c(NA,
-1L))
as.POSIXct(paste(data$date, data$sleep_time), format = "%d-%m-%Y %H.%M")
# [1] "2022-03-16 01:01:00 CDT"
as.POSIXct(paste(data$date,... | As mentioned in the comments, if you want to convert to `POSIXct`, then you need to combine the time with the date. Here, we can `paste` the date and time together, then convert to `as.POSIXct`.
```
library(tidyverse)
df %>%
mutate(sleep_time = as.POSIXct(paste(date, sleep_time), format="%d-%m-%Y %H.%M"),
... |
40,711,445 | With the following piece of code:
```
QString msg;
msg = "Datalogging Item" + ',' +
QString::number(item) + ',' +
"Slave Index" + ',' +
QString::number(slaveIndex) + ',' +
"Slave Name" + ',' +
slaveName + ',' +
... | 2016/11/21 | [
"https://Stackoverflow.com/questions/40711445",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3565922/"
] | You can repro similar results even simpler:
```
msg = "Datalogging Item" + ',' + QString::number(item);
```
And now it occurs to be exactly what the issue is. The first part of that expression is simply:
```
"Datalogging Item" + ','
```
In the above expression, a raw string literal is having the integer value... | It is better to use QStringLiteral macro for static string in code.
```
msg = QStringLiteral("Datalogging Item") + ',' +
```
More info here: <http://doc.qt.io/qt-5/qstring.html#QStringLiteral> |
40,711,445 | With the following piece of code:
```
QString msg;
msg = "Datalogging Item" + ',' +
QString::number(item) + ',' +
"Slave Index" + ',' +
QString::number(slaveIndex) + ',' +
"Slave Name" + ',' +
slaveName + ',' +
... | 2016/11/21 | [
"https://Stackoverflow.com/questions/40711445",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3565922/"
] | The expression
```
"Datalogging Item" + ','
```
has the type and meaning of
```
static_cast<const char *>("Datalogging Item" + 44)
```
You're taking the address of the beginning of the `Datalogging` string constant and adding 44 to it - advancing it by 44 characters. This is undefined behavior as you're moving a ... | It is better to use QStringLiteral macro for static string in code.
```
msg = QStringLiteral("Datalogging Item") + ',' +
```
More info here: <http://doc.qt.io/qt-5/qstring.html#QStringLiteral> |
29,790,417 | In Spark SQL when I tried to use map function on DataFrame then I am getting below error.
The method map(Function1, ClassTag) in the type DataFrame is not applicable for the arguments (new Function(){})
I am following spark 1.3 documentation as well. <https://spark.apache.org/docs/latest/sql-programming-guide.html#i... | 2015/04/22 | [
"https://Stackoverflow.com/questions/29790417",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3206330/"
] | Change this to:
*Java 6 & 7*
```
List<String> teenagerNames = teenagers.javaRDD().map(
new Function<Row, String>() {
public String call(Row row) {
return "Name: " + row.getString(0);
}
}).collect();
```
*Java 8*
```
List<String> t2 = teenagers.javaRDD().map(
row -> "Name: " + row.getString(... | Do you have the correct dependency set in your pom.
Set this and try
```
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-sql_2.10</artifactId>
<version>1.3.1</version>
</dependency>
``` |
29,790,417 | In Spark SQL when I tried to use map function on DataFrame then I am getting below error.
The method map(Function1, ClassTag) in the type DataFrame is not applicable for the arguments (new Function(){})
I am following spark 1.3 documentation as well. <https://spark.apache.org/docs/latest/sql-programming-guide.html#i... | 2015/04/22 | [
"https://Stackoverflow.com/questions/29790417",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3206330/"
] | No need to convert to RDD, its delays the execution it can be done as below
`public static void mapMethod() {
// Read the data from file, where the file is in the classpath.
Dataset df = sparkSession.read().json("file1.json");
```
// Prior to java 1.8
Encoder<String> encoder = Encoders.STRING();
List<String> r... | Do you have the correct dependency set in your pom.
Set this and try
```
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-sql_2.10</artifactId>
<version>1.3.1</version>
</dependency>
``` |
29,790,417 | In Spark SQL when I tried to use map function on DataFrame then I am getting below error.
The method map(Function1, ClassTag) in the type DataFrame is not applicable for the arguments (new Function(){})
I am following spark 1.3 documentation as well. <https://spark.apache.org/docs/latest/sql-programming-guide.html#i... | 2015/04/22 | [
"https://Stackoverflow.com/questions/29790417",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3206330/"
] | Change this to:
*Java 6 & 7*
```
List<String> teenagerNames = teenagers.javaRDD().map(
new Function<Row, String>() {
public String call(Row row) {
return "Name: " + row.getString(0);
}
}).collect();
```
*Java 8*
```
List<String> t2 = teenagers.javaRDD().map(
row -> "Name: " + row.getString(... | try this:
```
// SQL can be run over RDDs that have been registered as tables.
DataFrame teenagers = sqlContext.sql("SELECT name FROM people WHERE age >= 13 AND age <= 19");
List<String> teenagerNames = teenagers.toJavaRDD().map(
new Function<Row, String>() {
public String call(Row row) {
return... |
29,790,417 | In Spark SQL when I tried to use map function on DataFrame then I am getting below error.
The method map(Function1, ClassTag) in the type DataFrame is not applicable for the arguments (new Function(){})
I am following spark 1.3 documentation as well. <https://spark.apache.org/docs/latest/sql-programming-guide.html#i... | 2015/04/22 | [
"https://Stackoverflow.com/questions/29790417",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3206330/"
] | Change this to:
*Java 6 & 7*
```
List<String> teenagerNames = teenagers.javaRDD().map(
new Function<Row, String>() {
public String call(Row row) {
return "Name: " + row.getString(0);
}
}).collect();
```
*Java 8*
```
List<String> t2 = teenagers.javaRDD().map(
row -> "Name: " + row.getString(... | check if you are using the correct import for
>
> Row(import org.apache.spark.sql.Row)
> Remove any other imports related to Row.otherwise ur syntax is correct
>
>
> |
29,790,417 | In Spark SQL when I tried to use map function on DataFrame then I am getting below error.
The method map(Function1, ClassTag) in the type DataFrame is not applicable for the arguments (new Function(){})
I am following spark 1.3 documentation as well. <https://spark.apache.org/docs/latest/sql-programming-guide.html#i... | 2015/04/22 | [
"https://Stackoverflow.com/questions/29790417",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3206330/"
] | Change this to:
*Java 6 & 7*
```
List<String> teenagerNames = teenagers.javaRDD().map(
new Function<Row, String>() {
public String call(Row row) {
return "Name: " + row.getString(0);
}
}).collect();
```
*Java 8*
```
List<String> t2 = teenagers.javaRDD().map(
row -> "Name: " + row.getString(... | Please check your input file's data and your dataframe sql query same thing I am facing and when I look back to the data so it was not matching with my query.
So probably same issue you are facing. toJavaRDD and JavaRDD both are working. |
29,790,417 | In Spark SQL when I tried to use map function on DataFrame then I am getting below error.
The method map(Function1, ClassTag) in the type DataFrame is not applicable for the arguments (new Function(){})
I am following spark 1.3 documentation as well. <https://spark.apache.org/docs/latest/sql-programming-guide.html#i... | 2015/04/22 | [
"https://Stackoverflow.com/questions/29790417",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3206330/"
] | Change this to:
*Java 6 & 7*
```
List<String> teenagerNames = teenagers.javaRDD().map(
new Function<Row, String>() {
public String call(Row row) {
return "Name: " + row.getString(0);
}
}).collect();
```
*Java 8*
```
List<String> t2 = teenagers.javaRDD().map(
row -> "Name: " + row.getString(... | No need to convert to RDD, its delays the execution it can be done as below
`public static void mapMethod() {
// Read the data from file, where the file is in the classpath.
Dataset df = sparkSession.read().json("file1.json");
```
// Prior to java 1.8
Encoder<String> encoder = Encoders.STRING();
List<String> r... |
29,790,417 | In Spark SQL when I tried to use map function on DataFrame then I am getting below error.
The method map(Function1, ClassTag) in the type DataFrame is not applicable for the arguments (new Function(){})
I am following spark 1.3 documentation as well. <https://spark.apache.org/docs/latest/sql-programming-guide.html#i... | 2015/04/22 | [
"https://Stackoverflow.com/questions/29790417",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3206330/"
] | No need to convert to RDD, its delays the execution it can be done as below
`public static void mapMethod() {
// Read the data from file, where the file is in the classpath.
Dataset df = sparkSession.read().json("file1.json");
```
// Prior to java 1.8
Encoder<String> encoder = Encoders.STRING();
List<String> r... | try this:
```
// SQL can be run over RDDs that have been registered as tables.
DataFrame teenagers = sqlContext.sql("SELECT name FROM people WHERE age >= 13 AND age <= 19");
List<String> teenagerNames = teenagers.toJavaRDD().map(
new Function<Row, String>() {
public String call(Row row) {
return... |
29,790,417 | In Spark SQL when I tried to use map function on DataFrame then I am getting below error.
The method map(Function1, ClassTag) in the type DataFrame is not applicable for the arguments (new Function(){})
I am following spark 1.3 documentation as well. <https://spark.apache.org/docs/latest/sql-programming-guide.html#i... | 2015/04/22 | [
"https://Stackoverflow.com/questions/29790417",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3206330/"
] | No need to convert to RDD, its delays the execution it can be done as below
`public static void mapMethod() {
// Read the data from file, where the file is in the classpath.
Dataset df = sparkSession.read().json("file1.json");
```
// Prior to java 1.8
Encoder<String> encoder = Encoders.STRING();
List<String> r... | check if you are using the correct import for
>
> Row(import org.apache.spark.sql.Row)
> Remove any other imports related to Row.otherwise ur syntax is correct
>
>
> |
29,790,417 | In Spark SQL when I tried to use map function on DataFrame then I am getting below error.
The method map(Function1, ClassTag) in the type DataFrame is not applicable for the arguments (new Function(){})
I am following spark 1.3 documentation as well. <https://spark.apache.org/docs/latest/sql-programming-guide.html#i... | 2015/04/22 | [
"https://Stackoverflow.com/questions/29790417",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3206330/"
] | No need to convert to RDD, its delays the execution it can be done as below
`public static void mapMethod() {
// Read the data from file, where the file is in the classpath.
Dataset df = sparkSession.read().json("file1.json");
```
// Prior to java 1.8
Encoder<String> encoder = Encoders.STRING();
List<String> r... | Please check your input file's data and your dataframe sql query same thing I am facing and when I look back to the data so it was not matching with my query.
So probably same issue you are facing. toJavaRDD and JavaRDD both are working. |
38,010 | The volume of an $n$-sphere of radius $R$ is
$$V\_n(R) = \frac{\pi^{n/2} R^n}{\Gamma(\frac{n}2+1)}$$
and the surface area is
$$S\_n(R) = \frac{2\pi^{n/2}R^{n-1}}{\Gamma(\frac{n}2)} = \frac{n\pi^{n/2}R^{n-1}}{\Gamma(\frac{n}2+1)} = \frac{d V\_n(R)}{dR}$$
What is the intuition for this relationship between the volume... | 2011/05/09 | [
"https://math.stackexchange.com/questions/38010",
"https://math.stackexchange.com",
"https://math.stackexchange.com/users/4873/"
] | There is a very simple geometric explanation for the fact that the constant of proportionality is 1 for the sphere's radius and the cube's half-width. In fact, this relationship also lets you define a sensible notion of a "half-width" of an arbitrary $n$-dimensional shape.
Pick an arbitrary shape and a point $O$ insid... | Some remarks:
1. It is not necessary to regard solids that generalize to $n$ dimensions, so one can start with shapes in 2 dimensions.
2. It is very natural to always use a radius-type parameter to scale the figure because the intuition is that the figure gets growth rings that have the size of the surface.
3. Unfortu... |
38,010 | The volume of an $n$-sphere of radius $R$ is
$$V\_n(R) = \frac{\pi^{n/2} R^n}{\Gamma(\frac{n}2+1)}$$
and the surface area is
$$S\_n(R) = \frac{2\pi^{n/2}R^{n-1}}{\Gamma(\frac{n}2)} = \frac{n\pi^{n/2}R^{n-1}}{\Gamma(\frac{n}2+1)} = \frac{d V\_n(R)}{dR}$$
What is the intuition for this relationship between the volume... | 2011/05/09 | [
"https://math.stackexchange.com/questions/38010",
"https://math.stackexchange.com",
"https://math.stackexchange.com/users/4873/"
] | Some remarks:
1. It is not necessary to regard solids that generalize to $n$ dimensions, so one can start with shapes in 2 dimensions.
2. It is very natural to always use a radius-type parameter to scale the figure because the intuition is that the figure gets growth rings that have the size of the surface.
3. Unfortu... | What you're seeing with spheres is an instance of something really important called the coarea formula. You're looking at a function like $f(x,y,z) = r = \sqrt{x^2 + y^2 + z^2}$ and you're comparing the volumes of the lower contour sets $f(x,y,z) \leq R$ (in this case they are balls) to the areas of the level sets $f(x... |
38,010 | The volume of an $n$-sphere of radius $R$ is
$$V\_n(R) = \frac{\pi^{n/2} R^n}{\Gamma(\frac{n}2+1)}$$
and the surface area is
$$S\_n(R) = \frac{2\pi^{n/2}R^{n-1}}{\Gamma(\frac{n}2)} = \frac{n\pi^{n/2}R^{n-1}}{\Gamma(\frac{n}2+1)} = \frac{d V\_n(R)}{dR}$$
What is the intuition for this relationship between the volume... | 2011/05/09 | [
"https://math.stackexchange.com/questions/38010",
"https://math.stackexchange.com",
"https://math.stackexchange.com/users/4873/"
] | There is a very simple geometric explanation for the fact that the constant of proportionality is 1 for the sphere's radius and the cube's half-width. In fact, this relationship also lets you define a sensible notion of a "half-width" of an arbitrary $n$-dimensional shape.
Pick an arbitrary shape and a point $O$ insid... | What you're seeing with spheres is an instance of something really important called the coarea formula. You're looking at a function like $f(x,y,z) = r = \sqrt{x^2 + y^2 + z^2}$ and you're comparing the volumes of the lower contour sets $f(x,y,z) \leq R$ (in this case they are balls) to the areas of the level sets $f(x... |
23,210,770 | I have two tables, one table has three columns another one has two columns. I need to fetch records from Table1 which is not present in Table2. For example
```
DECLARE @Table1 TABLE (C1 INT, C2 INT, C3 INT)
INSERT INTO @Table1 VALUES(1,1,1)
INSERT INTO @Table1 VALUES(1,2,2)
INSERT INTO @Table1 VALUES(1,3,3)
INSERT INT... | 2014/04/22 | [
"https://Stackoverflow.com/questions/23210770",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2891428/"
] | This should work:
```
SELECT Table1.*
FROM Table1
LEFT OUTER JOIN Table2
ON Table1.C1 = Table2.C1
AND Table1.C2 = Table2.C2
WHERE Table2.C1 IS NULL
AND Table2.C2 IS NULL
``` | Please try this -
```
SELECT t1.*
from table1 t1
where not exists (select null from table2 t2
where t1.c1=t2.c1
and t1.c2=t2.c2);
``` |
32,511,161 | I have dynamically built tabs. When you add a tab you give it a class (which is equal to the name you give to the tab), the same class is added to the tab's description, which appears beneath the default description field.
The problem is when I remove a tab I search through `<li>` elements and check whether they have ... | 2015/09/10 | [
"https://Stackoverflow.com/questions/32511161",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4440968/"
] | try change `$( "li" ).hasClass( $thisClass ).remove();` to `$('.'+$thisClass).remove();` | ```
$thisClass = $ ( this ).closest( "li" ).attr( "class" );
```
This will return you *all* the classes on the element. That element may have more than one class. If it does, then you'll get a space-separated list of them.
Also `hasClass()` returns a boolean. It tells you whether an element has a class or not.
You ... |
32,511,161 | I have dynamically built tabs. When you add a tab you give it a class (which is equal to the name you give to the tab), the same class is added to the tab's description, which appears beneath the default description field.
The problem is when I remove a tab I search through `<li>` elements and check whether they have ... | 2015/09/10 | [
"https://Stackoverflow.com/questions/32511161",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4440968/"
] | If you have the same situation as described in fiddle, then
1. you need to remove class 'item' from li classes list
2. correct mistake with hasClass
and you'll get something like this
```
$( ".close" ).click( function(){
$( this ).closest( "li" ).fadeOut( 200, function() {$( this ).remove();});... | try change `$( "li" ).hasClass( $thisClass ).remove();` to `$('.'+$thisClass).remove();` |
32,511,161 | I have dynamically built tabs. When you add a tab you give it a class (which is equal to the name you give to the tab), the same class is added to the tab's description, which appears beneath the default description field.
The problem is when I remove a tab I search through `<li>` elements and check whether they have ... | 2015/09/10 | [
"https://Stackoverflow.com/questions/32511161",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4440968/"
] | If you have the same situation as described in fiddle, then
1. you need to remove class 'item' from li classes list
2. correct mistake with hasClass
and you'll get something like this
```
$( ".close" ).click( function(){
$( this ).closest( "li" ).fadeOut( 200, function() {$( this ).remove();});... | ```
$thisClass = $ ( this ).closest( "li" ).attr( "class" );
```
This will return you *all* the classes on the element. That element may have more than one class. If it does, then you'll get a space-separated list of them.
Also `hasClass()` returns a boolean. It tells you whether an element has a class or not.
You ... |
54,294,901 | I'm currently executing my stored procedure below, and it works perfectly. But I can't specify the command timeout.
```
var results = await _dbContext.DbContext.Database.SqlQuery<GetOutputDto>(@"[dbo].[GetOutput] " + parameterString, list.ToArray()).ToListAsync();
```
Now I've change this to the below, and wonderi... | 2019/01/21 | [
"https://Stackoverflow.com/questions/54294901",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10791696/"
] | Using System.reflection in those situation is really handy.
```
public static List<T> Convert<T>(IDataReader dr) where T : class, new()
{
List<T> list = new List<T>();
T obj = default(T);
while (dr.Read()) {
obj = Activator.CreateInstance<T>();
foreach (PropertyInfo prop in obj.GetType().Ge... | Not that hard, do it like this
>
> note, this is lazy eval so it should perform well when there is user IO, still fairly fast in other cases, I've used it in data ETL projects with many records.
>
>
>
```
public static IEnumerable<dynamic>( /* params */)
{
// build command object here.
using (SqlDataRe... |
54,294,901 | I'm currently executing my stored procedure below, and it works perfectly. But I can't specify the command timeout.
```
var results = await _dbContext.DbContext.Database.SqlQuery<GetOutputDto>(@"[dbo].[GetOutput] " + parameterString, list.ToArray()).ToListAsync();
```
Now I've change this to the below, and wonderi... | 2019/01/21 | [
"https://Stackoverflow.com/questions/54294901",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10791696/"
] | Using System.reflection in those situation is really handy.
```
public static List<T> Convert<T>(IDataReader dr) where T : class, new()
{
List<T> list = new List<T>();
T obj = default(T);
while (dr.Read()) {
obj = Activator.CreateInstance<T>();
foreach (PropertyInfo prop in obj.GetType().Ge... | I would in all honesty send over as an array and convert to table type within SQL and do the dirty work on the server side. Also a good way to be able to specify the timeout can be done by either the connection strings within your config file or you can also pass that same parameter over to sql with a WAITFOR DELAY.
C... |
45,880,127 | Let's say we have a fake data source which will return data it holds in batch
```
class DataSource(size: Int) {
private var s = 0
implicit val g = scala.concurrent.ExecutionContext.global
def getData(): Future[List[Int]] = {
s = s + 1
Future {
Thread.sleep(Random.nextInt(s * 100))
... | 2017/08/25 | [
"https://Stackoverflow.com/questions/45880127",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6273735/"
] | The following is one way to achieve the same behavior with Akka Streams, using your `DataSource` class:
```
import scala.concurrent.Future
import scala.util.Random
import akka.actor.ActorSystem
import akka.stream._
import akka.stream.scaladsl._
object StreamsExample extends App {
implicit val system = ActorSystem(... | >
> Ideally, I would like to wrap the Future for each batch into a big future, and the wrapper future success when last batch returned 0 size list?
>
>
>
I think you are looking for a `Promise`.
You would set up a `Promise` before you start the first iteration.
This gives you `promise.future`, a `Future` that y... |
45,880,127 | Let's say we have a fake data source which will return data it holds in batch
```
class DataSource(size: Int) {
private var s = 0
implicit val g = scala.concurrent.ExecutionContext.global
def getData(): Future[List[Int]] = {
s = s + 1
Future {
Thread.sleep(Random.nextInt(s * 100))
... | 2017/08/25 | [
"https://Stackoverflow.com/questions/45880127",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6273735/"
] | The following is one way to achieve the same behavior with Akka Streams, using your `DataSource` class:
```
import scala.concurrent.Future
import scala.util.Random
import akka.actor.ActorSystem
import akka.stream._
import akka.stream.scaladsl._
object StreamsExample extends App {
implicit val system = ActorSystem(... | You are probably looking for a reactive streams library. My personal favorite (and one I'm most familiar with) is [Monix](https://monix.io). This is how it will work with DataSource unchanged
```
import scala.concurrent.duration.Duration
import scala.concurrent.Await
import monix.reactive.Observable
import monix.exec... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.