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
|
|---|---|---|---|---|---|
5,988,457
|
I'm compiling a trivial C++ file `Temp.cpp`:
```
#include <string>
int main() { std::wstring s; }
```
With the command line:
```
cl.exe /MD /Iinc\api\crt\stl60 /Iinc\crt /Iinc\api C:\Temp.cpp
/LibPath:lib\wxp\i386 /LibPath:lib\crt\i386
/link /LibPath:lib\wxp\i386 /LibPath:lib\crt\i386
```
in the WDK 7.1 Windows XP Free Build Environment.
I get link errors like (LNK2019):
```
unresolved external symbol "__declspec(dllimport) public: __thiscall
std::basic_string<wchar_t,struct std::char_traits<wchar_t>,
class std::allocator<wchar_t> >::~basic_string<wchar_t,
struct std::char_traits<wchar_t>,class std::allocator<wchar_t> >(void)"
(__imp_??1?$basic_string@_WU?$char_traits@_W@std@@V?$allocator
@_W@2@@std@@QAE@XZ) referenced in function _main
```
If I use `string` instead of `wstring`, it works.
What's the cause of the problem? How can I use `wchar_t`-based types in my source file?
|
2011/05/13
|
[
"https://Stackoverflow.com/questions/5988457",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/541686/"
] |
The likely fix would be to set /Zc:wchar\_t- to turn off wchar\_t as an intrinsic type. STL6 doesn't have great support for /Zc:wchar\_t which is the default since at least VC7.1, perhaps earlier.
Meta: Please don't use the STL60 version of STL. This version from 1998 lacks a large number of bug fixes, performance improvements and standards-conformance work that you can find in a modern STL. If you are using the VC compiler toolchain the free VC++ express includes STL.
Martyn
|
VC6 doesn't support the `wchar_t` *type* , it had a `typedef` for `unsigned short`. The linker would only be able to find `std::basic_string<unsigned short>` in the "stl60" lib.
|
1,061,449
|
I have a directory containing thousands of files with names
```
t_00xx_000xxx.png
```
I want to change their names to `00xx_000xxx_t.png`
so take the prefix and put it as a postfix, can this be done in only one command
|
2018/08/01
|
[
"https://askubuntu.com/questions/1061449",
"https://askubuntu.com",
"https://askubuntu.com/users/837988/"
] |
This is possible with the [`rename`](http://manpages.ubuntu.com/manpages/bionic/en/man1/prename.1p.html) command:
First check what *would* be done (by suppliying `-n`). If it looks good, drop the `-n` and run again:
```
rename -n 's/t_(.+)\.png$/$1_t.png/' *.png # check only
rename 's/t_(.+)\.png$/$1_t.png/' *.png # actually rename the files
```
|
`mmv` (available from the `universe` repository) is nice for this kind of thing, where simple shell globs rather than regular expression can do the job
Ex.
```
mmv -n -- '*_*_*.png' '#2_#3_#1.png'
t_00xx_000xxx.png -> 00xx_000xxx_t.png
```
Remove the `-n` once you are happy that it's working right.
|
1,061,449
|
I have a directory containing thousands of files with names
```
t_00xx_000xxx.png
```
I want to change their names to `00xx_000xxx_t.png`
so take the prefix and put it as a postfix, can this be done in only one command
|
2018/08/01
|
[
"https://askubuntu.com/questions/1061449",
"https://askubuntu.com",
"https://askubuntu.com/users/837988/"
] |
If the prefix is separated by an underscore (`_`), you can do the following:
```
rename -n 's/^([^_]*)_(.*)\.(.*)$/$2_$1.$3/' file(s)
```
It will work with any prefix and any extension.
Remove the `-n` to perform the rename if you're happy with the result.
---
**Explanation:**
* `s/search_pattern/replace_pattern/`
Search pattern:
* `^` - Match the beginning of the file name
* `([^_]*)` - Match any character that is not an underscore `[^_]*` and capture it as `$1` `(...)`
* `_` - Match the first underscore
* `(.*)\.(.*)` - Match anything `.*` before and after the last `.` and capture it as `$2` and `$3`. The `.` must be escaped because it is a special character in Regex --> `\.`
* `$` - Match the end of the line
Replace pattern:
* `$2_$1.$3` - "Filename\_Prefix.Extension" from the search pattern captures.
|
`mmv` (available from the `universe` repository) is nice for this kind of thing, where simple shell globs rather than regular expression can do the job
Ex.
```
mmv -n -- '*_*_*.png' '#2_#3_#1.png'
t_00xx_000xxx.png -> 00xx_000xxx_t.png
```
Remove the `-n` once you are happy that it's working right.
|
17,618,051
|
My setup is as follows: Windows 7, XAMPP with Apache and PHP enabled I have a PHP script in which I call an external program to do run a conversion. This external program is an EXE file, which requires 3 attributes:
* The source file
* The destination file
* Additional flags (conversion type etc)
When I use the command line tool built into XAMPP to execute my script, everything works fine. But when I use the exec() function in my PHP script, no output file is created. I'm pretty sure the conversion is actually happening (it takes about 5 seconds, about the same time it takes to run the PHP script).
I think it's a permissions thing, so I already moved the EXE file to the same folder as my PHP file and adjusted the permissions of the entire folder (I granted all permissions to all users). I also disabled the Windows UAC and tried to put the command in a BAT file. The file just is not created.
Any help or tips would be greatly appreciated!
My PHP code is as follows:
```
exec('c:\converter.exe c:\src.txt c:\dst.txt -f', $output);
print_r($output);
```
When I print out $output, the array turns out to be empty. When I put the exact same command in Command Prompt, the code works like a charm (no syntax errors). I use absolute paths as well.
|
2013/07/12
|
[
"https://Stackoverflow.com/questions/17618051",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2029689/"
] |
The default driver for Capybara is Rack::Test. Your page probably requires javacript which means that Capybara's default driver is not rendering everything correctly. Just set `Capybara.default_driver = :selenium`. This way the javascript is run correctly.
See also [link](http://www.opinionatedprogrammer.com/2011/02/capybara-and-selenium-with-rspec-and-rails-3/), which explains how to change the driver for only one testcase and not the whole test suite. Note that if you use selenium as the driver the method `save_and_open_page` probably won't work.
|
I needed to add to `spec_helper.rb` the line
```
require 'capybara/rspec'
```
and use default browser driver
|
6,604,814
|
Well, I've finally decided that I'm not crazy. So, that leaves DataMapper.
Here's what I'm doing. I have a model Msrun which `has 1` Metric.
```
tmp = Msrun.first_or_create # I'll skip the boring details
tmp.metric = Metric.first_or_create( {msrun_id: tmp.id}, {metric_input_file: @metricsfile} )
p tmp.metric # => #<Metric @metric_input_file=nil @msrun_id=1>
tmp.metric.metric_input_file = @metricsfile
p tmp.metric # => #<Metric @metric_input_file=#<Pathname:/home/ryanmt/Dropbox/coding/rails/metrics_site/spec/tfiles/single_metric.txt> @msrun_id=1>
```
So, why doesn't this work? I'm reading <http://datamapper.org/docs/create_and_destroy> and doing what it shows working. This has been terribly arduous. Thanks for any help.
Update:
I still can't figure out what is going on, but to prove I'm not insane...
```
puts Metric.all # => []
tmp.metric = Metric.first_or_create( {msrun_id: tmp.id}, {metric_input_file: @metricsfile} )
puts Metric.all # => [] #??????????????
tmp.metric.metric_input_file = @metricsfile
p tmp.metric # => #<Metric @metric_input_file=#<Pathname:/home/ryanmt/Dropbox/coding/rails/metrics_site/spec/tfiles/single_metric.txt> @msrun_id=1>
tmp.metric.save
puts Metric.all # => [#<Metric @metric_input_file=#<Pathname:/home/ryanmt/Dropbox/coding/rails/metrics_site/spec/tfiles/single_metric.txt> @msrun_id=1>]
```
So, not only is `first_or_create` not delivering on the behavior I expect by reading the source
```
def first_or_create(conditions = {}, attributes = {})
first(conditions) || create(conditions.merge(attributes))
end
```
but it is also not even creating.
|
2011/07/07
|
[
"https://Stackoverflow.com/questions/6604814",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/654245/"
] |
I'm probably missing something here (more of those boring details might help) but if the metric exists, it's metric\_input\_file shouldn't be updated, i.e., it's only set when new. If you're after updating then you can do
```
.first_or_create(msrun_id: tmp.id).update(metric_input_file: @metricsfile)
```
Or if not hitting the database twice is relevant, then
```
m = Metric.first_or_new(msrun_id: tmp.id)
[set..save..assign]
```
But if it's not being set on *new models*, I don't see what would cause that from the code posted so far, more..?
[UPDATED]
Based on your new code, I'd say this is "a classic case" of a false DM save. I usually add the following line to an initialization section, e.g., application.rb in Rails.
```
DataMapper::Model.raise_on_save_failure = true
```
Unfortunately, the exception raised never tells you why (there's a special place in hell for that choice, right next to people who talk in theaters.) But it's typically one of:
* a slightly incorrect association definition
* a has/belongs\_to that isn't "required: false" and isn't set
* putting the wrong datatype into a field, e.g., a string into a decimal
* a validation failing
If you want to post your model definitions, the problem may be spottable there.
|
In addition to the answer above, I've seen this call die (like, literally halt all execution) with no error when I was doing a find\_or\_create that would have created an object that violated the primary key constraint. This is because the datamapper model was not in sync with the actual database schema.
|
38,620,944
|
I have a function onload which is just a simple console.log
```
<script>
onload = function(){
console.log('Hello');
}
</script>
```
I call it in my body like so
```
<body window.onload="onload();">
```
which after the page loads correctly prints
```
Hello
```
But I am trying to make it so when I click on my it also calls this function so I tried
```
<th onclick()="onload();">
```
Doing so results in
```
Uncaught TypeError: onload is not a function
```
I thought I might add that I generate my html file using a jade template so the table is dynamically loaded in (not sure if that matters)
Thank you
|
2016/07/27
|
[
"https://Stackoverflow.com/questions/38620944",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2770808/"
] |
solve it like this
```
import { Http, Response } from '@angular/http';
export class LoginService {
constructor(private http: Http) {
}
}
```
or use it like this
```
public constructor(@Inject(Http) private http: Http) {}
```
|
Assuming `requester` is a service.
Each `Component` which uses your service `requester` have to reference `HTTP_PROVIDERS`:
```
import {HTTP_PROVIDERS} from '@angular2/http';
@Component({
...
providers: [HTTP_PROVIDERS, requester],
...
})
export class MyComponent{
constructor(private _req: requester) {
}
}
```
|
38,620,944
|
I have a function onload which is just a simple console.log
```
<script>
onload = function(){
console.log('Hello');
}
</script>
```
I call it in my body like so
```
<body window.onload="onload();">
```
which after the page loads correctly prints
```
Hello
```
But I am trying to make it so when I click on my it also calls this function so I tried
```
<th onclick()="onload();">
```
Doing so results in
```
Uncaught TypeError: onload is not a function
```
I thought I might add that I generate my html file using a jade template so the table is dynamically loaded in (not sure if that matters)
Thank you
|
2016/07/27
|
[
"https://Stackoverflow.com/questions/38620944",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2770808/"
] |
try this one
```
import {Http, HTTP_PROVIDERS} from '@angular2/http';
@Component({
....
providers: [HTTP_PROVIDERS]
....})
export class requester {
constructor(private http:Http){}
...
}
```
Assuming missing providers for your request
|
Assuming `requester` is a service.
Each `Component` which uses your service `requester` have to reference `HTTP_PROVIDERS`:
```
import {HTTP_PROVIDERS} from '@angular2/http';
@Component({
...
providers: [HTTP_PROVIDERS, requester],
...
})
export class MyComponent{
constructor(private _req: requester) {
}
}
```
|
423
|
Somebody answered this question instead of the question [here](https://mathoverflow.net/questions/410/what-is-an-example-of-a-smooth-variety-over-a-finite-field-fp-which-does-not-emb), so I am asking this with the hope that they will cut and paste their solution.
|
2009/10/13
|
[
"https://mathoverflow.net/questions/423",
"https://mathoverflow.net",
"https://mathoverflow.net/users/2/"
] |
Examples are also in my paper "Murphy's Law in Algebraic Geometry", which you can get from my [preprints page](http://math.stanford.edu/~vakil/preprints.html)
Here is a short (not quite complete) description of a construction, with two explanations of why it works. I hope I am remembering this correctly!
In characteristic $>2$, consider the blow up of $\mathbf{P}^2$ at the $\mathbf{F}\_p$-valued points of the plane. Take a Galois cover of this surface, with Galois group $(\mathbf{Z}/2)^3$, branched only over the proper transform of the lines, and the transform of another high degree curve with no $\mathbf{F}\_p$-points.
Then you can check that this surface violates the numerical constraints of the Bogomolov-Miyaoka-Yau inequality, which holds in characteristic zero; hence it doesn't lift. (This is in a paper by Rob Easton.) Alternatively, show that deformations of this surface must always preserve that Galois cover structure, which in turn must preserve the data of the branch locus back in $\mathbf{P}^2$, meaning that any deformation must preserve the data of those $p^2+p+1$ lines meeting $p+1$ to a point, which forces you to live over $\mathbf{Z}/p$.
The two papers mentioned above give more exotic behavior too (of different sorts in the two papers), e.g. you an find a surface that lifts to $\mathbf{Z}/p^{10}$ but still not to $\mathbf{Z}\_p$.
|
There is an article by Illusie in *Fundamental Algebraic Geometry: Grothendieck's FGA Explained* that contains a construction of a non-liftable surface. The article is online ([pdf](http://www.math.u-psud.fr/~illusie/illusie_trieste.pdf)
- see section 6) and the construction is rather complicated. There are additional references to other nonliftability results (section 5F).
|
14,261,656
|
I'm using `@Html.Action()` to render a child action within my view.
The `_ViewStart.cshtml` file specifies that all views should use a particular layout like this:
```
@{
Layout = "~/Views/Shared/_Layout.cshtml";
}
```
Problem is, that layout is getting applied to my child action too, so the final page ends up with two headers and two footers. How do I prevent this?
|
2013/01/10
|
[
"https://Stackoverflow.com/questions/14261656",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/164923/"
] |
2 possibilities:
1. `return PartialView()` from the corresponding controller action instead of a `return View()`
2. Blank out the layout in the view itself
```
@{
Layout = null;
}
```
|
Seems you want to use `ChildActionOnly` and don't want to pass the model from view then you can not user PartialView.
If it is so, you need to remove the layout manually
```
@{
Layout = "";
}
```
|
18,248,384
|
Anyone point out the issue?
Keep getting "The specified type member 'Date' is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported."
```
public IEnumerable<Appointment> FindAllAppointmentsWithReminders()
{
DateTime reminderDate = DateTime.Today.Date;
IEnumerable<Appointment> apps = RepositorySet
.OfType<Appointment>()
.Include("Client")
.Where(c => EntityFunctions.TruncateTime(c.Client.Reminder.Date) == reminderDate.Date
&& reminderDate.Date > EntityFunctions.TruncateTime(c.StartTime.Date));
return apps;
}
```
|
2013/08/15
|
[
"https://Stackoverflow.com/questions/18248384",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1401620/"
] |
Remove all the `.Date` from your method but this:
```
DateTime reminderDate = DateTime.Today.Date;
```
EntityFramework doesn't support the `.Date` property of `Datetime`. For this reason there is the pseudo-function `EntityFunctions.TruncateTime`, and for the `reminderDate` you already remove the time in the `DateTime reminderDate = DateTime.Today.Date`.
```
public IEnumerable<Appointment> FindAllAppointmentsWithReminders()
{
DateTime reminderDate = DateTime.Today.Date;
IEnumerable<Appointment> apps = RepositorySet
.OfType<Appointment>()
.Include("Client")
.Where(c => EntityFunctions.TruncateTime(c.Client.Reminder) == reminderDate
&& reminderDate > EntityFunctions.TruncateTime(c.StartTime));
return apps;
}
```
|
Try this
```
public IEnumerable<Appointment> FindAllAppointmentsWithReminders()
{
DateTime reminderDate = DateTime.Today.Date;
**DateTime NewDate =reminderDate.Date;**
IEnumerable<Appointment> apps = RepositorySet
.OfType<Appointment>()
.Include("Client")
.Where(c => EntityFunctions.TruncateTime(c.Client.Reminder.Date) == **NewDate**
&& reminderDate.Date > EntityFunctions.TruncateTime(c.StartTime.Date));
return apps;
}
```
|
33,182
|
I'm currently getting to grips with the new (3.1) ArcGIS JavaScript API and how it bundles Dojo and relies on Dojo's Asynchronous Module Definition (AMD) approach.
I'm familiar with AMD and recently completed a project using Require, Backbone, and OpenLayers in combination - overall a very pleasant experience.
However I'm worried by
* how tightly-coupled Dojo is with the ArcGIS JavaScript API,
* that trying to use Require instead of Dojo AMD throws an exception, and
* that Dojo AMD doesn't seem to have the same user-base and momentum as Require, making it difficult to research / resolve problems without hitting the forums
My main concern is that I will write an ArcGIS JavaScript API application and not be able to build / package it into a single / small number of scripts. This will leave me with an application making 100+ HTTP requests at startup for all of the modules it depends on.
I've seen [this article](http://odoe.net/blog/?p=307) covering 3.0 but it doesn't mention the build process and I believe 3.0 is quite different. I've also seen [this piece](http://geospatialscott.blogspot.ca/2011/06/using-dojo-build-system-to-speed-up.html) on building / packaging an application that uses the ArcGIS JavaScript API but the comments suggest this is pre-Dojo 1.7 AMD.
Have ESRI really only half implemented the AMD approach, and in a way that will actually make my application slower? Why can I not find ESRI documentation on building / packaging a JavaScript API-based application?
Any thoughts or experience here would be much appreciated.
**EDIT** Based on the answers so far it seems that no, ESRI hasn't provided any information on building your Dojo application after inflating the number of scripts involved. It seems the only useful information available is from non-official sources and slightly outdated (enough to cause problems). This leads to me wonder why more people aren't vocal about the API's new improvements / deficiencies
* am I being too critical / demanding in expecting some more information here?
* is no one using the latest version of the API?
* should I use an older version of the API that doesn't depend on AMD?
|
2012/09/11
|
[
"https://gis.stackexchange.com/questions/33182",
"https://gis.stackexchange.com",
"https://gis.stackexchange.com/users/2788/"
] |
Since esri does not ship source code you cannot build one layer package with all your classes. You will have to push out the esri api locally or using the CDN and then pull down your layer file. So you will have 2 and then the extra's that esri forgot to bundle or chose not to.
We've put together a discard layer so that you don't duplicate packages within your own built layer file and the esri layer file. This is pre AMD but as you've noticed, AMD is only partially implemented in the current version of the API.
[This blog post](http://geospatialscott.blogspot.com/2011/06/using-dojo-build-system-to-speed-up.html) will outline everything you need to know and the concept will apply for newer versions.
the freenode irc chatroom #dojo has great realtime information if you dont' want to wait around for the forum.
|
while ago I was wondering the same question. But on last Esri Developer Summit 2012 I saw a presentation about JS api. Person that was presenting the subject explained how to create basic OO dojo plugin/module. You can watch whole video here: <http://proceedings.esri.com/library/userconf/devsummit12/index.html>
|
14,787,571
|
I found this post on [Bootstrap Tutorial for Blog Design](http://www.9lessons.info/2012/03/bootstrap-tutorial-for-blog-design.html).
I am planning to use it for one of my project for the responsive layout that it provides.
I have found an issue in the page hosted for [demo](http://demos.9lessons.info/bootstrap/index.html).
have attached a screenshot 
The first post in the page "Facebook Timeline Design using JQuery and CSS" is falling outside the border of the background [Have marked it in blue].[not the expected result]
The rest of the posts in the page falls inside the border which is the expected behaviour[have marked it in green].
Is there any way I can fix the issue of the first post falling outside the background border. I have tested this in IE,firefox and chrome with the same results.
have created a jsbin page [here](http://jsbin.com/anuvej/2/edit)
|
2013/02/09
|
[
"https://Stackoverflow.com/questions/14787571",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/328911/"
] |
In the css files its stated that the first span-element to have no margin on the left.
bootstrap-responsive.css on line 232:
```
.row-fluid [class*="span"]:first-child {
margin-left: 0px;
}
```
bootstrap.css on line 419:
```
.row-fluid [class*="span"]:first-child {
margin-left: 0px;
}
```
Remove or comment these out.
|
Add this stylesheet (*prefered at the bottom*)
```
.row > [class*="span"]:first-child {
padding-left: 20px;
}
```
If you want you can add this jQuery
```
$('.row > [class*="span"]:first-child').css('padding-left','20px');
```
|
14,787,571
|
I found this post on [Bootstrap Tutorial for Blog Design](http://www.9lessons.info/2012/03/bootstrap-tutorial-for-blog-design.html).
I am planning to use it for one of my project for the responsive layout that it provides.
I have found an issue in the page hosted for [demo](http://demos.9lessons.info/bootstrap/index.html).
have attached a screenshot 
The first post in the page "Facebook Timeline Design using JQuery and CSS" is falling outside the border of the background [Have marked it in blue].[not the expected result]
The rest of the posts in the page falls inside the border which is the expected behaviour[have marked it in green].
Is there any way I can fix the issue of the first post falling outside the background border. I have tested this in IE,firefox and chrome with the same results.
have created a jsbin page [here](http://jsbin.com/anuvej/2/edit)
|
2013/02/09
|
[
"https://Stackoverflow.com/questions/14787571",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/328911/"
] |
You can get it resolved by using jquery selector
```
$('.row > [class*="span"]:first-child').css({"padding-left":"20px"});
```
|
In the css files its stated that the first span-element to have no margin on the left.
bootstrap-responsive.css on line 232:
```
.row-fluid [class*="span"]:first-child {
margin-left: 0px;
}
```
bootstrap.css on line 419:
```
.row-fluid [class*="span"]:first-child {
margin-left: 0px;
}
```
Remove or comment these out.
|
14,787,571
|
I found this post on [Bootstrap Tutorial for Blog Design](http://www.9lessons.info/2012/03/bootstrap-tutorial-for-blog-design.html).
I am planning to use it for one of my project for the responsive layout that it provides.
I have found an issue in the page hosted for [demo](http://demos.9lessons.info/bootstrap/index.html).
have attached a screenshot 
The first post in the page "Facebook Timeline Design using JQuery and CSS" is falling outside the border of the background [Have marked it in blue].[not the expected result]
The rest of the posts in the page falls inside the border which is the expected behaviour[have marked it in green].
Is there any way I can fix the issue of the first post falling outside the background border. I have tested this in IE,firefox and chrome with the same results.
have created a jsbin page [here](http://jsbin.com/anuvej/2/edit)
|
2013/02/09
|
[
"https://Stackoverflow.com/questions/14787571",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/328911/"
] |
You can get it resolved by using jquery selector
```
$('.row > [class*="span"]:first-child').css({"padding-left":"20px"});
```
|
Add this stylesheet (*prefered at the bottom*)
```
.row > [class*="span"]:first-child {
padding-left: 20px;
}
```
If you want you can add this jQuery
```
$('.row > [class*="span"]:first-child').css('padding-left','20px');
```
|
29,424,655
|
I have a directive and now I want to send same data to other controller's methods and this controller is totally independent of this directive. this other controller is actually resides out the current directory.
How can I do this in angularjs?
|
2015/04/03
|
[
"https://Stackoverflow.com/questions/29424655",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2561567/"
] |
Create an angular service and inject in both the controllers. Update a variable in that service from controller 1 and retrieve in controller 2. Something like this -
```
myApp.factory('myFactory', function () {
// declare and store the value in a local variable here
var prop = '';
return {
getProperty: function () {
return prop;
},
setProperty: function(value) {
prop = value;
}
};
});
function Ctrl1($scope, myFactory) {
myFactory.setProperty('myValue');
}
function Ctrl2($scope, myFactory) {
val = myFactory.getProperty();
}
```
An angular service is a Singleton, so it maintains the state throughout the code.
|
In angularjs there is an idea about directive scope.It lets you to use data for directive with 3 ways.
1) string @
2) biDirectional =
3) functional &
I think you have heard about these.This link maybe can help you.
<https://docs.angularjs.org/api/ng/service/>$compile#directive-definition-object
|
67,510,810
|
I have the query below. How come with the invoice\_dt set between 1/1/2021 - 5/31/2021... the output display ALL date ranges. How would I set it to look for dups based on pay\_cte within the date range?
```
with pay_cte( vendor_id,invoice_id, pay_amt,pay_cnt ) as (
select vendor_id,invoice_id, pay_amt,count(*)
from ps_voucher
where invoice_dt between '01-Jan-2021' and '31-May-2021'
group by vendor_id,invoice_id, pay_amt
having count(*)>1)
select t.vendor_id, t.voucher_id,t.INVOICE_ID,t.gross_amt, t.INVOICE_DT
from ps_voucher t
join pay_cte p on t.vendor_id=p.vendor_id and t.invoice_id = p.invoice_id
and t.gross_amt=p.pay_amt
```
|
2021/05/12
|
[
"https://Stackoverflow.com/questions/67510810",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12081754/"
] |
The reason your query is returning all dates is due to the fact that your actual select statement that uses the `WITH` clause does not have any filtering for dates. It is likely that your `ps_voucher` table has records in it that have `INVOICE_DT` values that are out of the range of dates about which you are curious.
There are two ways you can filter results; the first is in the (inner) `JOIN` clause, and the second is by adding a `WHERE` clause in the query.
Option 1:
```
with pay_cte( vendor_id,invoice_id, pay_amt,pay_cnt ) as (
select
vendor_id,
invoice_id,
pay_amt,
count(*)
from ps_voucher
where
invoice_dt between '01-Jan-2021' and '31-May-2021'
group by
vendor_id,
invoice_id,
pay_amt
having
count(*)>1
)
select
t.vendor_id,
t.voucher_id,
t.INVOICE_ID,
t.gross_amt,
t.INVOICE_DT
from ps_voucher t
join pay_cte p
on t.vendor_id = p.vendor_id
and t.invoice_id = p.invoice_id
and t.gross_amt=p.pay_amt
and t.INVOICE_DT between '01-Jan-2021' and '31-May-2021'
```
Option 2:
```
with pay_cte( vendor_id,invoice_id, pay_amt,pay_cnt ) as (
select
vendor_id,
invoice_id,
pay_amt,
count(*)
from ps_voucher
where
invoice_dt between '01-Jan-2021' and '31-May-2021'
group by
vendor_id,
invoice_id,
pay_amt
having
count(*)>1
)
select
t.vendor_id,
t.voucher_id,
t.INVOICE_ID,
t.gross_amt,
t.INVOICE_DT
from ps_voucher t
join pay_cte p
on t.vendor_id = p.vendor_id
and t.invoice_id = p.invoice_id
and t.gross_amt=p.pay_amt
where
t.INVOICE_DT between '01-Jan-2021' and '31-May-2021'
```
|
You have to change your date for this format "yyyy-mm-dd"
|
19,235,348
|
I have the following line of code, which conditionally redirects that I would like to include in my Rails controller and execute only in the case that the request is an HTML request.
I would like to skip this logic in the case that the request is JSON. How does one do this in conjunction with the `respond_to :html, :json` method, declared before all controller actions?
```
redirect_to some_controller and return if @pages.empty?
```
|
2013/10/07
|
[
"https://Stackoverflow.com/questions/19235348",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/165448/"
] |
You want something like this:
```
class SomeController < ApplicationController
def index
@pages = Pages.find(:all)
respond_to do |format|
format.html do
redirect_to other_controller and return if @pages.empty
# ... other logic ...
end
format.json { render json: @pages }
end
end
end
```
|
You mean just branch logic by HTTP request format.
```
respond_to do |format|
format.html {your_html_logic }
format.json { your_json_logic }
end
```
|
19,235,348
|
I have the following line of code, which conditionally redirects that I would like to include in my Rails controller and execute only in the case that the request is an HTML request.
I would like to skip this logic in the case that the request is JSON. How does one do this in conjunction with the `respond_to :html, :json` method, declared before all controller actions?
```
redirect_to some_controller and return if @pages.empty?
```
|
2013/10/07
|
[
"https://Stackoverflow.com/questions/19235348",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/165448/"
] |
You should use the `respond_to` block:
```
respond_to do |format|
format.html { redirect_to some_controller }
format.json { render json: @data }
end
```
This will redirect to `some_controller` after an HTML request, and render JSON data after a JSON request.
|
You mean just branch logic by HTTP request format.
```
respond_to do |format|
format.html {your_html_logic }
format.json { your_json_logic }
end
```
|
19,235,348
|
I have the following line of code, which conditionally redirects that I would like to include in my Rails controller and execute only in the case that the request is an HTML request.
I would like to skip this logic in the case that the request is JSON. How does one do this in conjunction with the `respond_to :html, :json` method, declared before all controller actions?
```
redirect_to some_controller and return if @pages.empty?
```
|
2013/10/07
|
[
"https://Stackoverflow.com/questions/19235348",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/165448/"
] |
You want something like this:
```
class SomeController < ApplicationController
def index
@pages = Pages.find(:all)
respond_to do |format|
format.html do
redirect_to other_controller and return if @pages.empty
# ... other logic ...
end
format.json { render json: @pages }
end
end
end
```
|
You should use the `respond_to` block:
```
respond_to do |format|
format.html { redirect_to some_controller }
format.json { render json: @data }
end
```
This will redirect to `some_controller` after an HTML request, and render JSON data after a JSON request.
|
61,716,602
|
I have a button that triggers my view state. As I have now added a network call, I would like my view model to replace the @State with its @Publihed variable to perform the same changes.
How to use my @Published in the place of my @State variable?
So this is my SwiftUI view:
```
struct ContentView: View {
@ObservedObject var viewModel = OnboardingViewModel()
// This is the value I want to use as @Publisher
@State var isLoggedIn = false
var body: some View {
ZStack {
Button(action: {
// Before my @State was here
// self.isLoggedIn = true
self.viewModel.login()
}) {
Text("Log in")
}
if isLoggedIn {
TutorialView()
}
}
}
}
```
And this is my model:
```
final class OnboardingViewModel: ObservableObject {
@Published var isLoggedIn = false
private var subscriptions = Set<AnyCancellable>()
func demoLogin() {
AuthRequest.shared.login()
.sink(
receiveCompletion: { print($0) },
receiveValue: {
// My credentials
print("Login: \($0.login)\nToken: \($0.token)")
DispatchQueue.main.async {
// Once I am logged in, I want this
// value to change my view.
self.isLoggedIn = true } })
.store(in: &subscriptions)
}
}
```
|
2020/05/10
|
[
"https://Stackoverflow.com/questions/61716602",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10408494/"
] |
Remove state and use view model member directly, as below
```
struct ContentView: View {
@ObservedObject var viewModel = OnboardingViewModel()
var body: some View {
ZStack {
Button(action: {
self.viewModel.demoLogin()
}) {
Text("Log in")
}
if viewModel.isLoggedIn { // << here !!
TutorialView()
}
}
}
}
```
|
Hey Roland I think that what you are looking for is this:
```
$viewMode.isLoggedIn
```
Adding the $ before the var will ensure that SwiftUI is aware of its value changes.
```
struct ContentView: View {
@ObservedObject var viewModel = OnboardingViewModel()
var body: some View {
ZStack {
Button(action: {
viewModel.login()
}) {
Text("Log in")
}
if $viewMode.isLoggedIn {
TutorialView()
}
}
}
}
class OnboardingViewModel: ObservableObject {
@Published var isLoggedIn = false
func login() {
isLoggedIn = true
}
}
```
|
6,248,351
|
If i have the following structure in an MVC site.
```
Areas
+ Documents
+ Controllers
+ Models
+ Views
+ Shared
+ icons
icon.png
```
I am trying to use `img src='@url.Content("~/Areas/Documents/Views/Shared/icons/icon.png")'`/>
Why is this image unavailable?
Is there another path to use? Weird that I can browse to the file path in firefox, but as soon as I click on the image it errors with resource unavailable.
Do images have to go into the content directory?
Regards
Craig.
|
2011/06/06
|
[
"https://Stackoverflow.com/questions/6248351",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/231821/"
] |
Yes. I don't know how to override that as default the css and images has to go to the Content folder.
**UPDATED**: I correct what I said above, the images cannot be inside the Views\Shared folder without any special coding. You have to put the images in the outside folder but the folder can be named any instead of "Content".
|
The Shared folder in MVC is used as a default location for views. When your routing request is rendered the process will check the Controller's view folder for the correct view, if it is not present, the it will check the Shared folder for the view.
There is nothing stopping you from putting an image in your Views folder or any folder in your structure, but it usually not the norm. Check to see that the image is referenced correctly. Right click and check the properties of the image. Check to see if the path is being rendered properly to find the image.
|
6,248,351
|
If i have the following structure in an MVC site.
```
Areas
+ Documents
+ Controllers
+ Models
+ Views
+ Shared
+ icons
icon.png
```
I am trying to use `img src='@url.Content("~/Areas/Documents/Views/Shared/icons/icon.png")'`/>
Why is this image unavailable?
Is there another path to use? Weird that I can browse to the file path in firefox, but as soon as I click on the image it errors with resource unavailable.
Do images have to go into the content directory?
Regards
Craig.
|
2011/06/06
|
[
"https://Stackoverflow.com/questions/6248351",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/231821/"
] |
This works for me
img src='@Url.Content("../../Content/Images/6.jpg")' alt="" style="width: 100px; height: 100px" />
Yet my problem is getting the corresponding image to the product I am trying to show, no luck so far, I have tried hard coding too.
|
Yes. I don't know how to override that as default the css and images has to go to the Content folder.
**UPDATED**: I correct what I said above, the images cannot be inside the Views\Shared folder without any special coding. You have to put the images in the outside folder but the folder can be named any instead of "Content".
|
6,248,351
|
If i have the following structure in an MVC site.
```
Areas
+ Documents
+ Controllers
+ Models
+ Views
+ Shared
+ icons
icon.png
```
I am trying to use `img src='@url.Content("~/Areas/Documents/Views/Shared/icons/icon.png")'`/>
Why is this image unavailable?
Is there another path to use? Weird that I can browse to the file path in firefox, but as soon as I click on the image it errors with resource unavailable.
Do images have to go into the content directory?
Regards
Craig.
|
2011/06/06
|
[
"https://Stackoverflow.com/questions/6248351",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/231821/"
] |
This works for me
img src='@Url.Content("../../Content/Images/6.jpg")' alt="" style="width: 100px; height: 100px" />
Yet my problem is getting the corresponding image to the product I am trying to show, no luck so far, I have tried hard coding too.
|
The Shared folder in MVC is used as a default location for views. When your routing request is rendered the process will check the Controller's view folder for the correct view, if it is not present, the it will check the Shared folder for the view.
There is nothing stopping you from putting an image in your Views folder or any folder in your structure, but it usually not the norm. Check to see that the image is referenced correctly. Right click and check the properties of the image. Check to see if the path is being rendered properly to find the image.
|
18,414,075
|
This question is chiefly about LINQ and possibly covariance.
Two of my Entities implement the **IDatedItem** interface. I'd like to union, then sort these, for enumerating as a single list. I must retain entity-specific properties at enumeration-time.
To clarify by example, one approach I tried was:
```
Context.Table1.Cast<IDatedItem>().
Union(Context.Table2.Cast<IDatedItem>()).
SortBy(i => i.Date).
ForEach(u => CustomRenderSelector(u, u is Table1));
```
In trying to do this various ways, I've run into various errors.
* LINQ to Entities only supports casting EDM primitive or enumeration types.
* Unable to process the type '.IDatedItem[]', no known mapping to the value layer
* Unable to create a constant value of type 'IDatedItem'. Only primitive types
* etc.
The bigger picture:
* The IDatedItem interface shown here is a simplification of the actual shared properties.
* In practice, the tables are filtered before the union.
* The entity-specific properties will be rendered, in order, in a web page.
* In a parallel feature, they will be serialized to a JSON result hierarchy.
* I'd like to be able to perform LINQ aggregate operations on the results as well.
|
2013/08/24
|
[
"https://Stackoverflow.com/questions/18414075",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/608220/"
] |
This requires more space than a comment offers. On the other hand, this is not really an answer, because there is no satisfying answer, really.
For a `Union` to succeed, both collections must have the same type (or have intrinsic conversions to common types, that's what covariance is about).
So a first go at getting a correct Union could be:
```
Context.Table1.Select(t1 => new {
A = t1.PropA,
B = t1.PropB,
Date = t1.Date
})
.Union(
Context.Table1.Select(t2 => new {
A = t2.PropC,
B = t2.PropD,
Date = t2.Date
}))
.OrderBy(x => x.Date)
.ToList();
```
which projects both tables to the same anonymous type. Unfortunately, because of the anonymous type, you can't do `.Cast<IDatedItem>()`.
Therefore, the only way to get a `List<IDatedItem>` is to define a type that implements `IDatedItem` and project both tables to that type:
```
Context.Table1.Select(t1 => new DateItem {
A = t1.PropA,
B = t1.PropB,
Date = t1.Date
})
.Union(
Context.Table1.Select(t2 => new DateItem {
A = t2.PropC,
B = t2.PropD,
Date = t2.Date
}))
.OrderBy(item => item.Date)
.AsEnumerable()
.Cast<IDatedItem>()
```
Which (I think) is quite elaborate. But as long as EF doesn't support casting to interfaces in linq queries it's the way to go.
By the way, contrary to what I said in my comment, the sorting will be done in SQL. And you can use subsequent aggregate functions on the result.
|
Here's the working code. My solution was to ensure all data was local, to keep LINQ-to-EF from trying to do all manner of things it knows it can't that were causing many unclear errors. Then a simple type declaration on the generic Union can take hold.
That means that, aside from the annoyances of LINQ-to-EF, the main issue here is really a duplicate of [LINQ Union different types - dynamically casting to an interface?](https://stackoverflow.com/questions/13540846/linq-union-different-types-dynamically-casting-to-an-interface) .
```
public virtual ActionResult Index() {
return View(StatusBoard().OrderBy(s => s.Status));
}
private IEnumerable<DefensiveSituationBoardMember> StatusBoard() {
DateTime now = DateTime.UtcNow;
DateTime historicalCutoff = now.AddDays(-1);
IEnumerable<Member> activeMembers = Context.Members.Where(n => !n.Disabled).ToList();
// IncomingAttack and Reinforcements both implement IDefensiveActivity
IEnumerable<IncomingAttack> harm = Context.IncomingAttacks.Where(n => n.IsOngoingThreat || n.ArrivalOn > historicalCutoff).ToList();
IEnumerable<Reinforcements> help = Context.Reinforcements.Where(n => !n.Returned.HasValue || n.Returned > historicalCutoff).ToList();
// Here's the relevant fix
IEnumerable<IDefensiveActivity> visibleActivity = help.Union<IDefensiveActivity>(harm);
return from member in activeMembers
join harmEntry in harm on member equals harmEntry.DestinationMember into harmGroup
join activityEntry in visibleActivity on member equals activityEntry.DestinationMember into activityGroup
select new DefensiveSituationBoardMember {
Member = member,
Posture = harmGroup.Max(i => (DefensivePostures?)i.Posture),
Activity = activityGroup.OrderBy(a => a.ArrivalOn)
};
}
```
|
4,553,304
|
`Qt` has a flexible and powerful layout mechanism to handle view of desktop application's windows.
But it is so flexible, that it nearly cannot be understood, when something goes wrong and needs fine tuning. And so powerful, that it can beat anyone in their tries to overwhelm Qt's opinion of how form should look.
So, can anyone explain, or provide articles, or source of Qt's positioning mechanisms?
I'm trying to force the `QLabel`, `QPushButton` and `QTableView`, marked by trailing underscores in their names, be two times higher than `QTextBrowser` having `verticalStretch = 1` below. How can I handle widget's height properly?
[.ui file of my form on google docs. Search '\_\_\_\_' in names, preview in QtDesigner](https://docs.google.com/leaf?id=0B60otNVdbWrrZjk2MGZmZjUtOTRkNy00Yjc3LTliZjMtOTJiMThmNzk1YTZh&hl=en)
|
2010/12/29
|
[
"https://Stackoverflow.com/questions/4553304",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/286291/"
] |
Layouts are actually easy to understand "I think". :)
A simple explanation of layouts can be found in the QT book "**[C++ Gui programming with QT 2nd edition](https://web.archive.org/web/20090822161435/qt.nokia.com/developer/books/cpp-gui-programming-with-qt-4-2nd-edition/)**"
**What you should be aware of regarding layouts and their size policies**
* Most Qt widgets have a size policy. This size policy tells the system how the widget should stretch or shrink. It's got from the class QSizePolicy. A size policy has both vertical and horizontal components.
* Most widgets also have a size Hint. This size hint tells the system a widgets preferred size
* QSizePolicy has a stretch factor to allow widgets to grow at different rates
\*\*I am only familiar with 4 size policies\*\*
* fixed size policy - The size of the widget is fixed and it can't be stretched. It remains at its size hint.
* minimum size policy - The size hint is the smallest possible size of the widget, but it \_can still\_ grow bigger if necessary.
* Preferred size policy - the widget can shrink or grow bigger than its size hint.
* expanding size policy - the widget can shrink or grow bigger than its size hint :)
You may want to ask,
What is the difference between preferred and expanding?
\*\*Answer:\*\* Imagine a form with 2 widgets, one with preferred and another with expanding. Then any extra space will be given to the widget with the expanding policy. The widget with the preferred policy will remain at its size hint.
I recommend (WARNING: am not an expert :)) **you buy and read through** "**[C++ Gui programming with QT 2nd edition](https://web.archive.org/web/20090822161435/qt.nokia.com/developer/books/cpp-gui-programming-with-qt-4-2nd-edition/)**". I am currently reading it and it is making a lot of sense. Look at the images and see if they make some sense.
**Explaining size policies**

**A simple example**
This is a simple dialog with 2 buttons whose horizontal and vertical size policies are shown as are the horizontal and vertical stretch.

**Here is the preview at its smallest size.**

**Here is another preview at a larger size**

[EDITED: //added size hint example]
**WHY YOU SHOULD CARE ABOUT SIZEHINT**
You can see that every widget has a sizeHint which is vital because QT's layout system always respects the sizeHint. This is only a problem if the default size of the widget is not exactly what you want. The only way around this problem is to extend (subclass) the widget and reimplement its `sizeHint()` member function. An example is worth 1000 words. To save space, see my blog where there is an example project.
|
You can use QT Style Sheets to control the widgets height
and other properties in an easy customizable way.
<http://doc.qt.io/archives/qt-4.7/stylesheet.html>
As for the layouts you need to use them wisely and strongly
coupled with spacers in order to make the widgets behave
exactly the way you want them to.
<http://doc.qt.io/archives/qt-4.7/designer-layouts.html>
|
4,553,304
|
`Qt` has a flexible and powerful layout mechanism to handle view of desktop application's windows.
But it is so flexible, that it nearly cannot be understood, when something goes wrong and needs fine tuning. And so powerful, that it can beat anyone in their tries to overwhelm Qt's opinion of how form should look.
So, can anyone explain, or provide articles, or source of Qt's positioning mechanisms?
I'm trying to force the `QLabel`, `QPushButton` and `QTableView`, marked by trailing underscores in their names, be two times higher than `QTextBrowser` having `verticalStretch = 1` below. How can I handle widget's height properly?
[.ui file of my form on google docs. Search '\_\_\_\_' in names, preview in QtDesigner](https://docs.google.com/leaf?id=0B60otNVdbWrrZjk2MGZmZjUtOTRkNy00Yjc3LTliZjMtOTJiMThmNzk1YTZh&hl=en)
|
2010/12/29
|
[
"https://Stackoverflow.com/questions/4553304",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/286291/"
] |
According to its [docs](https://doc.qt.io/qt-5/layout.html#adding-widgets-to-a-layout):
>
> When you add widgets to a layout, the layout process works as follows:
>
>
> 1. All the widgets will initially be allocated an amount of space in accordance with their QWidget::sizePolicy() and QWidget::sizeHint().
> 2. If any of the widgets have stretch factors set, with a value greater than zero, then they are allocated space in proportion to their stretch factor (explained below).
> 3. If any of the widgets have stretch factors set to zero they will only get more space if no other widgets want the space. Of these, space is allocated to widgets with an Expanding size policy first.
> 4. Any widgets that are allocated less space than their minimum size (or minimum size hint if no minimum size is specified) are allocated this minimum size they require. (Widgets don't have to have a minimum size or minimum size hint in which case the stretch factor is their determining factor.)
> 5. Any widgets that are allocated more space than their maximum size are allocated the maximum size space they require. (Widgets do not have to have a maximum size in which case the stretch factor is their determining factor.)
>
>
>
And `sizeHint()` is the recommended size of a QWidget, and the `Layout` of the widget parent will take `sizeHint()` and `sizePolicy()` into consideration to determine the space of the child widget can hold.
|
You can use QT Style Sheets to control the widgets height
and other properties in an easy customizable way.
<http://doc.qt.io/archives/qt-4.7/stylesheet.html>
As for the layouts you need to use them wisely and strongly
coupled with spacers in order to make the widgets behave
exactly the way you want them to.
<http://doc.qt.io/archives/qt-4.7/designer-layouts.html>
|
4,553,304
|
`Qt` has a flexible and powerful layout mechanism to handle view of desktop application's windows.
But it is so flexible, that it nearly cannot be understood, when something goes wrong and needs fine tuning. And so powerful, that it can beat anyone in their tries to overwhelm Qt's opinion of how form should look.
So, can anyone explain, or provide articles, or source of Qt's positioning mechanisms?
I'm trying to force the `QLabel`, `QPushButton` and `QTableView`, marked by trailing underscores in their names, be two times higher than `QTextBrowser` having `verticalStretch = 1` below. How can I handle widget's height properly?
[.ui file of my form on google docs. Search '\_\_\_\_' in names, preview in QtDesigner](https://docs.google.com/leaf?id=0B60otNVdbWrrZjk2MGZmZjUtOTRkNy00Yjc3LTliZjMtOTJiMThmNzk1YTZh&hl=en)
|
2010/12/29
|
[
"https://Stackoverflow.com/questions/4553304",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/286291/"
] |
Layouts are actually easy to understand "I think". :)
A simple explanation of layouts can be found in the QT book "**[C++ Gui programming with QT 2nd edition](https://web.archive.org/web/20090822161435/qt.nokia.com/developer/books/cpp-gui-programming-with-qt-4-2nd-edition/)**"
**What you should be aware of regarding layouts and their size policies**
* Most Qt widgets have a size policy. This size policy tells the system how the widget should stretch or shrink. It's got from the class QSizePolicy. A size policy has both vertical and horizontal components.
* Most widgets also have a size Hint. This size hint tells the system a widgets preferred size
* QSizePolicy has a stretch factor to allow widgets to grow at different rates
\*\*I am only familiar with 4 size policies\*\*
* fixed size policy - The size of the widget is fixed and it can't be stretched. It remains at its size hint.
* minimum size policy - The size hint is the smallest possible size of the widget, but it \_can still\_ grow bigger if necessary.
* Preferred size policy - the widget can shrink or grow bigger than its size hint.
* expanding size policy - the widget can shrink or grow bigger than its size hint :)
You may want to ask,
What is the difference between preferred and expanding?
\*\*Answer:\*\* Imagine a form with 2 widgets, one with preferred and another with expanding. Then any extra space will be given to the widget with the expanding policy. The widget with the preferred policy will remain at its size hint.
I recommend (WARNING: am not an expert :)) **you buy and read through** "**[C++ Gui programming with QT 2nd edition](https://web.archive.org/web/20090822161435/qt.nokia.com/developer/books/cpp-gui-programming-with-qt-4-2nd-edition/)**". I am currently reading it and it is making a lot of sense. Look at the images and see if they make some sense.
**Explaining size policies**

**A simple example**
This is a simple dialog with 2 buttons whose horizontal and vertical size policies are shown as are the horizontal and vertical stretch.

**Here is the preview at its smallest size.**

**Here is another preview at a larger size**

[EDITED: //added size hint example]
**WHY YOU SHOULD CARE ABOUT SIZEHINT**
You can see that every widget has a sizeHint which is vital because QT's layout system always respects the sizeHint. This is only a problem if the default size of the widget is not exactly what you want. The only way around this problem is to extend (subclass) the widget and reimplement its `sizeHint()` member function. An example is worth 1000 words. To save space, see my blog where there is an example project.
|
According to its [docs](https://doc.qt.io/qt-5/layout.html#adding-widgets-to-a-layout):
>
> When you add widgets to a layout, the layout process works as follows:
>
>
> 1. All the widgets will initially be allocated an amount of space in accordance with their QWidget::sizePolicy() and QWidget::sizeHint().
> 2. If any of the widgets have stretch factors set, with a value greater than zero, then they are allocated space in proportion to their stretch factor (explained below).
> 3. If any of the widgets have stretch factors set to zero they will only get more space if no other widgets want the space. Of these, space is allocated to widgets with an Expanding size policy first.
> 4. Any widgets that are allocated less space than their minimum size (or minimum size hint if no minimum size is specified) are allocated this minimum size they require. (Widgets don't have to have a minimum size or minimum size hint in which case the stretch factor is their determining factor.)
> 5. Any widgets that are allocated more space than their maximum size are allocated the maximum size space they require. (Widgets do not have to have a maximum size in which case the stretch factor is their determining factor.)
>
>
>
And `sizeHint()` is the recommended size of a QWidget, and the `Layout` of the widget parent will take `sizeHint()` and `sizePolicy()` into consideration to determine the space of the child widget can hold.
|
405,123
|
I know that Hamel bases have a couple of defects for the purposes of doing analysis in infinite dimensions:
(1) Every Hamel basis of a complete normed space must be uncountable.
(2) For every Hamel basis of a complete normed space, all but finitely many of the coordinate functionals are discontinuous.
I also know both (1) and (2) are false if completeness is dropped.
Here are my questions, which I have labeled A,B,C,D:
A. I don't see why (1) is a serious problem. An uncountable Hamel basis seems just as hard (or just as easy) to work with as a countable Hamel basis. After all, Hamel bases are about unique representation as *finite* linear combinations. What am I missing?
B. (2) seems like it could be inconvenient. But I don't have a concrete understanding of why. What does (2) stop you from doing? I see that it means the standard dual basis for the algebraic dual is not basis a for the continuous dual.
C. Is there something else that goes wrong with Hamel basis in infinite dimensional spaces? Something, perhaps, that is more obviously inconvenient?
D. Is there something that goes wrong with Hamel basis in *incomplete* infinite dimensional spaces?
**Edit:** Some commentators have pointed out that Hamel bases cannot be produced explicitly for the most important spaces. I was aware of that, and should have said so. Is there anything else for C, other than (1),(2), and the lack of explicitness?
|
2021/09/29
|
[
"https://mathoverflow.net/questions/405123",
"https://mathoverflow.net",
"https://mathoverflow.net/users/150527/"
] |
The following perhaps could be a comment, but I thought that maybe I should state it as an answer so it can get positive or negative feedback.
To my mind, whenever I have taught linear algebra in the past, I emphasises that the great power of having a basis B for a vector space V, to study a linear map T from V to some other vector space W it is enough to know what T does on the elements of B. More precisely: T is uniquely determined by its restriction to B; and any function $B \to W$ extends (uniquely) to a linear map $V \to W$.
To make use of this, we therefore want to have examples or results where we can actually specify the values of T on some given basis.
Now suppose you want to study continuous linear maps $V\to W$ between Banach spaces. Since you can never get your hands on a Hamel basis, there is no possibility of creating interesting/useful linear maps by starting with a function defined on that basis. More seriously: if one just works abstractly and says that any function on a Hamel basis extends uniquely to a linear map on the containing space, how would one be able to tell if the resulting linear map is continuous?
Another practical problems is that most of the time, Banach spaces come with extra structure or context: e.g. $L^p(\mu)$ spaces or $C(K)$-spaces. Discontinuous linear maps are just not going to see this structure.
I think that ultimately, the point is that in functional analysis we want to do more than prove results of the form "if such-and-such a map exists, then another kind of map exists". One actually wants to relate Banach spaces to each other: to understand which ones embed as closed subspaces of other ones; to study settings where every bounded linear map from one space to another is automatically (weakly) compact; and so on. Hamel bases will rarely tell us anything here, because they don't reflect or detect various continuity or compactness properties.
|
This is an addition to Yemon Choi's answer.
In fact, a real-valued function $f$ defined on a Hamel basis $H$ of $\mathbb{R}$ over $\mathbb{Q}$, for instance, extends uniquely to ad *additive* function, not to a linear function (it only needs to be linear over $\mathbb{Q}$). This can be seen readily defining $$F(x)=\sum\_{i=1}^n q\_i f(b\_i),$$ where $b\_i\in H$ for every $i$ and $q\_i$ are $n$ rationals such that $\mathbb{R}\ni x=\sum\_{i=1}^n b\_iq\_i$.
This is a classical tool to provide additive, discontinuous real functions, of course exploiting the axiom of choice.
Finally, a Hamel basis is not only "not write-downable": it can be almost as nasty as you want. For instance, you can prove under AC that there is a Hamel basis $H$ of $\mathbb{R}$ over $\mathbb{Q}$ and a function $f:H\to\mathbb{R}$ such that, for every real $x$, $f^{-1}(x)$ has nonempty intersection with every closed, uncountable set without containing any of them (= is a Bernstein set). Or you can prove that there exists a Hamel basis which is not measurable *and* does not have the property of Baire, and much more...
All of this is very nicely covered in Chapter 7 of:
* Ciesielski, K. (1997). *Set theory for the working mathematician* (London Mathematical Society Student Texts No. 39). Cambridge University Press. <https://doi.org/10.1017/CBO9781139173131>
|
405,123
|
I know that Hamel bases have a couple of defects for the purposes of doing analysis in infinite dimensions:
(1) Every Hamel basis of a complete normed space must be uncountable.
(2) For every Hamel basis of a complete normed space, all but finitely many of the coordinate functionals are discontinuous.
I also know both (1) and (2) are false if completeness is dropped.
Here are my questions, which I have labeled A,B,C,D:
A. I don't see why (1) is a serious problem. An uncountable Hamel basis seems just as hard (or just as easy) to work with as a countable Hamel basis. After all, Hamel bases are about unique representation as *finite* linear combinations. What am I missing?
B. (2) seems like it could be inconvenient. But I don't have a concrete understanding of why. What does (2) stop you from doing? I see that it means the standard dual basis for the algebraic dual is not basis a for the continuous dual.
C. Is there something else that goes wrong with Hamel basis in infinite dimensional spaces? Something, perhaps, that is more obviously inconvenient?
D. Is there something that goes wrong with Hamel basis in *incomplete* infinite dimensional spaces?
**Edit:** Some commentators have pointed out that Hamel bases cannot be produced explicitly for the most important spaces. I was aware of that, and should have said so. Is there anything else for C, other than (1),(2), and the lack of explicitness?
|
2021/09/29
|
[
"https://mathoverflow.net/questions/405123",
"https://mathoverflow.net",
"https://mathoverflow.net/users/150527/"
] |
The following perhaps could be a comment, but I thought that maybe I should state it as an answer so it can get positive or negative feedback.
To my mind, whenever I have taught linear algebra in the past, I emphasises that the great power of having a basis B for a vector space V, to study a linear map T from V to some other vector space W it is enough to know what T does on the elements of B. More precisely: T is uniquely determined by its restriction to B; and any function $B \to W$ extends (uniquely) to a linear map $V \to W$.
To make use of this, we therefore want to have examples or results where we can actually specify the values of T on some given basis.
Now suppose you want to study continuous linear maps $V\to W$ between Banach spaces. Since you can never get your hands on a Hamel basis, there is no possibility of creating interesting/useful linear maps by starting with a function defined on that basis. More seriously: if one just works abstractly and says that any function on a Hamel basis extends uniquely to a linear map on the containing space, how would one be able to tell if the resulting linear map is continuous?
Another practical problems is that most of the time, Banach spaces come with extra structure or context: e.g. $L^p(\mu)$ spaces or $C(K)$-spaces. Discontinuous linear maps are just not going to see this structure.
I think that ultimately, the point is that in functional analysis we want to do more than prove results of the form "if such-and-such a map exists, then another kind of map exists". One actually wants to relate Banach spaces to each other: to understand which ones embed as closed subspaces of other ones; to study settings where every bounded linear map from one space to another is automatically (weakly) compact; and so on. Hamel bases will rarely tell us anything here, because they don't reflect or detect various continuity or compactness properties.
|
Historically, bases in functional analysis arose from reflection on a collection of concrete examples, such as trigonometric functions, orthogonal polynomials, spherical harmonics, eigenfunctions of the Laplacian, etc.
What's in common in these examples is that each appeared as a tool to solve a concrete problem by **diagonalizing an operator**. E. g. you know how the string evolves if released starting with a sine-wave shape, and we would like to know what happens in general. So, we decompose a function into Fourier series, which in general has infinitely many terms. It would be, of course, even better to diagonalize the wave operator into nice functions forming a Hamel basis, but, alas, no such thing exists.
From that point of view, uncountablity is not an issure, since e. g. operators with continuous spectra may be thought of "diagonalizable in an uncountable basis". It's the spectral decomposition of the operators that makes bases (in Hilbert spaces, at least) a particularly important tool.
|
405,123
|
I know that Hamel bases have a couple of defects for the purposes of doing analysis in infinite dimensions:
(1) Every Hamel basis of a complete normed space must be uncountable.
(2) For every Hamel basis of a complete normed space, all but finitely many of the coordinate functionals are discontinuous.
I also know both (1) and (2) are false if completeness is dropped.
Here are my questions, which I have labeled A,B,C,D:
A. I don't see why (1) is a serious problem. An uncountable Hamel basis seems just as hard (or just as easy) to work with as a countable Hamel basis. After all, Hamel bases are about unique representation as *finite* linear combinations. What am I missing?
B. (2) seems like it could be inconvenient. But I don't have a concrete understanding of why. What does (2) stop you from doing? I see that it means the standard dual basis for the algebraic dual is not basis a for the continuous dual.
C. Is there something else that goes wrong with Hamel basis in infinite dimensional spaces? Something, perhaps, that is more obviously inconvenient?
D. Is there something that goes wrong with Hamel basis in *incomplete* infinite dimensional spaces?
**Edit:** Some commentators have pointed out that Hamel bases cannot be produced explicitly for the most important spaces. I was aware of that, and should have said so. Is there anything else for C, other than (1),(2), and the lack of explicitness?
|
2021/09/29
|
[
"https://mathoverflow.net/questions/405123",
"https://mathoverflow.net",
"https://mathoverflow.net/users/150527/"
] |
Historically, bases in functional analysis arose from reflection on a collection of concrete examples, such as trigonometric functions, orthogonal polynomials, spherical harmonics, eigenfunctions of the Laplacian, etc.
What's in common in these examples is that each appeared as a tool to solve a concrete problem by **diagonalizing an operator**. E. g. you know how the string evolves if released starting with a sine-wave shape, and we would like to know what happens in general. So, we decompose a function into Fourier series, which in general has infinitely many terms. It would be, of course, even better to diagonalize the wave operator into nice functions forming a Hamel basis, but, alas, no such thing exists.
From that point of view, uncountablity is not an issure, since e. g. operators with continuous spectra may be thought of "diagonalizable in an uncountable basis". It's the spectral decomposition of the operators that makes bases (in Hilbert spaces, at least) a particularly important tool.
|
This is an addition to Yemon Choi's answer.
In fact, a real-valued function $f$ defined on a Hamel basis $H$ of $\mathbb{R}$ over $\mathbb{Q}$, for instance, extends uniquely to ad *additive* function, not to a linear function (it only needs to be linear over $\mathbb{Q}$). This can be seen readily defining $$F(x)=\sum\_{i=1}^n q\_i f(b\_i),$$ where $b\_i\in H$ for every $i$ and $q\_i$ are $n$ rationals such that $\mathbb{R}\ni x=\sum\_{i=1}^n b\_iq\_i$.
This is a classical tool to provide additive, discontinuous real functions, of course exploiting the axiom of choice.
Finally, a Hamel basis is not only "not write-downable": it can be almost as nasty as you want. For instance, you can prove under AC that there is a Hamel basis $H$ of $\mathbb{R}$ over $\mathbb{Q}$ and a function $f:H\to\mathbb{R}$ such that, for every real $x$, $f^{-1}(x)$ has nonempty intersection with every closed, uncountable set without containing any of them (= is a Bernstein set). Or you can prove that there exists a Hamel basis which is not measurable *and* does not have the property of Baire, and much more...
All of this is very nicely covered in Chapter 7 of:
* Ciesielski, K. (1997). *Set theory for the working mathematician* (London Mathematical Society Student Texts No. 39). Cambridge University Press. <https://doi.org/10.1017/CBO9781139173131>
|
29,591,304
|
I am developing an android application where I need to detect the blinking of eyes. So far I have been able to detect the face and eyes using OpenCV. But now I need to check if the eyes are open or close. I read somewhere that one of the ways I can do that is by measuring the pixel intensities (grey levels). But it was not properly explained as in how to do that step by step. I am actually new to OpenCV. So can anyone please help me how can I do that. It is really very important.
Here is my onCameraFrame method:
```
public Mat onCameraFrame(CvCameraViewFrame inputFrame) {
mRgba = inputFrame.rgba();
mGray = inputFrame.gray();
if (mAbsoluteFaceSize == 0) {
int height = mGray.rows();
if (Math.round(height * mRelativeFaceSize) > 0) {
mAbsoluteFaceSize = Math.round(height * mRelativeFaceSize);
}
}
if (mZoomWindow == null || mZoomWindow2 == null)
CreateAuxiliaryMats();
MatOfRect faces = new MatOfRect();
if (mJavaDetector != null)
mJavaDetector.detectMultiScale(mGray, faces, 1.1, 2,
2, // TODO: objdetect.CV_HAAR_SCALE_IMAGE
new Size(mAbsoluteFaceSize, mAbsoluteFaceSize),
new Size());
Rect[] facesArray = faces.toArray();
for (int i = 0; i < facesArray.length; i++) {
Core.rectangle(mRgba, facesArray[i].tl(), facesArray[i].br(),
FACE_RECT_COLOR, 2);
xCenter = (facesArray[i].x + facesArray[i].width + facesArray[i].x) / 2;
yCenter = (facesArray[i].y + facesArray[i].y + facesArray[i].height) / 2;
Point center = new Point(xCenter, yCenter);
Rect r = facesArray[i];
// compute the eye area
Rect eyearea = new Rect(r.x + r.width / 20,
(int) (r.y + (r.height / 20)), r.width - 2 * r.width / 20,
(int) (r.height / 9.0));
// split it
Rect eyearea_right = new Rect(r.x + r.width / 6,
(int) (r.y + (r.height / 4)),
(r.width - 2 * r.width / 16) / 3, (int) (r.height / 4.0));
Rect eyearea_left = new Rect(r.x + r.width / 11
+ (r.width - 2 * r.width / 16) / 2,
(int) (r.y + (r.height / 4)),
(r.width - 2 * r.width / 16) / 3, (int) (r.height / 4.0));
// draw the area - mGray is working grayscale mat, if you want to
// see area in rgb preview, change mGray to mRgba
Core.rectangle(mRgba, eyearea_left.tl(), eyearea_left.br(),
new Scalar(255, 0, 0, 255), 2);
Core.rectangle(mRgba, eyearea_right.tl(), eyearea_right.br(),
new Scalar(255, 0, 0, 255), 2);
if (learn_frames < 5) {
teplateR = get_template(mJavaDetectorEye, eyearea_right, 24);
teplateL = get_template(mJavaDetectorEye, eyearea_left, 24);
learn_frames++;
} else {
// Learning finished, use the new templates for template
// matching
match_eye(eyearea_right, teplateR, method);
match_eye(eyearea_left, teplateL, method);
}
}
return mRgba;
}
```
Thanks in advance.
|
2015/04/12
|
[
"https://Stackoverflow.com/questions/29591304",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4216014/"
] |
I already worked on this problem and this algorithm. It's implemented (C++) here: <https://github.com/maz/blinking-angel> with algorithm here: <http://www.cs.bu.edu/techreports/pdf/2005-012-blink-detection.pdf> .
As far as I can remember:
* You get B&W current and 100ms ago frames
* You do new - old (see 154 in github code)
* You apply a threshold then a dilatation filter
* You compute contours
* If you have a `blob with area > to a threshold` at the eye location, it means that user blinked eyes
Give a look at the `is_blink` function at line 316. In his case, he do `w * h of blob surrounding box > to a threshold`.
In fact it use difference between eye/skin color. In Github implementation, threshold > 5 is used.
|
Generally there is no obvious solution for this problem, but the number of approaches is quite big, so i'm sure that after a bit of serching you will find something good enough for you. For example you can use algorithm which i mentioned [here](https://stackoverflow.com/a/28811258/1598485) (there is a link to this question in "Related" btw - check other link from this group as well).
|
29,591,304
|
I am developing an android application where I need to detect the blinking of eyes. So far I have been able to detect the face and eyes using OpenCV. But now I need to check if the eyes are open or close. I read somewhere that one of the ways I can do that is by measuring the pixel intensities (grey levels). But it was not properly explained as in how to do that step by step. I am actually new to OpenCV. So can anyone please help me how can I do that. It is really very important.
Here is my onCameraFrame method:
```
public Mat onCameraFrame(CvCameraViewFrame inputFrame) {
mRgba = inputFrame.rgba();
mGray = inputFrame.gray();
if (mAbsoluteFaceSize == 0) {
int height = mGray.rows();
if (Math.round(height * mRelativeFaceSize) > 0) {
mAbsoluteFaceSize = Math.round(height * mRelativeFaceSize);
}
}
if (mZoomWindow == null || mZoomWindow2 == null)
CreateAuxiliaryMats();
MatOfRect faces = new MatOfRect();
if (mJavaDetector != null)
mJavaDetector.detectMultiScale(mGray, faces, 1.1, 2,
2, // TODO: objdetect.CV_HAAR_SCALE_IMAGE
new Size(mAbsoluteFaceSize, mAbsoluteFaceSize),
new Size());
Rect[] facesArray = faces.toArray();
for (int i = 0; i < facesArray.length; i++) {
Core.rectangle(mRgba, facesArray[i].tl(), facesArray[i].br(),
FACE_RECT_COLOR, 2);
xCenter = (facesArray[i].x + facesArray[i].width + facesArray[i].x) / 2;
yCenter = (facesArray[i].y + facesArray[i].y + facesArray[i].height) / 2;
Point center = new Point(xCenter, yCenter);
Rect r = facesArray[i];
// compute the eye area
Rect eyearea = new Rect(r.x + r.width / 20,
(int) (r.y + (r.height / 20)), r.width - 2 * r.width / 20,
(int) (r.height / 9.0));
// split it
Rect eyearea_right = new Rect(r.x + r.width / 6,
(int) (r.y + (r.height / 4)),
(r.width - 2 * r.width / 16) / 3, (int) (r.height / 4.0));
Rect eyearea_left = new Rect(r.x + r.width / 11
+ (r.width - 2 * r.width / 16) / 2,
(int) (r.y + (r.height / 4)),
(r.width - 2 * r.width / 16) / 3, (int) (r.height / 4.0));
// draw the area - mGray is working grayscale mat, if you want to
// see area in rgb preview, change mGray to mRgba
Core.rectangle(mRgba, eyearea_left.tl(), eyearea_left.br(),
new Scalar(255, 0, 0, 255), 2);
Core.rectangle(mRgba, eyearea_right.tl(), eyearea_right.br(),
new Scalar(255, 0, 0, 255), 2);
if (learn_frames < 5) {
teplateR = get_template(mJavaDetectorEye, eyearea_right, 24);
teplateL = get_template(mJavaDetectorEye, eyearea_left, 24);
learn_frames++;
} else {
// Learning finished, use the new templates for template
// matching
match_eye(eyearea_right, teplateR, method);
match_eye(eyearea_left, teplateL, method);
}
}
return mRgba;
}
```
Thanks in advance.
|
2015/04/12
|
[
"https://Stackoverflow.com/questions/29591304",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4216014/"
] |
What I did was that I converted the eye region from RGB to HSV and applied skin detection. I found out the range of skin color in HSV. If the percentage of skin pixels is greater than threshold value that means Eye is close otherwise it is open. Though there is still some accuracy issue due to amount of light present. Thank you all for giving me a start :)
|
Generally there is no obvious solution for this problem, but the number of approaches is quite big, so i'm sure that after a bit of serching you will find something good enough for you. For example you can use algorithm which i mentioned [here](https://stackoverflow.com/a/28811258/1598485) (there is a link to this question in "Related" btw - check other link from this group as well).
|
9,609,672
|
Is it possible to edit the text within a cell in datatables. So that when the user double clicks on the cell it becomes editable ?
Thanks
|
2012/03/07
|
[
"https://Stackoverflow.com/questions/9609672",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/470184/"
] |
No. I've seen all three. Personally, I use
```
if (!str[0])
```
Using strlen is a waste of processor time and not safe unless you can guarantee the string is terminated.
|
All of your examples are fine. It should be clear from the fact that all three are in your codebase that there is no "commonly agreed upon" method.
|
9,609,672
|
Is it possible to edit the text within a cell in datatables. So that when the user double clicks on the cell it becomes editable ?
Thanks
|
2012/03/07
|
[
"https://Stackoverflow.com/questions/9609672",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/470184/"
] |
1. `if(strlen(str) == 0)` -> it will **crash** if `str==NULL` (you need to check it before you use `strlen`)
2. `if(str[0] != 0)` -> the same as above
3. `if(!*str)` -> this is actually doing the same thing as **2)**
To summarise: if you want to do it safely:
```
if(!str || !(*str)) { /* empty string or NULL */ }
```
|
All of your examples are fine. It should be clear from the fact that all three are in your codebase that there is no "commonly agreed upon" method.
|
9,609,672
|
Is it possible to edit the text within a cell in datatables. So that when the user double clicks on the cell it becomes editable ?
Thanks
|
2012/03/07
|
[
"https://Stackoverflow.com/questions/9609672",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/470184/"
] |
If you already know that `str` is non-null:
```
if (!*str) {
// empty string
}
```
Otherwise:
```
if (!str || !*str) {
// empty string
}
```
Forget about `strlen()`.
|
All of your examples are fine. It should be clear from the fact that all three are in your codebase that there is no "commonly agreed upon" method.
|
9,609,672
|
Is it possible to edit the text within a cell in datatables. So that when the user double clicks on the cell it becomes editable ?
Thanks
|
2012/03/07
|
[
"https://Stackoverflow.com/questions/9609672",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/470184/"
] |
No. I've seen all three. Personally, I use
```
if (!str[0])
```
Using strlen is a waste of processor time and not safe unless you can guarantee the string is terminated.
|
I would definitely go with `strlen(str) == 0`, just for clarity.
The function should be implemented something like this:
```
int strlen(char *s) {
int len = 0;
while(*(s++)) len++;
return len;
}
```
so there will be no big overhead.
**Edit:** assuming you are sure that the string is actually zero terminated.
|
9,609,672
|
Is it possible to edit the text within a cell in datatables. So that when the user double clicks on the cell it becomes editable ?
Thanks
|
2012/03/07
|
[
"https://Stackoverflow.com/questions/9609672",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/470184/"
] |
No. I've seen all three. Personally, I use
```
if (!str[0])
```
Using strlen is a waste of processor time and not safe unless you can guarantee the string is terminated.
|
1. `if(strlen(str) == 0)` -> it will **crash** if `str==NULL` (you need to check it before you use `strlen`)
2. `if(str[0] != 0)` -> the same as above
3. `if(!*str)` -> this is actually doing the same thing as **2)**
To summarise: if you want to do it safely:
```
if(!str || !(*str)) { /* empty string or NULL */ }
```
|
9,609,672
|
Is it possible to edit the text within a cell in datatables. So that when the user double clicks on the cell it becomes editable ?
Thanks
|
2012/03/07
|
[
"https://Stackoverflow.com/questions/9609672",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/470184/"
] |
No. I've seen all three. Personally, I use
```
if (!str[0])
```
Using strlen is a waste of processor time and not safe unless you can guarantee the string is terminated.
|
If you already know that `str` is non-null:
```
if (!*str) {
// empty string
}
```
Otherwise:
```
if (!str || !*str) {
// empty string
}
```
Forget about `strlen()`.
|
9,609,672
|
Is it possible to edit the text within a cell in datatables. So that when the user double clicks on the cell it becomes editable ?
Thanks
|
2012/03/07
|
[
"https://Stackoverflow.com/questions/9609672",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/470184/"
] |
1. `if(strlen(str) == 0)` -> it will **crash** if `str==NULL` (you need to check it before you use `strlen`)
2. `if(str[0] != 0)` -> the same as above
3. `if(!*str)` -> this is actually doing the same thing as **2)**
To summarise: if you want to do it safely:
```
if(!str || !(*str)) { /* empty string or NULL */ }
```
|
I would definitely go with `strlen(str) == 0`, just for clarity.
The function should be implemented something like this:
```
int strlen(char *s) {
int len = 0;
while(*(s++)) len++;
return len;
}
```
so there will be no big overhead.
**Edit:** assuming you are sure that the string is actually zero terminated.
|
9,609,672
|
Is it possible to edit the text within a cell in datatables. So that when the user double clicks on the cell it becomes editable ?
Thanks
|
2012/03/07
|
[
"https://Stackoverflow.com/questions/9609672",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/470184/"
] |
If you already know that `str` is non-null:
```
if (!*str) {
// empty string
}
```
Otherwise:
```
if (!str || !*str) {
// empty string
}
```
Forget about `strlen()`.
|
I would definitely go with `strlen(str) == 0`, just for clarity.
The function should be implemented something like this:
```
int strlen(char *s) {
int len = 0;
while(*(s++)) len++;
return len;
}
```
so there will be no big overhead.
**Edit:** assuming you are sure that the string is actually zero terminated.
|
9,609,672
|
Is it possible to edit the text within a cell in datatables. So that when the user double clicks on the cell it becomes editable ?
Thanks
|
2012/03/07
|
[
"https://Stackoverflow.com/questions/9609672",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/470184/"
] |
1. `if(strlen(str) == 0)` -> it will **crash** if `str==NULL` (you need to check it before you use `strlen`)
2. `if(str[0] != 0)` -> the same as above
3. `if(!*str)` -> this is actually doing the same thing as **2)**
To summarise: if you want to do it safely:
```
if(!str || !(*str)) { /* empty string or NULL */ }
```
|
If you already know that `str` is non-null:
```
if (!*str) {
// empty string
}
```
Otherwise:
```
if (!str || !*str) {
// empty string
}
```
Forget about `strlen()`.
|
12,088
|
Which book is more a beginner to learn to program in c++ (or GML) and more fun: "Game Maker 8 Cookbook" (available for pre-order), or "The Game Maker's Companion" ?
|
2011/05/09
|
[
"https://gamedev.stackexchange.com/questions/12088",
"https://gamedev.stackexchange.com",
"https://gamedev.stackexchange.com/users/7193/"
] |
I created a game in Game Maker long ago, and was frustrated with the lack of control over many of the game elements. They try to take the programming out of game making. So I'm afraid you won't find Game Maker to be much help if you're trying to learn C++, or really programming in general.
I would recommend going with [Beginning C++ Through Game Programming, Third Edition](http://rads.stackoverflow.com/amzn/click/1435457420) if you want to achieve your intended goal.
|
I don't think either of them look all that great, and certainly they don't appear to teach C++ at all (focusing instead entirely on Game Maker and GML, it's internal language).
"Cookbook" style books tend to be more focused around isolated, individual techniques rather than providing a unifying educational "narrative," so I would shy away from the "Game Maker 8 Cookbook" entirely if that's what you are looking for.
Additionally, "The Game Maker's Companion" is a follow-up, so perhaps the first book in the series, [The Game Maker's Apprentice](http://rads.stackoverflow.com/amzn/click/1590596153) is a better choice overall.
|
12,088
|
Which book is more a beginner to learn to program in c++ (or GML) and more fun: "Game Maker 8 Cookbook" (available for pre-order), or "The Game Maker's Companion" ?
|
2011/05/09
|
[
"https://gamedev.stackexchange.com/questions/12088",
"https://gamedev.stackexchange.com",
"https://gamedev.stackexchange.com/users/7193/"
] |
I created a game in Game Maker long ago, and was frustrated with the lack of control over many of the game elements. They try to take the programming out of game making. So I'm afraid you won't find Game Maker to be much help if you're trying to learn C++, or really programming in general.
I would recommend going with [Beginning C++ Through Game Programming, Third Edition](http://rads.stackoverflow.com/amzn/click/1435457420) if you want to achieve your intended goal.
|
Both books will teach you Game Maker's drag and drop, neither will teach you C++.
Im not sure if the cookbook teaches you GML, though i know the companion does.
Both books have their own style of teaching. So on that matter, purely subjective.
The Cookbook is slightly cheaper (thought not much)
The Companion is out already.
The companion might (i'm not positive) require you to get the game makers apprentice as well.
Overall i would say companion. The sooner the better, and it will teach everything you need to get started. The Game Makers apprentice might be needed first though.
And regarding C++... Well thats a totally different area. If you want to jump straight into it, neither of these books will help. However if you want to learn the basics of using logic to do things before delving into the details of the language, well it might help to learn GML first.
|
9,434,956
|
So my CoreData model has one entity for the time being. It has several attributes, for testing purpose I set these attributes in the applicationdidfinishlaunching method. As soon as I set an NSNumber (Integer 16 or float) attribute it gets a EXC\_BAD\_ACCESS exception.
The string attributes work and gets stored, I tested this with a fetch.
If I set the Integer 16 number to 0 it does not crash but I guess it's because it gets assigned nil then.
**Core data NSManagedObject created by xcode:**
```
#import <Foundation/Foundation.h>
#import <CoreData/CoreData.h>
@interface ReminderSchedule : NSManagedObject
@property (nonatomic, retain) NSNumber * intervalSize;
@property (nonatomic, retain) NSNumber * intervalType;
@property (nonatomic, retain) NSString * name;
@property (nonatomic, retain) NSNumber * quantity;
@property (nonatomic, retain) NSDate * startDate;
@property (nonatomic, retain) NSNumber * unit;
@end
```
**Inside the applicationdidfinishlaunching method in the appdelegate**
```
ReminderSchedule *reminderSchedule;
reminderSchedule = [NSEntityDescription insertNewObjectForEntityForName:@"ReminderSchedule" inManagedObjectContext:self.managedObjectContext];
reminderSchedule.unit = 1; <==== EXC_BAD_ACCESS
reminderSchedule.quantity = 4.0f; <==== EXC_BAD_ACCESS
reminderSchedule.name = @"this works";
reminderSchedule.intervalType = 2; <==== EXC_BAD_ACCESS
reminderSchedule.intervalSize = 2; <==== EXC_BAD_ACCESS
[self.managedObjectContext save:nil]; //just for testing, never gets here
```
|
2012/02/24
|
[
"https://Stackoverflow.com/questions/9434956",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/871561/"
] |
You are passing in an 'int' and not an NSNumber.
Try this:
```
reminderSchedule.unit = [NSNumber numberWithInt:1]; // this won't crash
```
You can also reformat your @property to NSInteger. This will allow you to pass in a straight integer.
|
```
reminderSchedule.unit = [NSNumber numberWithInt:1];
```
This will save an NSObject of type: NSNumber, rather than a raw integer.
|
9,434,956
|
So my CoreData model has one entity for the time being. It has several attributes, for testing purpose I set these attributes in the applicationdidfinishlaunching method. As soon as I set an NSNumber (Integer 16 or float) attribute it gets a EXC\_BAD\_ACCESS exception.
The string attributes work and gets stored, I tested this with a fetch.
If I set the Integer 16 number to 0 it does not crash but I guess it's because it gets assigned nil then.
**Core data NSManagedObject created by xcode:**
```
#import <Foundation/Foundation.h>
#import <CoreData/CoreData.h>
@interface ReminderSchedule : NSManagedObject
@property (nonatomic, retain) NSNumber * intervalSize;
@property (nonatomic, retain) NSNumber * intervalType;
@property (nonatomic, retain) NSString * name;
@property (nonatomic, retain) NSNumber * quantity;
@property (nonatomic, retain) NSDate * startDate;
@property (nonatomic, retain) NSNumber * unit;
@end
```
**Inside the applicationdidfinishlaunching method in the appdelegate**
```
ReminderSchedule *reminderSchedule;
reminderSchedule = [NSEntityDescription insertNewObjectForEntityForName:@"ReminderSchedule" inManagedObjectContext:self.managedObjectContext];
reminderSchedule.unit = 1; <==== EXC_BAD_ACCESS
reminderSchedule.quantity = 4.0f; <==== EXC_BAD_ACCESS
reminderSchedule.name = @"this works";
reminderSchedule.intervalType = 2; <==== EXC_BAD_ACCESS
reminderSchedule.intervalSize = 2; <==== EXC_BAD_ACCESS
[self.managedObjectContext save:nil]; //just for testing, never gets here
```
|
2012/02/24
|
[
"https://Stackoverflow.com/questions/9434956",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/871561/"
] |
If any of them need to be doubles you can wrap them in an NSNumber object like this:
```
reminderSchedule.quantity = [NSNumber numberWithDouble:(double)]];
```
just declare the double first.
|
```
reminderSchedule.unit = [NSNumber numberWithInt:1];
```
This will save an NSObject of type: NSNumber, rather than a raw integer.
|
1,565,826
|
High School student here. I have been trying to derive a formula for an egg shaped curve. There are plenty of examples of egg shaped curves in the internet. Apparently it is a common topic.
I noticed Mr. Itou's approach for said curve as a section made by cutting a Pseudo-sphere by means of inclined plane. ([link](http://www.geocities.jp/nyjp07/index_egg_by_Itou_E.html), bottom of the page). I did not see the advantage in using a pseudo-sphere instead of a simpler surface.
I decided to do something similar, but starting with an hyperbolic funnel (Surface of revolution made by rotating a hyperbola in the ZY plane arround the Z-axis).
I wrote the equation, and after the rotation I obtained this parametric equation:
$$
\begin{cases} & x = t\sin s\\ & y = t\cos s \\ & z = 1/t \end{cases}
$$
After eliminating the parameters (using the pitagorean identity) I arrive at the following equation:
$x^{2}y^{2}+z^{2}y^{2}-1=0$
After solving for z, and plot for ${z \in \mathbb{R}:z>0}$ I got:
[Function plot](https://i.stack.imgur.com/MHWDJ.gif)
Now I would like to intersect the surface with an inclined plane to obtain my egg shaped curve. Then I would rotate the $P(x,y,z)$ to the XY plane to get a function $f(x)$.
I have no idea how to do this (obtaining the curve equation)
I tried equating both expressions (the surface and the plane) but when I plot it I get a strange curve. I tried to intersect it with the plane $z=3$ but instead of a circle I get something resembling a Gaussian curve reflected on the x-axis.
$x^{2}y^{2}+z^{2}y^{2}-z-1=0$
I have some knowledge in linear algebra and working with planes, lines in $R^{3}$.
I made the intersection by hand (technical drawing is pretty useful :) so I know that my original equations are right.
Any hints on how to get the function of the intersection?
|
2015/12/08
|
[
"https://math.stackexchange.com/questions/1565826",
"https://math.stackexchange.com",
"https://math.stackexchange.com/users/296974/"
] |
You show that $x<\tan x$ when $0<x<\pi/2$ by taking the path:
$$(\cos 2x,\sin 2x),(1,\tan x),(1,0)$$
This path, aside from the endpoints, is outside the unit disk. The two segments are tangent to the circle. There is a theorem which says that therefore it has to be longer than the shortest arc on the boundary of the unit disk. I [asked a question about this a while back](https://math.stackexchange.com/questions/125975/shortest-paths-between-points-on-the-boundary-of-a-convex-set) - it is a result of the Hahn Banach theorem.
So this path, of length $2\tan x$, is greater than or equal to the path on the circle, $2x$.
(That $\sin x\leq x$ is due to a simpler rule - the shortest path from a point to a line, is the perpendicular from the point to the line.)
|
You can also note that (for small, positive $x$) we have $$\sin(x)<x<\tan(x)$$then divide through by $\sin(x)$ and squeeze. This gives the limit of $\frac{x}{\sin x}$.
|
1,565,826
|
High School student here. I have been trying to derive a formula for an egg shaped curve. There are plenty of examples of egg shaped curves in the internet. Apparently it is a common topic.
I noticed Mr. Itou's approach for said curve as a section made by cutting a Pseudo-sphere by means of inclined plane. ([link](http://www.geocities.jp/nyjp07/index_egg_by_Itou_E.html), bottom of the page). I did not see the advantage in using a pseudo-sphere instead of a simpler surface.
I decided to do something similar, but starting with an hyperbolic funnel (Surface of revolution made by rotating a hyperbola in the ZY plane arround the Z-axis).
I wrote the equation, and after the rotation I obtained this parametric equation:
$$
\begin{cases} & x = t\sin s\\ & y = t\cos s \\ & z = 1/t \end{cases}
$$
After eliminating the parameters (using the pitagorean identity) I arrive at the following equation:
$x^{2}y^{2}+z^{2}y^{2}-1=0$
After solving for z, and plot for ${z \in \mathbb{R}:z>0}$ I got:
[Function plot](https://i.stack.imgur.com/MHWDJ.gif)
Now I would like to intersect the surface with an inclined plane to obtain my egg shaped curve. Then I would rotate the $P(x,y,z)$ to the XY plane to get a function $f(x)$.
I have no idea how to do this (obtaining the curve equation)
I tried equating both expressions (the surface and the plane) but when I plot it I get a strange curve. I tried to intersect it with the plane $z=3$ but instead of a circle I get something resembling a Gaussian curve reflected on the x-axis.
$x^{2}y^{2}+z^{2}y^{2}-z-1=0$
I have some knowledge in linear algebra and working with planes, lines in $R^{3}$.
I made the intersection by hand (technical drawing is pretty useful :) so I know that my original equations are right.
Any hints on how to get the function of the intersection?
|
2015/12/08
|
[
"https://math.stackexchange.com/questions/1565826",
"https://math.stackexchange.com",
"https://math.stackexchange.com/users/296974/"
] |
I don't see anything circular in comparing areas to get the inequality $\sin x < x < \tan x$ for $0 < x < \pi/2$. However we need to be very cautious in defining the symbols $\sin x, \tan x$ properly given $x$ a real number.
The approach based on areas goes like this. Using the concept of definite integrals it can be proven that a sector of a circle has an area. This does not require anything beyond the continuity of the function $\sqrt{1 - x^{2}}$ in interval $[0, 1]$. In particular justification of the area of a circle is not dependent on the definition of trigonometric functions and $\pi$.
Next consider a unit circle with origin $O$ as center and let $A$ be the point $(1, 0)$. Let $P$ be any point on the circle. For our purposes it is sufficient to consider $P$ to be in first quadrant. Let the area of sector $AOP$ be $y$ so that $y > 0$. Also let $x = 2y$ and then **by definition the point $P$ is $(\cos x, \sin x)$.** This is the usual definition of trigonometric functions as studied at the age of 15 years or so.
Note that some textbooks base the definition of $\sin x, \cos x$ on the basis of length of arc $AP$ which is $x$. The definition is equivalent to the one based on areas of sectors, but comparing areas of figures is simpler than comparing the length of arcs (at least in this context). Consider the tangent $AT$ to unit circle at point $A$ such that $OPT$ is a line segment. Also let $PB$ be a perpendicular to $OA$ and $B$ is the foot of this perpendicular. Now it is easy to show that $$\text {area of }\Delta AOP < \text{ area of sector }AOP < \text{ area of }\Delta AOT$$ (because each region is contained in the next). However it is very difficult to compare the length of arc $AP$ with the length of line segments $PB$ and $AT$ (because there is no containment here).
The above inequality leads to $$\sin x < x < \tan x$$ from which we get $\sin x \to 0$ as $x \to 0$ and then $\cos x = \sqrt{1 - \sin^{2}x} \to 1$. Further the inequality is equivalent to $$\cos x < \frac{\sin x}{x} < 1$$ and hence $(\sin x)/x \to 1$ as $x \to 0$.
---
**Update**: It appears from OP's comments that the relation between length of an arc of a circle and area of corresponding sector is something which can't be proven without using any analytic properties of circular functions. However this is not the case.
Let $P = (a, b)$ be a point on unit circle $x^{2} + y^{2} = 1$ and let $A = (1, 0)$. For simplicity let's consider $P$ in first quadrant so that $a, b$ are positive. Then the length of arc $AP$ is given by $$L = \int\_{a}^{1}\sqrt{1 + y'^{2}}\,dx = \int\_{a}^{1}\frac{dx}{\sqrt{1 - x^{2}}}$$ The area of the sector $AOP$ is given by $$A = \frac{ab}{2} + \int\_{a}^{1}\sqrt{1 - x^{2}}\,dx$$ We need to prove that $L = 2A$. We will do this using the fact that $b = \sqrt{1 - a^{2}}$ and using integration by parts.
We have
\begin{align}
\int\sqrt{1 - x^{2}}\,dx &= x\sqrt{1 - x^{2}} - \int x\cdot\frac{-x}{\sqrt{1 - x^{2}}}\,dx\notag\\
&= x\sqrt{1 - x^{2}} - \int \frac{1 - x^{2} - 1}{\sqrt{1 - x^{2}}}\,dx\notag\\
&= x\sqrt{1 - x^{2}} - \int \sqrt{1 - x^{2}}\,dx + \int \frac{1}{\sqrt{1 - x^{2}}}\,dx\notag\\
\Rightarrow \int\sqrt{1 - x^{2}}\,dx &= \frac{x\sqrt{1 - x^{2}}}{2} + \frac{1}{2}\int \frac{dx}{\sqrt{1 - x^{2}}}\notag\\
\end{align}
Hence $$\int\_{a}^{1}\sqrt{1 - x^{2}}\,dx = - \frac{a\sqrt{1 - a^{2}}}{2} + \frac{1}{2}\int\_{a}^{1}\frac{dx}{\sqrt{1 - x^{2}}}$$ or $$\int\_{a}^{1}\frac{dx}{\sqrt{1 - x^{2}}} = 2\left(\frac{ab}{2} + \int\_{a}^{1}\sqrt{1 - x^{2}}\,dx\right)$$ or $L = 2A$ which was to be proved.
Contrast the above proof of relation between length and area with the following totally non-rigorous proof. Let the length of arc $AP$ be $L$. Then the angle subtended by it at the center is also $L$ (definition of radian measure). Divide this angle into $n$ parts of measure $L/n$ each and then the area of sector $AOP$ is sum of areas of these $n$ sectors. If $n$ is large then area of each of these $n$ sectors can be approximated by area of the corresponding triangles and this area is $$\frac{1}{2}\sin (L/n)$$ so that the area of the whole sector $AOP$ is $(n/2)\sin(L/n)$. As $n \to \infty$ this becomes $L/2$ and here we need the analytic property of $\sin x$ namely $(\sin x)/x \to 1$ as $x \to 0$. Therefore area can't be the basis of a proof of this limit. This is perhaps the reason that proofs for limit formula $(\sin x)/x \to 1$ looks circular.
A proper proof can't be done without integrals as I have shown above. Hence the proof that $(\sin x)/x \to 1$ depends upon Riemann integration and definition of $\sin x, \cos x$ as inverses to the integrals. This is same as $e^{x}$ is defined as inverse to integral of $1/x$.
Also see [my another answer to a similar question](https://math.stackexchange.com/a/1001053/72031).
|
You can also note that (for small, positive $x$) we have $$\sin(x)<x<\tan(x)$$then divide through by $\sin(x)$ and squeeze. This gives the limit of $\frac{x}{\sin x}$.
|
1,565,826
|
High School student here. I have been trying to derive a formula for an egg shaped curve. There are plenty of examples of egg shaped curves in the internet. Apparently it is a common topic.
I noticed Mr. Itou's approach for said curve as a section made by cutting a Pseudo-sphere by means of inclined plane. ([link](http://www.geocities.jp/nyjp07/index_egg_by_Itou_E.html), bottom of the page). I did not see the advantage in using a pseudo-sphere instead of a simpler surface.
I decided to do something similar, but starting with an hyperbolic funnel (Surface of revolution made by rotating a hyperbola in the ZY plane arround the Z-axis).
I wrote the equation, and after the rotation I obtained this parametric equation:
$$
\begin{cases} & x = t\sin s\\ & y = t\cos s \\ & z = 1/t \end{cases}
$$
After eliminating the parameters (using the pitagorean identity) I arrive at the following equation:
$x^{2}y^{2}+z^{2}y^{2}-1=0$
After solving for z, and plot for ${z \in \mathbb{R}:z>0}$ I got:
[Function plot](https://i.stack.imgur.com/MHWDJ.gif)
Now I would like to intersect the surface with an inclined plane to obtain my egg shaped curve. Then I would rotate the $P(x,y,z)$ to the XY plane to get a function $f(x)$.
I have no idea how to do this (obtaining the curve equation)
I tried equating both expressions (the surface and the plane) but when I plot it I get a strange curve. I tried to intersect it with the plane $z=3$ but instead of a circle I get something resembling a Gaussian curve reflected on the x-axis.
$x^{2}y^{2}+z^{2}y^{2}-z-1=0$
I have some knowledge in linear algebra and working with planes, lines in $R^{3}$.
I made the intersection by hand (technical drawing is pretty useful :) so I know that my original equations are right.
Any hints on how to get the function of the intersection?
|
2015/12/08
|
[
"https://math.stackexchange.com/questions/1565826",
"https://math.stackexchange.com",
"https://math.stackexchange.com/users/296974/"
] |
You show that $x<\tan x$ when $0<x<\pi/2$ by taking the path:
$$(\cos 2x,\sin 2x),(1,\tan x),(1,0)$$
This path, aside from the endpoints, is outside the unit disk. The two segments are tangent to the circle. There is a theorem which says that therefore it has to be longer than the shortest arc on the boundary of the unit disk. I [asked a question about this a while back](https://math.stackexchange.com/questions/125975/shortest-paths-between-points-on-the-boundary-of-a-convex-set) - it is a result of the Hahn Banach theorem.
So this path, of length $2\tan x$, is greater than or equal to the path on the circle, $2x$.
(That $\sin x\leq x$ is due to a simpler rule - the shortest path from a point to a line, is the perpendicular from the point to the line.)
|
$\sin x$ is easy to define, but not $x$! You won't find a more elementary
rigorous definition of the $\sin$ function other that is the inverse of
the $\sin^{-1}$ function, where $\sin^{-1} y$ is defined for not too large
$y$ as the length of the arc in the circle between $(1, 0)$ and
$(\sqrt{(1-y^2)}, y)$. This is just the completely elementary definition
with the units for the angle actually defined. It is not elementary
enough for a first course since it uses inverse functions. The existence
of the arc length can be hand-waved and the coordinates not stated in a
first course.
Rigorously defining arc lengths needs a limit operation. Fairly
elementary calculus gives the formula for the arc length of a circle:
$$\sin^{-1} y = \int ^y \_0 \frac{dt}{\sqrt{(1-t^2)}}.$$ Note that
this is not circular; it is the definition of $\sin^{-1}$ and thus of
$\sin$.
The value of the limit is obvious from this formula using elementary
calculus. Note that I haven't done anything complicated like evaluating
the integral. Other properties of the $\sin$ function can be derived,
not so easily, from this definition. $\pi$ is by definition the length
of a half-circle, and thus twice the value of this integral from $0$ to
$1$, whatever that may be. Since the integral becomes improper at
$y = 1$, better define $\pi$ using half of the first quadrant instead
of all of it to minimize the calculus.
This is easier, at least for analysts, to understand after studying
elliptic functions and elliptic integrals. Change $t^2$ to $t^3$ in
the integral and the integral becomes elliptic. There is no geometry of
the circle or arc length to help or confuse you in understanding this
integral. The inverse of the elliptic integral is an elliptic
(doubly periodic) function. This is much less easy to see and prove
rigorously from the integral than that $sin$ is singly periodic. Other properties of elliptic functions are even harder to see and prove
starting from the integral.
|
1,565,826
|
High School student here. I have been trying to derive a formula for an egg shaped curve. There are plenty of examples of egg shaped curves in the internet. Apparently it is a common topic.
I noticed Mr. Itou's approach for said curve as a section made by cutting a Pseudo-sphere by means of inclined plane. ([link](http://www.geocities.jp/nyjp07/index_egg_by_Itou_E.html), bottom of the page). I did not see the advantage in using a pseudo-sphere instead of a simpler surface.
I decided to do something similar, but starting with an hyperbolic funnel (Surface of revolution made by rotating a hyperbola in the ZY plane arround the Z-axis).
I wrote the equation, and after the rotation I obtained this parametric equation:
$$
\begin{cases} & x = t\sin s\\ & y = t\cos s \\ & z = 1/t \end{cases}
$$
After eliminating the parameters (using the pitagorean identity) I arrive at the following equation:
$x^{2}y^{2}+z^{2}y^{2}-1=0$
After solving for z, and plot for ${z \in \mathbb{R}:z>0}$ I got:
[Function plot](https://i.stack.imgur.com/MHWDJ.gif)
Now I would like to intersect the surface with an inclined plane to obtain my egg shaped curve. Then I would rotate the $P(x,y,z)$ to the XY plane to get a function $f(x)$.
I have no idea how to do this (obtaining the curve equation)
I tried equating both expressions (the surface and the plane) but when I plot it I get a strange curve. I tried to intersect it with the plane $z=3$ but instead of a circle I get something resembling a Gaussian curve reflected on the x-axis.
$x^{2}y^{2}+z^{2}y^{2}-z-1=0$
I have some knowledge in linear algebra and working with planes, lines in $R^{3}$.
I made the intersection by hand (technical drawing is pretty useful :) so I know that my original equations are right.
Any hints on how to get the function of the intersection?
|
2015/12/08
|
[
"https://math.stackexchange.com/questions/1565826",
"https://math.stackexchange.com",
"https://math.stackexchange.com/users/296974/"
] |
I don't see anything circular in comparing areas to get the inequality $\sin x < x < \tan x$ for $0 < x < \pi/2$. However we need to be very cautious in defining the symbols $\sin x, \tan x$ properly given $x$ a real number.
The approach based on areas goes like this. Using the concept of definite integrals it can be proven that a sector of a circle has an area. This does not require anything beyond the continuity of the function $\sqrt{1 - x^{2}}$ in interval $[0, 1]$. In particular justification of the area of a circle is not dependent on the definition of trigonometric functions and $\pi$.
Next consider a unit circle with origin $O$ as center and let $A$ be the point $(1, 0)$. Let $P$ be any point on the circle. For our purposes it is sufficient to consider $P$ to be in first quadrant. Let the area of sector $AOP$ be $y$ so that $y > 0$. Also let $x = 2y$ and then **by definition the point $P$ is $(\cos x, \sin x)$.** This is the usual definition of trigonometric functions as studied at the age of 15 years or so.
Note that some textbooks base the definition of $\sin x, \cos x$ on the basis of length of arc $AP$ which is $x$. The definition is equivalent to the one based on areas of sectors, but comparing areas of figures is simpler than comparing the length of arcs (at least in this context). Consider the tangent $AT$ to unit circle at point $A$ such that $OPT$ is a line segment. Also let $PB$ be a perpendicular to $OA$ and $B$ is the foot of this perpendicular. Now it is easy to show that $$\text {area of }\Delta AOP < \text{ area of sector }AOP < \text{ area of }\Delta AOT$$ (because each region is contained in the next). However it is very difficult to compare the length of arc $AP$ with the length of line segments $PB$ and $AT$ (because there is no containment here).
The above inequality leads to $$\sin x < x < \tan x$$ from which we get $\sin x \to 0$ as $x \to 0$ and then $\cos x = \sqrt{1 - \sin^{2}x} \to 1$. Further the inequality is equivalent to $$\cos x < \frac{\sin x}{x} < 1$$ and hence $(\sin x)/x \to 1$ as $x \to 0$.
---
**Update**: It appears from OP's comments that the relation between length of an arc of a circle and area of corresponding sector is something which can't be proven without using any analytic properties of circular functions. However this is not the case.
Let $P = (a, b)$ be a point on unit circle $x^{2} + y^{2} = 1$ and let $A = (1, 0)$. For simplicity let's consider $P$ in first quadrant so that $a, b$ are positive. Then the length of arc $AP$ is given by $$L = \int\_{a}^{1}\sqrt{1 + y'^{2}}\,dx = \int\_{a}^{1}\frac{dx}{\sqrt{1 - x^{2}}}$$ The area of the sector $AOP$ is given by $$A = \frac{ab}{2} + \int\_{a}^{1}\sqrt{1 - x^{2}}\,dx$$ We need to prove that $L = 2A$. We will do this using the fact that $b = \sqrt{1 - a^{2}}$ and using integration by parts.
We have
\begin{align}
\int\sqrt{1 - x^{2}}\,dx &= x\sqrt{1 - x^{2}} - \int x\cdot\frac{-x}{\sqrt{1 - x^{2}}}\,dx\notag\\
&= x\sqrt{1 - x^{2}} - \int \frac{1 - x^{2} - 1}{\sqrt{1 - x^{2}}}\,dx\notag\\
&= x\sqrt{1 - x^{2}} - \int \sqrt{1 - x^{2}}\,dx + \int \frac{1}{\sqrt{1 - x^{2}}}\,dx\notag\\
\Rightarrow \int\sqrt{1 - x^{2}}\,dx &= \frac{x\sqrt{1 - x^{2}}}{2} + \frac{1}{2}\int \frac{dx}{\sqrt{1 - x^{2}}}\notag\\
\end{align}
Hence $$\int\_{a}^{1}\sqrt{1 - x^{2}}\,dx = - \frac{a\sqrt{1 - a^{2}}}{2} + \frac{1}{2}\int\_{a}^{1}\frac{dx}{\sqrt{1 - x^{2}}}$$ or $$\int\_{a}^{1}\frac{dx}{\sqrt{1 - x^{2}}} = 2\left(\frac{ab}{2} + \int\_{a}^{1}\sqrt{1 - x^{2}}\,dx\right)$$ or $L = 2A$ which was to be proved.
Contrast the above proof of relation between length and area with the following totally non-rigorous proof. Let the length of arc $AP$ be $L$. Then the angle subtended by it at the center is also $L$ (definition of radian measure). Divide this angle into $n$ parts of measure $L/n$ each and then the area of sector $AOP$ is sum of areas of these $n$ sectors. If $n$ is large then area of each of these $n$ sectors can be approximated by area of the corresponding triangles and this area is $$\frac{1}{2}\sin (L/n)$$ so that the area of the whole sector $AOP$ is $(n/2)\sin(L/n)$. As $n \to \infty$ this becomes $L/2$ and here we need the analytic property of $\sin x$ namely $(\sin x)/x \to 1$ as $x \to 0$. Therefore area can't be the basis of a proof of this limit. This is perhaps the reason that proofs for limit formula $(\sin x)/x \to 1$ looks circular.
A proper proof can't be done without integrals as I have shown above. Hence the proof that $(\sin x)/x \to 1$ depends upon Riemann integration and definition of $\sin x, \cos x$ as inverses to the integrals. This is same as $e^{x}$ is defined as inverse to integral of $1/x$.
Also see [my another answer to a similar question](https://math.stackexchange.com/a/1001053/72031).
|
You show that $x<\tan x$ when $0<x<\pi/2$ by taking the path:
$$(\cos 2x,\sin 2x),(1,\tan x),(1,0)$$
This path, aside from the endpoints, is outside the unit disk. The two segments are tangent to the circle. There is a theorem which says that therefore it has to be longer than the shortest arc on the boundary of the unit disk. I [asked a question about this a while back](https://math.stackexchange.com/questions/125975/shortest-paths-between-points-on-the-boundary-of-a-convex-set) - it is a result of the Hahn Banach theorem.
So this path, of length $2\tan x$, is greater than or equal to the path on the circle, $2x$.
(That $\sin x\leq x$ is due to a simpler rule - the shortest path from a point to a line, is the perpendicular from the point to the line.)
|
1,565,826
|
High School student here. I have been trying to derive a formula for an egg shaped curve. There are plenty of examples of egg shaped curves in the internet. Apparently it is a common topic.
I noticed Mr. Itou's approach for said curve as a section made by cutting a Pseudo-sphere by means of inclined plane. ([link](http://www.geocities.jp/nyjp07/index_egg_by_Itou_E.html), bottom of the page). I did not see the advantage in using a pseudo-sphere instead of a simpler surface.
I decided to do something similar, but starting with an hyperbolic funnel (Surface of revolution made by rotating a hyperbola in the ZY plane arround the Z-axis).
I wrote the equation, and after the rotation I obtained this parametric equation:
$$
\begin{cases} & x = t\sin s\\ & y = t\cos s \\ & z = 1/t \end{cases}
$$
After eliminating the parameters (using the pitagorean identity) I arrive at the following equation:
$x^{2}y^{2}+z^{2}y^{2}-1=0$
After solving for z, and plot for ${z \in \mathbb{R}:z>0}$ I got:
[Function plot](https://i.stack.imgur.com/MHWDJ.gif)
Now I would like to intersect the surface with an inclined plane to obtain my egg shaped curve. Then I would rotate the $P(x,y,z)$ to the XY plane to get a function $f(x)$.
I have no idea how to do this (obtaining the curve equation)
I tried equating both expressions (the surface and the plane) but when I plot it I get a strange curve. I tried to intersect it with the plane $z=3$ but instead of a circle I get something resembling a Gaussian curve reflected on the x-axis.
$x^{2}y^{2}+z^{2}y^{2}-z-1=0$
I have some knowledge in linear algebra and working with planes, lines in $R^{3}$.
I made the intersection by hand (technical drawing is pretty useful :) so I know that my original equations are right.
Any hints on how to get the function of the intersection?
|
2015/12/08
|
[
"https://math.stackexchange.com/questions/1565826",
"https://math.stackexchange.com",
"https://math.stackexchange.com/users/296974/"
] |
I don't see anything circular in comparing areas to get the inequality $\sin x < x < \tan x$ for $0 < x < \pi/2$. However we need to be very cautious in defining the symbols $\sin x, \tan x$ properly given $x$ a real number.
The approach based on areas goes like this. Using the concept of definite integrals it can be proven that a sector of a circle has an area. This does not require anything beyond the continuity of the function $\sqrt{1 - x^{2}}$ in interval $[0, 1]$. In particular justification of the area of a circle is not dependent on the definition of trigonometric functions and $\pi$.
Next consider a unit circle with origin $O$ as center and let $A$ be the point $(1, 0)$. Let $P$ be any point on the circle. For our purposes it is sufficient to consider $P$ to be in first quadrant. Let the area of sector $AOP$ be $y$ so that $y > 0$. Also let $x = 2y$ and then **by definition the point $P$ is $(\cos x, \sin x)$.** This is the usual definition of trigonometric functions as studied at the age of 15 years or so.
Note that some textbooks base the definition of $\sin x, \cos x$ on the basis of length of arc $AP$ which is $x$. The definition is equivalent to the one based on areas of sectors, but comparing areas of figures is simpler than comparing the length of arcs (at least in this context). Consider the tangent $AT$ to unit circle at point $A$ such that $OPT$ is a line segment. Also let $PB$ be a perpendicular to $OA$ and $B$ is the foot of this perpendicular. Now it is easy to show that $$\text {area of }\Delta AOP < \text{ area of sector }AOP < \text{ area of }\Delta AOT$$ (because each region is contained in the next). However it is very difficult to compare the length of arc $AP$ with the length of line segments $PB$ and $AT$ (because there is no containment here).
The above inequality leads to $$\sin x < x < \tan x$$ from which we get $\sin x \to 0$ as $x \to 0$ and then $\cos x = \sqrt{1 - \sin^{2}x} \to 1$. Further the inequality is equivalent to $$\cos x < \frac{\sin x}{x} < 1$$ and hence $(\sin x)/x \to 1$ as $x \to 0$.
---
**Update**: It appears from OP's comments that the relation between length of an arc of a circle and area of corresponding sector is something which can't be proven without using any analytic properties of circular functions. However this is not the case.
Let $P = (a, b)$ be a point on unit circle $x^{2} + y^{2} = 1$ and let $A = (1, 0)$. For simplicity let's consider $P$ in first quadrant so that $a, b$ are positive. Then the length of arc $AP$ is given by $$L = \int\_{a}^{1}\sqrt{1 + y'^{2}}\,dx = \int\_{a}^{1}\frac{dx}{\sqrt{1 - x^{2}}}$$ The area of the sector $AOP$ is given by $$A = \frac{ab}{2} + \int\_{a}^{1}\sqrt{1 - x^{2}}\,dx$$ We need to prove that $L = 2A$. We will do this using the fact that $b = \sqrt{1 - a^{2}}$ and using integration by parts.
We have
\begin{align}
\int\sqrt{1 - x^{2}}\,dx &= x\sqrt{1 - x^{2}} - \int x\cdot\frac{-x}{\sqrt{1 - x^{2}}}\,dx\notag\\
&= x\sqrt{1 - x^{2}} - \int \frac{1 - x^{2} - 1}{\sqrt{1 - x^{2}}}\,dx\notag\\
&= x\sqrt{1 - x^{2}} - \int \sqrt{1 - x^{2}}\,dx + \int \frac{1}{\sqrt{1 - x^{2}}}\,dx\notag\\
\Rightarrow \int\sqrt{1 - x^{2}}\,dx &= \frac{x\sqrt{1 - x^{2}}}{2} + \frac{1}{2}\int \frac{dx}{\sqrt{1 - x^{2}}}\notag\\
\end{align}
Hence $$\int\_{a}^{1}\sqrt{1 - x^{2}}\,dx = - \frac{a\sqrt{1 - a^{2}}}{2} + \frac{1}{2}\int\_{a}^{1}\frac{dx}{\sqrt{1 - x^{2}}}$$ or $$\int\_{a}^{1}\frac{dx}{\sqrt{1 - x^{2}}} = 2\left(\frac{ab}{2} + \int\_{a}^{1}\sqrt{1 - x^{2}}\,dx\right)$$ or $L = 2A$ which was to be proved.
Contrast the above proof of relation between length and area with the following totally non-rigorous proof. Let the length of arc $AP$ be $L$. Then the angle subtended by it at the center is also $L$ (definition of radian measure). Divide this angle into $n$ parts of measure $L/n$ each and then the area of sector $AOP$ is sum of areas of these $n$ sectors. If $n$ is large then area of each of these $n$ sectors can be approximated by area of the corresponding triangles and this area is $$\frac{1}{2}\sin (L/n)$$ so that the area of the whole sector $AOP$ is $(n/2)\sin(L/n)$. As $n \to \infty$ this becomes $L/2$ and here we need the analytic property of $\sin x$ namely $(\sin x)/x \to 1$ as $x \to 0$. Therefore area can't be the basis of a proof of this limit. This is perhaps the reason that proofs for limit formula $(\sin x)/x \to 1$ looks circular.
A proper proof can't be done without integrals as I have shown above. Hence the proof that $(\sin x)/x \to 1$ depends upon Riemann integration and definition of $\sin x, \cos x$ as inverses to the integrals. This is same as $e^{x}$ is defined as inverse to integral of $1/x$.
Also see [my another answer to a similar question](https://math.stackexchange.com/a/1001053/72031).
|
$\sin x$ is easy to define, but not $x$! You won't find a more elementary
rigorous definition of the $\sin$ function other that is the inverse of
the $\sin^{-1}$ function, where $\sin^{-1} y$ is defined for not too large
$y$ as the length of the arc in the circle between $(1, 0)$ and
$(\sqrt{(1-y^2)}, y)$. This is just the completely elementary definition
with the units for the angle actually defined. It is not elementary
enough for a first course since it uses inverse functions. The existence
of the arc length can be hand-waved and the coordinates not stated in a
first course.
Rigorously defining arc lengths needs a limit operation. Fairly
elementary calculus gives the formula for the arc length of a circle:
$$\sin^{-1} y = \int ^y \_0 \frac{dt}{\sqrt{(1-t^2)}}.$$ Note that
this is not circular; it is the definition of $\sin^{-1}$ and thus of
$\sin$.
The value of the limit is obvious from this formula using elementary
calculus. Note that I haven't done anything complicated like evaluating
the integral. Other properties of the $\sin$ function can be derived,
not so easily, from this definition. $\pi$ is by definition the length
of a half-circle, and thus twice the value of this integral from $0$ to
$1$, whatever that may be. Since the integral becomes improper at
$y = 1$, better define $\pi$ using half of the first quadrant instead
of all of it to minimize the calculus.
This is easier, at least for analysts, to understand after studying
elliptic functions and elliptic integrals. Change $t^2$ to $t^3$ in
the integral and the integral becomes elliptic. There is no geometry of
the circle or arc length to help or confuse you in understanding this
integral. The inverse of the elliptic integral is an elliptic
(doubly periodic) function. This is much less easy to see and prove
rigorously from the integral than that $sin$ is singly periodic. Other properties of elliptic functions are even harder to see and prove
starting from the integral.
|
44,562,560
|
Where I can disable **"Unclosed comment"** inspection in PhpStorm?
[](https://i.stack.imgur.com/sFLY3.png)
I can't find this inspection settings
```
<script type="text/javascript">
$(function () {
/*// Typeahead
var a = $.parseJSON('<?php //echo json_encode( $groups); ?>');
$('#query').typeahead({
local: a
});*/
});
</script>
```
|
2017/06/15
|
[
"https://Stackoverflow.com/questions/44562560",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6625548/"
] |
It's a known issue.
<https://youtrack.jetbrains.com/issue/WEB-22461> -- watch this ticket (star/vote/comment) to get notified on any progress.
Possible workaround -- use single line comments instead of block comments.
|
I had this issue too. PHPStorm seems to have trouble with inspecting mixed HTML/PHP files.
Until they fix the issue, you can disable real-time inspections:
[Picture I took as a test](https://i.stack.imgur.com/1NRWG.png)
If this concerns you, you can always just run a manual code inspection by navigating the menus to the option:
Code > Inspect Code
|
38,433,834
|
Below are the xml file
```
<maindata>
<publication-reference>
<document-id document-id-type="docdb">
<country>US</country>
<doc-number>9820394ASD</doc-number>
<date>20111101</date>
</document-id>
<document-id document-id-type="docmain">
<doc-number>9820394</doc-number>
<date>20111101</date>
</document-id>
</publication-reference>
</maindata>
```
i want to extract the `<doc-number>`tag value under the type = "`docmain`"
below is my java code, while executed its extract `9829394ASD` instead of `9820394`
```
public static void main(String[] args) {
String filePath ="D:/bs.xml";
File xmlFile = new File(filePath);
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder;
try {
dBuilder = dbFactory.newDocumentBuilder();
Document doc = dBuilder.parse(xmlFile);
doc.getDocumentElement().normalize();
System.out.println("Root element :" + doc.getDocumentElement().getNodeName());
NodeList nodeList = doc.getElementsByTagName("publication-reference");
List<Biblio> docList = new ArrayList<Biblio>();
for (int i = 0; i < nodeList.getLength(); i++) {
docList.add(getdoc(nodeList.item(i)));
}
} catch (SAXException | ParserConfigurationException | IOException e1) {
e1.printStackTrace();
}
}
private static Biblio getdoc(Node node) {
Biblio bib = new Biblio();
if (node.getNodeType() == Node.ELEMENT_NODE) {
Element element = (Element) node;
bib.setCountry(getTagValue("country",element));
bib.setDocnumber(getTagValue("doc-number",element));
bib.setDate(getTagValue("date",element));
}
return bib;
}
```
let me know how can we check the Type its docmain or doctype, should extract only if the type is docmain else should leave the element
added the getTagValue method
```
private static String getTagValue(String tag, Element element) {
NodeList nodeList = element.getElementsByTagName(tag).item(0).getChildNodes();
Node node = (Node) nodeList.item(0);
return node.getNodeValue();
}
```
|
2016/07/18
|
[
"https://Stackoverflow.com/questions/38433834",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2257288/"
] |
Change your method `getdoc()` so that it create only a `Biblio` object for 'docmain` types.
```
private static Biblio getdoc(Node node) {
Biblio bib = null;
if (node.getNodeType() == Node.ELEMENT_NODE) {
Element element = (Element) node;
String type = element.getAttribute("document-id-type");
if(type != null && type.equals("docmain")) {
bib = new Biblio();
bib.setCountry(getTagValue("country",element));
bib.setDocnumber(getTagValue("doc-number",element));
bib.setDate(getTagValue("date",element));
}
}
return bib;
}
```
Then in your main method you should only add to the list, if `getdoc()` result is not null:
```
for (int i = 0; i < nodeList.getLength(); i++) {
Biblio biblio = getdoc(nodeList.item(i));
if(biblio != null) {
docList.add(biblio);
}
}
```
**Update:**
Ok, this is horrible, sorry. You should really learn a little bit about XPath.
I try to rewrite this using XPath expressions.
First we need four XPath expressions. One to extract a node list with all `document-id` elements with type `docmain`.
The XPath expression for this is: `/maindata/publication-reference/document-id[@document-id-type='docmain']` (whole XML document in context).
Here the predicate in [] ensures, that only `document-id` elements with type `docmain` are extracted.
Then for each field in a `document-id` element (with `document-id` element as context):
* country: `country`
* docnumber: `doc-number`
* date: `date`
We use a static initializer for that:
```
private static XPathExpression xpathDocId;
private static XPathExpression xpathCountry;
private static XPathExpression xpathDocnumber;
private static XPathExpression xpathDate;
static {
try {
XPath xpath = XPathFactory.newInstance().newXPath();
// Context is the whole document. Find all document-id elements with type docmain
xpathDocId = xpath.compile("/maindata/publication-reference/document-id[@document-id-type='docmain']");
// Context is a document-id element.
xpathCountry = xpath.compile("country");
xpathDocnumber = xpath.compile("doc-number");
xpathDate = xpath.compile("date");
} catch (XPathExpressionException e) {
e.printStackTrace();
}
}
```
Then we rewrite the method `getdoc`. This method now gets a `document-id` element as input and creates a `Biblio` instance out of it using XPath expressions:
```
private static Biblio getdoc(Node element) throws XPathExpressionException {
Biblio biblio = new Biblio();
biblio.setCountry((String) xpathCountry.evaluate(element, XPathConstants.STRING));
biblio.setDocnumber((String) xpathDocnumber.evaluate(element, XPathConstants.STRING));
biblio.setDate((String) xpathDate.evaluate(element, XPathConstants.STRING));
return biblio;
}
```
Then in the `main()` method you use the XPath expression to extract only the needed elements:
```
NodeList nodeList = (NodeList) xpathDocId.evaluate(doc, XPathConstants.NODESET);
List<Biblio> docList = new ArrayList<Biblio>();
for (int i = 0; i < nodeList.getLength(); i++) {
docList.add(getdoc(nodeList.item(i)));
}
```
|
thanks for the Help, following are the code
```
String Number = xPath.compile("//publication-reference//document-id[@document-id-type=\"docmain\"]/doc-number").evaluate(xmlDocument);
```
|
38,433,834
|
Below are the xml file
```
<maindata>
<publication-reference>
<document-id document-id-type="docdb">
<country>US</country>
<doc-number>9820394ASD</doc-number>
<date>20111101</date>
</document-id>
<document-id document-id-type="docmain">
<doc-number>9820394</doc-number>
<date>20111101</date>
</document-id>
</publication-reference>
</maindata>
```
i want to extract the `<doc-number>`tag value under the type = "`docmain`"
below is my java code, while executed its extract `9829394ASD` instead of `9820394`
```
public static void main(String[] args) {
String filePath ="D:/bs.xml";
File xmlFile = new File(filePath);
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder;
try {
dBuilder = dbFactory.newDocumentBuilder();
Document doc = dBuilder.parse(xmlFile);
doc.getDocumentElement().normalize();
System.out.println("Root element :" + doc.getDocumentElement().getNodeName());
NodeList nodeList = doc.getElementsByTagName("publication-reference");
List<Biblio> docList = new ArrayList<Biblio>();
for (int i = 0; i < nodeList.getLength(); i++) {
docList.add(getdoc(nodeList.item(i)));
}
} catch (SAXException | ParserConfigurationException | IOException e1) {
e1.printStackTrace();
}
}
private static Biblio getdoc(Node node) {
Biblio bib = new Biblio();
if (node.getNodeType() == Node.ELEMENT_NODE) {
Element element = (Element) node;
bib.setCountry(getTagValue("country",element));
bib.setDocnumber(getTagValue("doc-number",element));
bib.setDate(getTagValue("date",element));
}
return bib;
}
```
let me know how can we check the Type its docmain or doctype, should extract only if the type is docmain else should leave the element
added the getTagValue method
```
private static String getTagValue(String tag, Element element) {
NodeList nodeList = element.getElementsByTagName(tag).item(0).getChildNodes();
Node node = (Node) nodeList.item(0);
return node.getNodeValue();
}
```
|
2016/07/18
|
[
"https://Stackoverflow.com/questions/38433834",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2257288/"
] |
The value could be retrieved with [following](http://xpathfiddle.net/1J17R9) XPath using the [DOM and XPath API](https://stackoverflow.com/questions/2811001/how-to-read-xml-using-xpath-in-java).
```
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document doc = builder.parse(new File(...) );
XPathFactory xPathfactory = XPathFactory.newInstance();
XPath xpath = xPathfactory.newXPath();
XPathExpression expr = xpath.compile("//document-id[@document-id-type=\"docmain\"]/doc-number/text()");
String value = expr.evaluate(doc);
```
|
thanks for the Help, following are the code
```
String Number = xPath.compile("//publication-reference//document-id[@document-id-type=\"docmain\"]/doc-number").evaluate(xmlDocument);
```
|
29,117,951
|
I have this [Website](http://avocat.dac-proiect.ro/wp/?page_id=10)
**HTML:**
```css
.lista_sus li {
display: inline-block;
position: relative;
margin: 0 9px 5px 0;
background-color: #041067;
}
.lista_sus li p {
position: absolute;
top: 0;
left: 0;
color: white;
}
.hide {
display: none;
}
```
```html
<ul class="lista_sus">
<li>
<img src="./wp-content/themes/twentyfourteen/images/1.png" alt="Smiley face" height="250" width="250">
<p class="hide">
<div class="title">Zorica L. Codoban
<br>avocat
<br>
</div>
- Avocat din anul 1997
<br>- domenii de specialitate: drept civil, drept comercial, drept succesoral, drept imobiliar, dreptul muncii, drept administrativ, dreptul familiei;
<br>- limbi vorbite: franceza.
</p>
</li>
```
I want to position text over the image ... I did some testing we have found here in the forum but not working.
How can i solve this problem?
Can you help me please?
Thanks in advance!
|
2015/03/18
|
[
"https://Stackoverflow.com/questions/29117951",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4684429/"
] |
Create HTML `background Image`
Or change structure for HTML code and use `float` for this.
|
Usually you make a div with position relative. And in it you have a img, and a text element that is absolute positioned where you wan't it.
|
29,117,951
|
I have this [Website](http://avocat.dac-proiect.ro/wp/?page_id=10)
**HTML:**
```css
.lista_sus li {
display: inline-block;
position: relative;
margin: 0 9px 5px 0;
background-color: #041067;
}
.lista_sus li p {
position: absolute;
top: 0;
left: 0;
color: white;
}
.hide {
display: none;
}
```
```html
<ul class="lista_sus">
<li>
<img src="./wp-content/themes/twentyfourteen/images/1.png" alt="Smiley face" height="250" width="250">
<p class="hide">
<div class="title">Zorica L. Codoban
<br>avocat
<br>
</div>
- Avocat din anul 1997
<br>- domenii de specialitate: drept civil, drept comercial, drept succesoral, drept imobiliar, dreptul muncii, drept administrativ, dreptul familiei;
<br>- limbi vorbite: franceza.
</p>
</li>
```
I want to position text over the image ... I did some testing we have found here in the forum but not working.
How can i solve this problem?
Can you help me please?
Thanks in advance!
|
2015/03/18
|
[
"https://Stackoverflow.com/questions/29117951",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4684429/"
] |
[Here is a working example](http://codepen.io/palashbasak/pen/NPEJax)
```css
ul {
list-style: none;
margin: 0;
padding: 0;
}
ul li {
display: block;
background-color: blue;
color: #fff;
}
ul li img {
width: 500px;
position: absolute;
z-index: 10;
}
ul li p {
position: absolute;
z-index: 100;
padding: 15px;
}
```
```html
<ul>
<li>
<img src="http://www.psdgraphics.com/file/colorful-triangles-background.jpg" alt="">
<p>
Avocat din anul 1997
<br>domenii de specialitate: drept civil, drept comercial, drept succesoral, drept imobiliar, dreptul muncii, drept administrativ, dreptul familiei;
<br>limbi vorbite: franceza.
</p>
</li>
</ul>
```
|
Usually you make a div with position relative. And in it you have a img, and a text element that is absolute positioned where you wan't it.
|
29,117,951
|
I have this [Website](http://avocat.dac-proiect.ro/wp/?page_id=10)
**HTML:**
```css
.lista_sus li {
display: inline-block;
position: relative;
margin: 0 9px 5px 0;
background-color: #041067;
}
.lista_sus li p {
position: absolute;
top: 0;
left: 0;
color: white;
}
.hide {
display: none;
}
```
```html
<ul class="lista_sus">
<li>
<img src="./wp-content/themes/twentyfourteen/images/1.png" alt="Smiley face" height="250" width="250">
<p class="hide">
<div class="title">Zorica L. Codoban
<br>avocat
<br>
</div>
- Avocat din anul 1997
<br>- domenii de specialitate: drept civil, drept comercial, drept succesoral, drept imobiliar, dreptul muncii, drept administrativ, dreptul familiei;
<br>- limbi vorbite: franceza.
</p>
</li>
```
I want to position text over the image ... I did some testing we have found here in the forum but not working.
How can i solve this problem?
Can you help me please?
Thanks in advance!
|
2015/03/18
|
[
"https://Stackoverflow.com/questions/29117951",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4684429/"
] |
Option1: Use background Image
=============================
You could set the image in the background of a div, and have text within the image:
```css
div {
display: inline-block;
height: 300px;
width: 300px;
background: url(http://placekitten.com/g/300/300);
}
```
```html
<div>This is some text</div>
```
---
Option2: Use Positioning
========================
You could use a wrapper div (`position: relative`), and position the text and image accordingly (`position: absolute`):
```css
.wrap {
position: relative;
height: 300px;
width: 300px;
}
.text,
.wrap img {
position: absolute;
top: 0;
left: 0;
height: 300px;
width: 300px;
}
.text {
z-index: 8;
}
```
```html
<div class="wrap">
<div class="text">This is some text</div>
<img src="http://placekitten.com/g/300/300" />
</div>
```
|
Usually you make a div with position relative. And in it you have a img, and a text element that is absolute positioned where you wan't it.
|
29,117,951
|
I have this [Website](http://avocat.dac-proiect.ro/wp/?page_id=10)
**HTML:**
```css
.lista_sus li {
display: inline-block;
position: relative;
margin: 0 9px 5px 0;
background-color: #041067;
}
.lista_sus li p {
position: absolute;
top: 0;
left: 0;
color: white;
}
.hide {
display: none;
}
```
```html
<ul class="lista_sus">
<li>
<img src="./wp-content/themes/twentyfourteen/images/1.png" alt="Smiley face" height="250" width="250">
<p class="hide">
<div class="title">Zorica L. Codoban
<br>avocat
<br>
</div>
- Avocat din anul 1997
<br>- domenii de specialitate: drept civil, drept comercial, drept succesoral, drept imobiliar, dreptul muncii, drept administrativ, dreptul familiei;
<br>- limbi vorbite: franceza.
</p>
</li>
```
I want to position text over the image ... I did some testing we have found here in the forum but not working.
How can i solve this problem?
Can you help me please?
Thanks in advance!
|
2015/03/18
|
[
"https://Stackoverflow.com/questions/29117951",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4684429/"
] |
```css
.picture {
background: url("http://www.wallpaperup.com/uploads/wallpapers/2012/09/07/13037/big_thumb_97f1fdc4221e259ac57c475977627b9d.jpg") no-repeat center center fixed;
background-size: 100%;
display:inline-block;
}
```
```html
<div class="picture">TEXT HERE</div>
```
|
Usually you make a div with position relative. And in it you have a img, and a text element that is absolute positioned where you wan't it.
|
29,117,951
|
I have this [Website](http://avocat.dac-proiect.ro/wp/?page_id=10)
**HTML:**
```css
.lista_sus li {
display: inline-block;
position: relative;
margin: 0 9px 5px 0;
background-color: #041067;
}
.lista_sus li p {
position: absolute;
top: 0;
left: 0;
color: white;
}
.hide {
display: none;
}
```
```html
<ul class="lista_sus">
<li>
<img src="./wp-content/themes/twentyfourteen/images/1.png" alt="Smiley face" height="250" width="250">
<p class="hide">
<div class="title">Zorica L. Codoban
<br>avocat
<br>
</div>
- Avocat din anul 1997
<br>- domenii de specialitate: drept civil, drept comercial, drept succesoral, drept imobiliar, dreptul muncii, drept administrativ, dreptul familiei;
<br>- limbi vorbite: franceza.
</p>
</li>
```
I want to position text over the image ... I did some testing we have found here in the forum but not working.
How can i solve this problem?
Can you help me please?
Thanks in advance!
|
2015/03/18
|
[
"https://Stackoverflow.com/questions/29117951",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4684429/"
] |
Create HTML `background Image`
Or change structure for HTML code and use `float` for this.
|
Option1: Use background Image
=============================
You could set the image in the background of a div, and have text within the image:
```css
div {
display: inline-block;
height: 300px;
width: 300px;
background: url(http://placekitten.com/g/300/300);
}
```
```html
<div>This is some text</div>
```
---
Option2: Use Positioning
========================
You could use a wrapper div (`position: relative`), and position the text and image accordingly (`position: absolute`):
```css
.wrap {
position: relative;
height: 300px;
width: 300px;
}
.text,
.wrap img {
position: absolute;
top: 0;
left: 0;
height: 300px;
width: 300px;
}
.text {
z-index: 8;
}
```
```html
<div class="wrap">
<div class="text">This is some text</div>
<img src="http://placekitten.com/g/300/300" />
</div>
```
|
29,117,951
|
I have this [Website](http://avocat.dac-proiect.ro/wp/?page_id=10)
**HTML:**
```css
.lista_sus li {
display: inline-block;
position: relative;
margin: 0 9px 5px 0;
background-color: #041067;
}
.lista_sus li p {
position: absolute;
top: 0;
left: 0;
color: white;
}
.hide {
display: none;
}
```
```html
<ul class="lista_sus">
<li>
<img src="./wp-content/themes/twentyfourteen/images/1.png" alt="Smiley face" height="250" width="250">
<p class="hide">
<div class="title">Zorica L. Codoban
<br>avocat
<br>
</div>
- Avocat din anul 1997
<br>- domenii de specialitate: drept civil, drept comercial, drept succesoral, drept imobiliar, dreptul muncii, drept administrativ, dreptul familiei;
<br>- limbi vorbite: franceza.
</p>
</li>
```
I want to position text over the image ... I did some testing we have found here in the forum but not working.
How can i solve this problem?
Can you help me please?
Thanks in advance!
|
2015/03/18
|
[
"https://Stackoverflow.com/questions/29117951",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4684429/"
] |
Create HTML `background Image`
Or change structure for HTML code and use `float` for this.
|
```css
.picture {
background: url("http://www.wallpaperup.com/uploads/wallpapers/2012/09/07/13037/big_thumb_97f1fdc4221e259ac57c475977627b9d.jpg") no-repeat center center fixed;
background-size: 100%;
display:inline-block;
}
```
```html
<div class="picture">TEXT HERE</div>
```
|
29,117,951
|
I have this [Website](http://avocat.dac-proiect.ro/wp/?page_id=10)
**HTML:**
```css
.lista_sus li {
display: inline-block;
position: relative;
margin: 0 9px 5px 0;
background-color: #041067;
}
.lista_sus li p {
position: absolute;
top: 0;
left: 0;
color: white;
}
.hide {
display: none;
}
```
```html
<ul class="lista_sus">
<li>
<img src="./wp-content/themes/twentyfourteen/images/1.png" alt="Smiley face" height="250" width="250">
<p class="hide">
<div class="title">Zorica L. Codoban
<br>avocat
<br>
</div>
- Avocat din anul 1997
<br>- domenii de specialitate: drept civil, drept comercial, drept succesoral, drept imobiliar, dreptul muncii, drept administrativ, dreptul familiei;
<br>- limbi vorbite: franceza.
</p>
</li>
```
I want to position text over the image ... I did some testing we have found here in the forum but not working.
How can i solve this problem?
Can you help me please?
Thanks in advance!
|
2015/03/18
|
[
"https://Stackoverflow.com/questions/29117951",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4684429/"
] |
[Here is a working example](http://codepen.io/palashbasak/pen/NPEJax)
```css
ul {
list-style: none;
margin: 0;
padding: 0;
}
ul li {
display: block;
background-color: blue;
color: #fff;
}
ul li img {
width: 500px;
position: absolute;
z-index: 10;
}
ul li p {
position: absolute;
z-index: 100;
padding: 15px;
}
```
```html
<ul>
<li>
<img src="http://www.psdgraphics.com/file/colorful-triangles-background.jpg" alt="">
<p>
Avocat din anul 1997
<br>domenii de specialitate: drept civil, drept comercial, drept succesoral, drept imobiliar, dreptul muncii, drept administrativ, dreptul familiei;
<br>limbi vorbite: franceza.
</p>
</li>
</ul>
```
|
Option1: Use background Image
=============================
You could set the image in the background of a div, and have text within the image:
```css
div {
display: inline-block;
height: 300px;
width: 300px;
background: url(http://placekitten.com/g/300/300);
}
```
```html
<div>This is some text</div>
```
---
Option2: Use Positioning
========================
You could use a wrapper div (`position: relative`), and position the text and image accordingly (`position: absolute`):
```css
.wrap {
position: relative;
height: 300px;
width: 300px;
}
.text,
.wrap img {
position: absolute;
top: 0;
left: 0;
height: 300px;
width: 300px;
}
.text {
z-index: 8;
}
```
```html
<div class="wrap">
<div class="text">This is some text</div>
<img src="http://placekitten.com/g/300/300" />
</div>
```
|
29,117,951
|
I have this [Website](http://avocat.dac-proiect.ro/wp/?page_id=10)
**HTML:**
```css
.lista_sus li {
display: inline-block;
position: relative;
margin: 0 9px 5px 0;
background-color: #041067;
}
.lista_sus li p {
position: absolute;
top: 0;
left: 0;
color: white;
}
.hide {
display: none;
}
```
```html
<ul class="lista_sus">
<li>
<img src="./wp-content/themes/twentyfourteen/images/1.png" alt="Smiley face" height="250" width="250">
<p class="hide">
<div class="title">Zorica L. Codoban
<br>avocat
<br>
</div>
- Avocat din anul 1997
<br>- domenii de specialitate: drept civil, drept comercial, drept succesoral, drept imobiliar, dreptul muncii, drept administrativ, dreptul familiei;
<br>- limbi vorbite: franceza.
</p>
</li>
```
I want to position text over the image ... I did some testing we have found here in the forum but not working.
How can i solve this problem?
Can you help me please?
Thanks in advance!
|
2015/03/18
|
[
"https://Stackoverflow.com/questions/29117951",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4684429/"
] |
[Here is a working example](http://codepen.io/palashbasak/pen/NPEJax)
```css
ul {
list-style: none;
margin: 0;
padding: 0;
}
ul li {
display: block;
background-color: blue;
color: #fff;
}
ul li img {
width: 500px;
position: absolute;
z-index: 10;
}
ul li p {
position: absolute;
z-index: 100;
padding: 15px;
}
```
```html
<ul>
<li>
<img src="http://www.psdgraphics.com/file/colorful-triangles-background.jpg" alt="">
<p>
Avocat din anul 1997
<br>domenii de specialitate: drept civil, drept comercial, drept succesoral, drept imobiliar, dreptul muncii, drept administrativ, dreptul familiei;
<br>limbi vorbite: franceza.
</p>
</li>
</ul>
```
|
```css
.picture {
background: url("http://www.wallpaperup.com/uploads/wallpapers/2012/09/07/13037/big_thumb_97f1fdc4221e259ac57c475977627b9d.jpg") no-repeat center center fixed;
background-size: 100%;
display:inline-block;
}
```
```html
<div class="picture">TEXT HERE</div>
```
|
10,546,302
|
How can I find all indexes of a pattern in a string using c#?
For example I want to find all `##` pattern indexes in a string like this `45##78$$#56$$JK01UU`
|
2012/05/11
|
[
"https://Stackoverflow.com/questions/10546302",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1269997/"
] |
Edited the code to make it a cleaner function.
```
public IEnumerable<int> FindAllIndexes(string str, string pattern)
{
int prevIndex = -pattern.Length; // so we start at index 0
int index;
while((index = str.IndexOf(pattern, prevIndex + pattern.Length)) != -1)
{
prevIndex = index;
yield return index;
}
}
string str = "45##78$$#56$$JK01UU";
string pattern = "##";
var indexes = FindAllIndexes(str, pattern);
```
|
Another one that tries to be efficient:
```
public IEnumerable<int> FindPatternIndexes(string input, string search)
{
var sb = new StringBuilder(input);
for (var i = 0; search.Length <= sb.Length; i++)
{
if (sb.ToString().StartsWith(search)) yield return i;
sb.Remove(0,1);
}
}
```
|
10,546,302
|
How can I find all indexes of a pattern in a string using c#?
For example I want to find all `##` pattern indexes in a string like this `45##78$$#56$$JK01UU`
|
2012/05/11
|
[
"https://Stackoverflow.com/questions/10546302",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1269997/"
] |
Edited the code to make it a cleaner function.
```
public IEnumerable<int> FindAllIndexes(string str, string pattern)
{
int prevIndex = -pattern.Length; // so we start at index 0
int index;
while((index = str.IndexOf(pattern, prevIndex + pattern.Length)) != -1)
{
prevIndex = index;
yield return index;
}
}
string str = "45##78$$#56$$JK01UU";
string pattern = "##";
var indexes = FindAllIndexes(str, pattern);
```
|
Tested. Worked. But somewhat dumb.
```
string foo = "45##78$$#56$$JK01UU";
char[] fooChar = foo.ToCharArray();
int i = 0;
bool register = false;
foreach (char fc in fooChar)
{
if (fc == '#' && register == true)
{
MessageBox.Show("Index: " + (i-1));
}
else if (fc == '#')
{
register = true;
}
else
{
register = false;
}
i++;
}
```
|
10,546,302
|
How can I find all indexes of a pattern in a string using c#?
For example I want to find all `##` pattern indexes in a string like this `45##78$$#56$$JK01UU`
|
2012/05/11
|
[
"https://Stackoverflow.com/questions/10546302",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1269997/"
] |
```
string pattern = "##";
string sentence = "45##78$$#56$$J##K01UU";
IList<int> indeces = new List<int>();
foreach (Match match in Regex.Matches(sentence, pattern))
{
indeces.Add(match.Index);
}
```
indeces will have 2, 14
|
Edited the code to make it a cleaner function.
```
public IEnumerable<int> FindAllIndexes(string str, string pattern)
{
int prevIndex = -pattern.Length; // so we start at index 0
int index;
while((index = str.IndexOf(pattern, prevIndex + pattern.Length)) != -1)
{
prevIndex = index;
yield return index;
}
}
string str = "45##78$$#56$$JK01UU";
string pattern = "##";
var indexes = FindAllIndexes(str, pattern);
```
|
10,546,302
|
How can I find all indexes of a pattern in a string using c#?
For example I want to find all `##` pattern indexes in a string like this `45##78$$#56$$JK01UU`
|
2012/05/11
|
[
"https://Stackoverflow.com/questions/10546302",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1269997/"
] |
You can get all the indices of a pattern in a string by using a regex search like this.
```
string input = "45##78$$#56$$JK01UU", pattern = Regex.Escape("##");
Regex rx = new Regex(pattern);
var indices = new List<int>();
var matches = rx.Matches(s);
for (int i=0 ; i<matches.Length ; i++)
{
indices.Add(matches[i].Index);
}
```
|
Another one that tries to be efficient:
```
public IEnumerable<int> FindPatternIndexes(string input, string search)
{
var sb = new StringBuilder(input);
for (var i = 0; search.Length <= sb.Length; i++)
{
if (sb.ToString().StartsWith(search)) yield return i;
sb.Remove(0,1);
}
}
```
|
10,546,302
|
How can I find all indexes of a pattern in a string using c#?
For example I want to find all `##` pattern indexes in a string like this `45##78$$#56$$JK01UU`
|
2012/05/11
|
[
"https://Stackoverflow.com/questions/10546302",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1269997/"
] |
You can get all the indices of a pattern in a string by using a regex search like this.
```
string input = "45##78$$#56$$JK01UU", pattern = Regex.Escape("##");
Regex rx = new Regex(pattern);
var indices = new List<int>();
var matches = rx.Matches(s);
for (int i=0 ; i<matches.Length ; i++)
{
indices.Add(matches[i].Index);
}
```
|
Tested. Worked. But somewhat dumb.
```
string foo = "45##78$$#56$$JK01UU";
char[] fooChar = foo.ToCharArray();
int i = 0;
bool register = false;
foreach (char fc in fooChar)
{
if (fc == '#' && register == true)
{
MessageBox.Show("Index: " + (i-1));
}
else if (fc == '#')
{
register = true;
}
else
{
register = false;
}
i++;
}
```
|
10,546,302
|
How can I find all indexes of a pattern in a string using c#?
For example I want to find all `##` pattern indexes in a string like this `45##78$$#56$$JK01UU`
|
2012/05/11
|
[
"https://Stackoverflow.com/questions/10546302",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1269997/"
] |
```
string pattern = "##";
string sentence = "45##78$$#56$$J##K01UU";
IList<int> indeces = new List<int>();
foreach (Match match in Regex.Matches(sentence, pattern))
{
indeces.Add(match.Index);
}
```
indeces will have 2, 14
|
You can get all the indices of a pattern in a string by using a regex search like this.
```
string input = "45##78$$#56$$JK01UU", pattern = Regex.Escape("##");
Regex rx = new Regex(pattern);
var indices = new List<int>();
var matches = rx.Matches(s);
for (int i=0 ; i<matches.Length ; i++)
{
indices.Add(matches[i].Index);
}
```
|
10,546,302
|
How can I find all indexes of a pattern in a string using c#?
For example I want to find all `##` pattern indexes in a string like this `45##78$$#56$$JK01UU`
|
2012/05/11
|
[
"https://Stackoverflow.com/questions/10546302",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1269997/"
] |
```
string pattern = "##";
string sentence = "45##78$$#56$$J##K01UU";
IList<int> indeces = new List<int>();
foreach (Match match in Regex.Matches(sentence, pattern))
{
indeces.Add(match.Index);
}
```
indeces will have 2, 14
|
Another one that tries to be efficient:
```
public IEnumerable<int> FindPatternIndexes(string input, string search)
{
var sb = new StringBuilder(input);
for (var i = 0; search.Length <= sb.Length; i++)
{
if (sb.ToString().StartsWith(search)) yield return i;
sb.Remove(0,1);
}
}
```
|
10,546,302
|
How can I find all indexes of a pattern in a string using c#?
For example I want to find all `##` pattern indexes in a string like this `45##78$$#56$$JK01UU`
|
2012/05/11
|
[
"https://Stackoverflow.com/questions/10546302",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1269997/"
] |
```
string pattern = "##";
string sentence = "45##78$$#56$$J##K01UU";
IList<int> indeces = new List<int>();
foreach (Match match in Regex.Matches(sentence, pattern))
{
indeces.Add(match.Index);
}
```
indeces will have 2, 14
|
Tested. Worked. But somewhat dumb.
```
string foo = "45##78$$#56$$JK01UU";
char[] fooChar = foo.ToCharArray();
int i = 0;
bool register = false;
foreach (char fc in fooChar)
{
if (fc == '#' && register == true)
{
MessageBox.Show("Index: " + (i-1));
}
else if (fc == '#')
{
register = true;
}
else
{
register = false;
}
i++;
}
```
|
13,768,049
|
Is there a way to use instanceof based on the passed argument of a method? Example
```
doSomething(myClass.class); /* I would like to call this also with other classes */
public void doSomething(/*generic parameter that accepts all classes, not just myClass */) {
if (myObject instanceOf /* the generic parameter */ == true) {...}
}
```
sometimes I'll call the method using myClass.class but other times I would like to call it using someOtherClass.class - I don't want to change the if condition though. Is that possible? If so, how? :)
Thanks
|
2012/12/07
|
[
"https://Stackoverflow.com/questions/13768049",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/511477/"
] |
You're looking for the [`Class.isInstance()` method](http://docs.oracle.com/javase/7/docs/api/java/lang/Class.html#isInstance(java.lang.Object)).
```
public void doSomething(Class<?> c, Object myObject) {
if (c.isInstance(myObject)) {...}
}
```
|
This is the way to do it, as far as I know:
```
public static <T> boolean doInstanceOf(Object object,Class<T> clz) {
return clz.isInstance(object);
}
```
Usage:
```
System.out.println(doInstanceOf(myObject,MyClass.class));
```
|
11,047,344
|
I'm trying to check network available or not.
But in my emulator it always shows `connected` (after disconnecting internet also)
Is there any mistake in my code.I am connecting with **wifi**.
*Code:*
```
public class AndroidConnectivityActivity extends Activity
{
Button checkBtn;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
checkBtn = (Button) findViewById(R.id.button1);
checkBtn.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
if(isInternetOn())
{
Toast.makeText(getBaseContext(), "Connected",
Toast.LENGTH_SHORT).show();
}
else
{
Toast.makeText(getBaseContext(), "Not connected",
Toast.LENGTH_SHORT).show();
}
}});
}
public final boolean isInternetOn()
{
ConnectivityManager connec = (ConnectivityManager) getSystemService
(Context.CONNECTIVITY_SERVICE);
if ((connec.getNetworkInfo(0).getState() == NetworkInfo.State.CONNECTED)
||(connec.getNetworkInfo(0).getState() == NetworkInfo.State.CONNECTING)
||(connec.getNetworkInfo(1).getState() == NetworkInfo.State.CONNECTING)
||(connec.getNetworkInfo(1).getState() == NetworkInfo.State.CONNECTED))
{
return true;
}
else if ((connec.getNetworkInfo(0).getState() == NetworkInfo.State.DISCONNECTED)
|| (connec.getNetworkInfo(1).getState() == NetworkInfo.State.DISCONNECTED))
{
return false;
}
return false;
}
}
```
|
2012/06/15
|
[
"https://Stackoverflow.com/questions/11047344",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1453422/"
] |
use below code
```
public static boolean isInternetAvailable(Context context)
{
boolean isInternetAvailable = false;
try
{
ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
if(networkInfo != null && (networkInfo.isConnected()))
{
isInternetAvailable = true;
}
}
catch(Exception exception)
{
// Do Nothing
}
return isInternetAvailable;
}
```
and also try on real device
use code in Activity onCreate Method like
```
if(isInternetAvailable(this))
{
Toast toast = Toast.makeText(this, "internet available", Toast.LENGTH_SHORT);
toast.show();
}
else
{
Toast toast = Toast.makeText(this, "internet not available", Toast.LENGTH_SHORT);
toast.show();
}
```
Required manifest permission
```
<uses-permission
android:name="android.permission.INTERNET" />
<uses-permission
android:name="android.permission.ACCESS_NETWORK_STATE" />
```
|
Use mehod shoen below
```
public static boolean isInternetAvailable(Context context) {
ConnectivityManager cm =
(ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo netInfo = cm.getActiveNetworkInfo();
if (netInfo != null && netInfo.isConnectedOrConnecting()) {
return true;
}
return false;
}
```
and in manifest set permission as
```
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
```
|
11,047,344
|
I'm trying to check network available or not.
But in my emulator it always shows `connected` (after disconnecting internet also)
Is there any mistake in my code.I am connecting with **wifi**.
*Code:*
```
public class AndroidConnectivityActivity extends Activity
{
Button checkBtn;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
checkBtn = (Button) findViewById(R.id.button1);
checkBtn.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
if(isInternetOn())
{
Toast.makeText(getBaseContext(), "Connected",
Toast.LENGTH_SHORT).show();
}
else
{
Toast.makeText(getBaseContext(), "Not connected",
Toast.LENGTH_SHORT).show();
}
}});
}
public final boolean isInternetOn()
{
ConnectivityManager connec = (ConnectivityManager) getSystemService
(Context.CONNECTIVITY_SERVICE);
if ((connec.getNetworkInfo(0).getState() == NetworkInfo.State.CONNECTED)
||(connec.getNetworkInfo(0).getState() == NetworkInfo.State.CONNECTING)
||(connec.getNetworkInfo(1).getState() == NetworkInfo.State.CONNECTING)
||(connec.getNetworkInfo(1).getState() == NetworkInfo.State.CONNECTED))
{
return true;
}
else if ((connec.getNetworkInfo(0).getState() == NetworkInfo.State.DISCONNECTED)
|| (connec.getNetworkInfo(1).getState() == NetworkInfo.State.DISCONNECTED))
{
return false;
}
return false;
}
}
```
|
2012/06/15
|
[
"https://Stackoverflow.com/questions/11047344",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1453422/"
] |
use below code
```
public static boolean isInternetAvailable(Context context)
{
boolean isInternetAvailable = false;
try
{
ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
if(networkInfo != null && (networkInfo.isConnected()))
{
isInternetAvailable = true;
}
}
catch(Exception exception)
{
// Do Nothing
}
return isInternetAvailable;
}
```
and also try on real device
use code in Activity onCreate Method like
```
if(isInternetAvailable(this))
{
Toast toast = Toast.makeText(this, "internet available", Toast.LENGTH_SHORT);
toast.show();
}
else
{
Toast toast = Toast.makeText(this, "internet not available", Toast.LENGTH_SHORT);
toast.show();
}
```
Required manifest permission
```
<uses-permission
android:name="android.permission.INTERNET" />
<uses-permission
android:name="android.permission.ACCESS_NETWORK_STATE" />
```
|
use this:
```
private boolean getOnlineState() {
ConnectivityManager myConnectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo myNetworkInfo = myConnectivityManager
.getActiveNetworkInfo();
if (myNetworkInfo != null
&& myNetworkInfo.isConnectedOrConnecting())
return true;
return false;
}
```
and btw:
```
if ((connec.getNetworkInfo(0).getState() == NetworkInfo.State.CONNECTED)
||(connec.getNetworkInfo(0).getState() == NetworkInfo.State.CONNECTING)
||(connec.getNetworkInfo(1).getState() == NetworkInfo.State.CONNECTING)
||(connec.getNetworkInfo(1).getState() == NetworkInfo.State.CONNECTED))
{
return true;
}
else if ((connec.getNetworkInfo(0).getState() == NetworkInfo.State.DISCONNECTED)
|| (connec.getNetworkInfo(1).getState() == NetworkInfo.State.DISCONNECTED))
{
return false;
}
return false;
}
```
is the same like:
```
if ((connec.getNetworkInfo(0).getState() == NetworkInfo.State.CONNECTED)
||(connec.getNetworkInfo(0).getState() == NetworkInfo.State.CONNECTING)
||(connec.getNetworkInfo(1).getState() == NetworkInfo.State.CONNECTING)
||(connec.getNetworkInfo(1).getState() == NetworkInfo.State.CONNECTED))
return true;
return false;
```
Yous should try such hardwareoperations on a real phone rather then the emulator.
|
11,047,344
|
I'm trying to check network available or not.
But in my emulator it always shows `connected` (after disconnecting internet also)
Is there any mistake in my code.I am connecting with **wifi**.
*Code:*
```
public class AndroidConnectivityActivity extends Activity
{
Button checkBtn;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
checkBtn = (Button) findViewById(R.id.button1);
checkBtn.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
if(isInternetOn())
{
Toast.makeText(getBaseContext(), "Connected",
Toast.LENGTH_SHORT).show();
}
else
{
Toast.makeText(getBaseContext(), "Not connected",
Toast.LENGTH_SHORT).show();
}
}});
}
public final boolean isInternetOn()
{
ConnectivityManager connec = (ConnectivityManager) getSystemService
(Context.CONNECTIVITY_SERVICE);
if ((connec.getNetworkInfo(0).getState() == NetworkInfo.State.CONNECTED)
||(connec.getNetworkInfo(0).getState() == NetworkInfo.State.CONNECTING)
||(connec.getNetworkInfo(1).getState() == NetworkInfo.State.CONNECTING)
||(connec.getNetworkInfo(1).getState() == NetworkInfo.State.CONNECTED))
{
return true;
}
else if ((connec.getNetworkInfo(0).getState() == NetworkInfo.State.DISCONNECTED)
|| (connec.getNetworkInfo(1).getState() == NetworkInfo.State.DISCONNECTED))
{
return false;
}
return false;
}
}
```
|
2012/06/15
|
[
"https://Stackoverflow.com/questions/11047344",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1453422/"
] |
Use mehod shoen below
```
public static boolean isInternetAvailable(Context context) {
ConnectivityManager cm =
(ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo netInfo = cm.getActiveNetworkInfo();
if (netInfo != null && netInfo.isConnectedOrConnecting()) {
return true;
}
return false;
}
```
and in manifest set permission as
```
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
```
|
use this:
```
private boolean getOnlineState() {
ConnectivityManager myConnectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo myNetworkInfo = myConnectivityManager
.getActiveNetworkInfo();
if (myNetworkInfo != null
&& myNetworkInfo.isConnectedOrConnecting())
return true;
return false;
}
```
and btw:
```
if ((connec.getNetworkInfo(0).getState() == NetworkInfo.State.CONNECTED)
||(connec.getNetworkInfo(0).getState() == NetworkInfo.State.CONNECTING)
||(connec.getNetworkInfo(1).getState() == NetworkInfo.State.CONNECTING)
||(connec.getNetworkInfo(1).getState() == NetworkInfo.State.CONNECTED))
{
return true;
}
else if ((connec.getNetworkInfo(0).getState() == NetworkInfo.State.DISCONNECTED)
|| (connec.getNetworkInfo(1).getState() == NetworkInfo.State.DISCONNECTED))
{
return false;
}
return false;
}
```
is the same like:
```
if ((connec.getNetworkInfo(0).getState() == NetworkInfo.State.CONNECTED)
||(connec.getNetworkInfo(0).getState() == NetworkInfo.State.CONNECTING)
||(connec.getNetworkInfo(1).getState() == NetworkInfo.State.CONNECTING)
||(connec.getNetworkInfo(1).getState() == NetworkInfo.State.CONNECTED))
return true;
return false;
```
Yous should try such hardwareoperations on a real phone rather then the emulator.
|
145,015
|
How to evaluate the following definite integral:
$$\int\_{-1}^1 \exp\left(\frac1{x^2-1}\right) \, dx$$
It seems that indefinite integral also cannot be expressed in standard functions. I would like any solution in popular elementary or non-elementary functions.
|
2012/05/14
|
[
"https://math.stackexchange.com/questions/145015",
"https://math.stackexchange.com",
"https://math.stackexchange.com/users/2513/"
] |
I have the best approach:
$\int\_{-1}^1e^{\frac{1}{x^2-1}}~dx$
$=\int\_{-1}^0e^{\frac{1}{x^2-1}}~dx+\int\_0^1e^{\frac{1}{x^2-1}}~dx$
$=\int\_1^0e^{\frac{1}{(-x)^2-1}}~d(-x)+\int\_0^1e^{\frac{1}{x^2-1}}~dx$
$=\int\_0^1e^{\frac{1}{x^2-1}}~dx+\int\_0^1e^{\frac{1}{x^2-1}}~dx$
$=2\int\_0^1e^{\frac{1}{x^2-1}}~dx$
$=2\int\_0^\infty e^{\frac{1}{\tanh^2x-1}}~d(\tanh x)$
$=2\int\_0^\infty e^{-\frac{1}{\text{sech}^2x}}~d(\tanh x)$
$=2\int\_0^\infty e^{-\cosh^2x}~d(\tanh x)$
$=2\left[e^{-\cosh^2x}\tanh x\right]\_0^\infty-2\int\_0^\infty\tanh x~d\left(e^{-\cosh^2x}\right)$
$=4\int\_0^\infty e^{-\cosh^2x}\sinh x\cosh x\tanh x~dx$
$=4\int\_0^\infty e^{-\cosh^2x}\sinh^2x~dx$
$=4\int\_0^\infty e^{-\frac{\cosh2x+1}{2}}\dfrac{\cosh2x-1}{2}dx$
$=2e^{-\frac{1}{2}}\int\_0^\infty e^{-\frac{\cosh2x}{2}}(\cosh2x-1)~dx$
$=e^{-\frac{1}{2}}\int\_0^\infty e^{-\frac{\cosh2x}{2}}(\cosh2x-1)~d(2x)$
$=e^{-\frac{1}{2}}\int\_0^\infty e^{-\frac{\cosh x}{2}}(\cosh x-1)~dx$
$=e^{-\frac{1}{2}}\left(K\_1\left(\dfrac{1}{2}\right)-K\_0\left(\dfrac{1}{2}\right)\right)$
|
The symmetry of the integrand and variable substitution $t=1/(1-x^2)-1$ can be used to transform your integral as follows:
$$
I=\int\_{-1}^1 \exp\left(\frac{1}{x^2-1}\right)dx=\int\_0^1 2\exp\left(\frac{1}{x^2-1}\right)dx
=\frac{1}{e}\int\_0^{\infty}\frac{e^{-t}dt}{\sqrt{t}(1+t)^{3/2}}\,,
$$
Maple can evaluate this integral in terms of Meijer's $G$-function, just as obtained by J.M. after "coaxing" his Mathematica. Alternatively, this integral can be recognised as [Whittaker's function $W$](http://mathworld.wolfram.com/WhittakerFunction.html). The same conclusion can also be arrived at by noting that this integral is, effectively, a Laplace transform and using an appropriate command of Maple (or Mathematica), with the result
$$
I=\sqrt{\frac{\pi}{e}} W\_{-\frac{1}{2},-\frac{1}{2}}(1) \approx 0.44399\,.
$$
This answer is only slightly more elegant than J.M.'s; it's still not elementary and I am unsure whether you would describe Whittaker's function as "popular". You may also consider reformulating this in terms of confluent hypergeometric function.
**Updated 15/05/2012:** It seems that you can avoid using Whittaker's function after all, at the cost of computing a modified Bessel function and a certain continued fraction. Specifically, identities [13.17.3](http://dlmf.nist.gov/13.17.E3) and [13.18.9](http://dlmf.nist.gov/13.18.E9), given in the "new" DLMF, lead to the simple result:
$$
I=\frac{K\_0(1/2)}{C\sqrt{e}}\,,
$$
with constant $C$ given by the following continued fraction:
$$
C=1+\frac{1/2}{1+}\,\frac{3/2}{1+}\,\frac{3/2}{1+}\,\frac{5/2}{1+}\,\frac{5/2}{1+}\,
\frac{7/2}{1+}\,\frac{7/2}{1+}\,\cdots
=\frac{W\_{0,0}(1)}{W\_{-\frac{1}{2},-\frac{1}{2}}(1)}\approx 1.2628295456\,.
$$
In terms of functions involved, this is a lot more "elementary". From the computational point of view, I suspect that the original answer above is more practical.
|
145,015
|
How to evaluate the following definite integral:
$$\int\_{-1}^1 \exp\left(\frac1{x^2-1}\right) \, dx$$
It seems that indefinite integral also cannot be expressed in standard functions. I would like any solution in popular elementary or non-elementary functions.
|
2012/05/14
|
[
"https://math.stackexchange.com/questions/145015",
"https://math.stackexchange.com",
"https://math.stackexchange.com/users/2513/"
] |
I have the best approach:
$\int\_{-1}^1e^{\frac{1}{x^2-1}}~dx$
$=\int\_{-1}^0e^{\frac{1}{x^2-1}}~dx+\int\_0^1e^{\frac{1}{x^2-1}}~dx$
$=\int\_1^0e^{\frac{1}{(-x)^2-1}}~d(-x)+\int\_0^1e^{\frac{1}{x^2-1}}~dx$
$=\int\_0^1e^{\frac{1}{x^2-1}}~dx+\int\_0^1e^{\frac{1}{x^2-1}}~dx$
$=2\int\_0^1e^{\frac{1}{x^2-1}}~dx$
$=2\int\_0^\infty e^{\frac{1}{\tanh^2x-1}}~d(\tanh x)$
$=2\int\_0^\infty e^{-\frac{1}{\text{sech}^2x}}~d(\tanh x)$
$=2\int\_0^\infty e^{-\cosh^2x}~d(\tanh x)$
$=2\left[e^{-\cosh^2x}\tanh x\right]\_0^\infty-2\int\_0^\infty\tanh x~d\left(e^{-\cosh^2x}\right)$
$=4\int\_0^\infty e^{-\cosh^2x}\sinh x\cosh x\tanh x~dx$
$=4\int\_0^\infty e^{-\cosh^2x}\sinh^2x~dx$
$=4\int\_0^\infty e^{-\frac{\cosh2x+1}{2}}\dfrac{\cosh2x-1}{2}dx$
$=2e^{-\frac{1}{2}}\int\_0^\infty e^{-\frac{\cosh2x}{2}}(\cosh2x-1)~dx$
$=e^{-\frac{1}{2}}\int\_0^\infty e^{-\frac{\cosh2x}{2}}(\cosh2x-1)~d(2x)$
$=e^{-\frac{1}{2}}\int\_0^\infty e^{-\frac{\cosh x}{2}}(\cosh x-1)~dx$
$=e^{-\frac{1}{2}}\left(K\_1\left(\dfrac{1}{2}\right)-K\_0\left(\dfrac{1}{2}\right)\right)$
|
Using the symmetry $x \to -x$ and change of variables $t = 1/\sqrt{1-x^2}$ we get
$2 \int\_1^\infty \dfrac{e^{-t^2}}{t^2 \sqrt{t^2-1}} dt$, which Maple 16 can then evaluate as
${{\rm e}^{-1/2}} \left( {{\rm K}\_1\left(1/2\right)}-
{{\rm K}\_0\left(1/2\right)} \right) $.
|
8,794,937
|
I know how to create bundle using console. Now I want to add second controller to generated bundle, how can I do it from console. (php app/console generate:controller doesn't work)
|
2012/01/09
|
[
"https://Stackoverflow.com/questions/8794937",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/783353/"
] |
You can use `php app/console doctrine:generate:crud` to create forms and a CRUD (create, read, update, delete) controller based on an existing Doctrine entity (which, incidentally, you can generate with the `php app/console doctrine:generate:entity` command).
|
`php app/console list` shows there are no such command to generate controllers.
You may go for manual process.
|
8,794,937
|
I know how to create bundle using console. Now I want to add second controller to generated bundle, how can I do it from console. (php app/console generate:controller doesn't work)
|
2012/01/09
|
[
"https://Stackoverflow.com/questions/8794937",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/783353/"
] |
Since version `2.2` you can use
```
php app/console generate:controller
```
Documentation [here](http://symfony.com/doc/current/bundles/SensioGeneratorBundle/commands/generate_controller.html).
|
You can use `php app/console doctrine:generate:crud` to create forms and a CRUD (create, read, update, delete) controller based on an existing Doctrine entity (which, incidentally, you can generate with the `php app/console doctrine:generate:entity` command).
|
8,794,937
|
I know how to create bundle using console. Now I want to add second controller to generated bundle, how can I do it from console. (php app/console generate:controller doesn't work)
|
2012/01/09
|
[
"https://Stackoverflow.com/questions/8794937",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/783353/"
] |
Since version `2.2` you can use
```
php app/console generate:controller
```
Documentation [here](http://symfony.com/doc/current/bundles/SensioGeneratorBundle/commands/generate_controller.html).
|
`php app/console list` shows there are no such command to generate controllers.
You may go for manual process.
|
389,953
|
You often *plunge* into the sea or *plunge* you hands into your pockets.
Can the word be used to describe a "horizontal immersion"?
Example sentence:
>
> She opened the door and **plunged** into the blinding sun.
>
>
>
If not, what's a more appropriate word?
|
2017/05/19
|
[
"https://english.stackexchange.com/questions/389953",
"https://english.stackexchange.com",
"https://english.stackexchange.com/users/202294/"
] |
It's perfectly acceptable, but you might want to consider the "literal baggage," for lack of a better word, that the figurative term carries with it.
Take the OED literal definition that this derives from:
>
> To thrust, throw, or drop into or in a liquid, penetrable substance, deep pit, container, etc.; to immerse, to submerge.
>
>
>
In any case that you use the word "plunge," readers will associate it with the literal meaning to derive its figurative meaning. If you want to invoke feelings of falling deep into something, then it's appropriate. Just be aware that the use **ordinarily** refers to falling or pushing *in a downward direction*.
|
Almost all definitions of Plunging seem to imply that it's a word describing vertical descent.
[Merriam Webster](https://www.merriam-webster.com/thesaurus/plunge) thesaurus includes the following words as related:
>
> dip, immersion, submersion; fall, plump, slip, spill, stumble, tumble; descent, drop; belly flop, header, jackknife, swan dive
>
>
>
None of them indicating a horizontal direction.
Also, [Thesaurus](http://www.thesaurus.com/browse/plunging) synonyms imply a vertical nature.
It may be acceptable to use *plunging* in the sentence but you may not get the intended effect on a reader.
Maybe the following will suit better
>
> She opened the door and **stepped** into the blinding sun.
>
>
>
or
>
> She opened the door and **charged** into the blinding sun.
>
>
>
|
389,953
|
You often *plunge* into the sea or *plunge* you hands into your pockets.
Can the word be used to describe a "horizontal immersion"?
Example sentence:
>
> She opened the door and **plunged** into the blinding sun.
>
>
>
If not, what's a more appropriate word?
|
2017/05/19
|
[
"https://english.stackexchange.com/questions/389953",
"https://english.stackexchange.com",
"https://english.stackexchange.com/users/202294/"
] |
It's perfectly acceptable, but you might want to consider the "literal baggage," for lack of a better word, that the figurative term carries with it.
Take the OED literal definition that this derives from:
>
> To thrust, throw, or drop into or in a liquid, penetrable substance, deep pit, container, etc.; to immerse, to submerge.
>
>
>
In any case that you use the word "plunge," readers will associate it with the literal meaning to derive its figurative meaning. If you want to invoke feelings of falling deep into something, then it's appropriate. Just be aware that the use **ordinarily** refers to falling or pushing *in a downward direction*.
|
"Plunged" is a good word to use, but "sunlight" would be much better then "sun".
Otherwise, you could say "emerged" into the sunlight.
One historical example shows both "plunged" and "emerged" would be good choices:
[Reports of Observations of the Total Eclipse of the Sun, August 7, 1869](https://books.google.com/books?id=c00QPyT2IjMC&pg=PA108&lpg=PA108&dq=%22plunged%20into%20%22%20sunlight&source=bl&ots=WqTGBpgo99&sig=zznbtkA2vX7fQjSBLuwgE1CF9vY&hl=en&sa=X&ved=0ahUKEwjT0aK25vvTAhUF6yYKHaqOBnkQ6AEIUTAI#v=onepage&q=%22plunged%20into%20%22%20sunlight&f=false):
>
> ...observed with what frightful rapidity we were plunged into the dark shadow, and the contrary effect as we emerged into sunlight
>
>
>
|
389,953
|
You often *plunge* into the sea or *plunge* you hands into your pockets.
Can the word be used to describe a "horizontal immersion"?
Example sentence:
>
> She opened the door and **plunged** into the blinding sun.
>
>
>
If not, what's a more appropriate word?
|
2017/05/19
|
[
"https://english.stackexchange.com/questions/389953",
"https://english.stackexchange.com",
"https://english.stackexchange.com/users/202294/"
] |
The OED's first meaning of ***plunge*** involves transitively thrusting, throwing or dropping something (or oneself) into a liquid - from the French ***plonger*** - *to jump into water, to submerge, or sink*
However, sense 4 (intransitive) of the verb covers precisely the circumstance you relate:
>
> 4. intr. To move or travel forth, on, etc., rapidly, abruptly, or recklessly; to move with a rush or sudden impulse into or out of; to
> hurtle, career. Also fig. 1726 W. Broome in Pope et al. tr. Homer
> Odyssey V. xxiii. 256 He views the strand, And plunging forth with
> transport grasps the land.
>
>
> 1806 T. Jefferson Let. 5 July in Writings (1984) 1165 If the
> executive is to keep all other information to himself, and the House
> to plunge on in the dark, it becomes a government of chance and not of
> design.
>
>
> 1834 L. Ritchie Wanderings by Seine 110 We..plunged into the high
> road leading to Duclair.
>
>
> 1885 Manch. Examiner 22 Jan. 5/2 Under a well-organised fire from
> the works, the Arabs plunged forth upon the square.
>
>
> 1891 C. Graves Field of Tares iv. vi. 241 The Norwich Express,
> plunging out of Liverpool Street Station.
>
>
> a1902 F. Norris Pit (1903) x. 400 She had committed herself now;
> recklessly she plunged on.
>
>
> 1954 Times Lit. Suppl. 12 Nov. 714/4 As the Age of Reason plunged
> towards revolution, Juvenal was carried like a banner in the van of
> the attack.
>
>
> 1990 A. Stevens On Jung ii. 18 The dreamer might see a train,
> carrying him home, plunging in and out of a series of tunnels.
>
>
> 2004 Derby Evening Tel. (Nexis) 16 Mar. 6 If the Germans had
> captured crossings over the Trent, they could have plunged in any
> direction.
>
>
>
|
Almost all definitions of Plunging seem to imply that it's a word describing vertical descent.
[Merriam Webster](https://www.merriam-webster.com/thesaurus/plunge) thesaurus includes the following words as related:
>
> dip, immersion, submersion; fall, plump, slip, spill, stumble, tumble; descent, drop; belly flop, header, jackknife, swan dive
>
>
>
None of them indicating a horizontal direction.
Also, [Thesaurus](http://www.thesaurus.com/browse/plunging) synonyms imply a vertical nature.
It may be acceptable to use *plunging* in the sentence but you may not get the intended effect on a reader.
Maybe the following will suit better
>
> She opened the door and **stepped** into the blinding sun.
>
>
>
or
>
> She opened the door and **charged** into the blinding sun.
>
>
>
|
389,953
|
You often *plunge* into the sea or *plunge* you hands into your pockets.
Can the word be used to describe a "horizontal immersion"?
Example sentence:
>
> She opened the door and **plunged** into the blinding sun.
>
>
>
If not, what's a more appropriate word?
|
2017/05/19
|
[
"https://english.stackexchange.com/questions/389953",
"https://english.stackexchange.com",
"https://english.stackexchange.com/users/202294/"
] |
The OED's first meaning of ***plunge*** involves transitively thrusting, throwing or dropping something (or oneself) into a liquid - from the French ***plonger*** - *to jump into water, to submerge, or sink*
However, sense 4 (intransitive) of the verb covers precisely the circumstance you relate:
>
> 4. intr. To move or travel forth, on, etc., rapidly, abruptly, or recklessly; to move with a rush or sudden impulse into or out of; to
> hurtle, career. Also fig. 1726 W. Broome in Pope et al. tr. Homer
> Odyssey V. xxiii. 256 He views the strand, And plunging forth with
> transport grasps the land.
>
>
> 1806 T. Jefferson Let. 5 July in Writings (1984) 1165 If the
> executive is to keep all other information to himself, and the House
> to plunge on in the dark, it becomes a government of chance and not of
> design.
>
>
> 1834 L. Ritchie Wanderings by Seine 110 We..plunged into the high
> road leading to Duclair.
>
>
> 1885 Manch. Examiner 22 Jan. 5/2 Under a well-organised fire from
> the works, the Arabs plunged forth upon the square.
>
>
> 1891 C. Graves Field of Tares iv. vi. 241 The Norwich Express,
> plunging out of Liverpool Street Station.
>
>
> a1902 F. Norris Pit (1903) x. 400 She had committed herself now;
> recklessly she plunged on.
>
>
> 1954 Times Lit. Suppl. 12 Nov. 714/4 As the Age of Reason plunged
> towards revolution, Juvenal was carried like a banner in the van of
> the attack.
>
>
> 1990 A. Stevens On Jung ii. 18 The dreamer might see a train,
> carrying him home, plunging in and out of a series of tunnels.
>
>
> 2004 Derby Evening Tel. (Nexis) 16 Mar. 6 If the Germans had
> captured crossings over the Trent, they could have plunged in any
> direction.
>
>
>
|
"Plunged" is a good word to use, but "sunlight" would be much better then "sun".
Otherwise, you could say "emerged" into the sunlight.
One historical example shows both "plunged" and "emerged" would be good choices:
[Reports of Observations of the Total Eclipse of the Sun, August 7, 1869](https://books.google.com/books?id=c00QPyT2IjMC&pg=PA108&lpg=PA108&dq=%22plunged%20into%20%22%20sunlight&source=bl&ots=WqTGBpgo99&sig=zznbtkA2vX7fQjSBLuwgE1CF9vY&hl=en&sa=X&ved=0ahUKEwjT0aK25vvTAhUF6yYKHaqOBnkQ6AEIUTAI#v=onepage&q=%22plunged%20into%20%22%20sunlight&f=false):
>
> ...observed with what frightful rapidity we were plunged into the dark shadow, and the contrary effect as we emerged into sunlight
>
>
>
|
59,893,690
|
```
$scope.vergleich = function () {
if ($scope.relrechtsform.indexOf(dataService.dic.alt.rechtsformKanlei || dataService.dic.neu.rechtsformKanlei ) !== -1) {
return true
} else {
return false; }
}
}
```
I am currently student and intelliJ tells me I have to simplify this if-statement but I have no idea how. Maybe somebody can help me.
|
2020/01/24
|
[
"https://Stackoverflow.com/questions/59893690",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
The simplification is probably that, if `condition` is a boolean, :
```
if (condition) {
return true;
}
else {
return false;
}
```
is equivalent to
```
return condition;
```
**However** there also seems to be a logical error in your test.
```
$scope.relrechtsform.indexOf(dataService.dic.alt.rechtsformKanlei ||
dataService.dic.neu.rechtsformKanlei ) !== -1
```
Does **not** mean the same thing as :
```
$scope.relrechtsform.indexOf(dataService.dic.alt.rechtsformKanlei) !== -1 ||
$scope.relrechtsform.indexOf(dataService.dic.neu.rechtsformKanlei) !== -1
```
|
You can just use your condition instead of using `IF else` statement -:
```
$scope.vergleich = function () {
return ($scope.relrechtsform.indexOf(dataService.dic.alt.rechtsformKanlei ||
dataService.dic.neu.rechtsformKanlei ) !== -1);
};
```
|
59,893,690
|
```
$scope.vergleich = function () {
if ($scope.relrechtsform.indexOf(dataService.dic.alt.rechtsformKanlei || dataService.dic.neu.rechtsformKanlei ) !== -1) {
return true
} else {
return false; }
}
}
```
I am currently student and intelliJ tells me I have to simplify this if-statement but I have no idea how. Maybe somebody can help me.
|
2020/01/24
|
[
"https://Stackoverflow.com/questions/59893690",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
The simplification is probably that, if `condition` is a boolean, :
```
if (condition) {
return true;
}
else {
return false;
}
```
is equivalent to
```
return condition;
```
**However** there also seems to be a logical error in your test.
```
$scope.relrechtsform.indexOf(dataService.dic.alt.rechtsformKanlei ||
dataService.dic.neu.rechtsformKanlei ) !== -1
```
Does **not** mean the same thing as :
```
$scope.relrechtsform.indexOf(dataService.dic.alt.rechtsformKanlei) !== -1 ||
$scope.relrechtsform.indexOf(dataService.dic.neu.rechtsformKanlei) !== -1
```
|
[Tân's version](https://stackoverflow.com/a/59893737/6320039) is a correct answer to your question. However, with recent JavaScript you can simplify even more thanks to [`array.includes`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/includes):
```js
$scope.vergleich = () =>
$scope.relrechtsform.includes(dataService.dic.alt.rechtsformKanlei || dataService.dic.neu.rechtsformKanlei)
```
|
59,893,690
|
```
$scope.vergleich = function () {
if ($scope.relrechtsform.indexOf(dataService.dic.alt.rechtsformKanlei || dataService.dic.neu.rechtsformKanlei ) !== -1) {
return true
} else {
return false; }
}
}
```
I am currently student and intelliJ tells me I have to simplify this if-statement but I have no idea how. Maybe somebody can help me.
|
2020/01/24
|
[
"https://Stackoverflow.com/questions/59893690",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
Maybe you're looking for this:
```
$scope.vergleich = function () {
return $scope.relrechtsform.indexOf(dataService.dic.alt.rechtsformKanlei || dataService.dic.neu.rechtsformKanlei ) !== -1;
};
```
|
You can just use your condition instead of using `IF else` statement -:
```
$scope.vergleich = function () {
return ($scope.relrechtsform.indexOf(dataService.dic.alt.rechtsformKanlei ||
dataService.dic.neu.rechtsformKanlei ) !== -1);
};
```
|
59,893,690
|
```
$scope.vergleich = function () {
if ($scope.relrechtsform.indexOf(dataService.dic.alt.rechtsformKanlei || dataService.dic.neu.rechtsformKanlei ) !== -1) {
return true
} else {
return false; }
}
}
```
I am currently student and intelliJ tells me I have to simplify this if-statement but I have no idea how. Maybe somebody can help me.
|
2020/01/24
|
[
"https://Stackoverflow.com/questions/59893690",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
Maybe you're looking for this:
```
$scope.vergleich = function () {
return $scope.relrechtsform.indexOf(dataService.dic.alt.rechtsformKanlei || dataService.dic.neu.rechtsformKanlei ) !== -1;
};
```
|
[Tân's version](https://stackoverflow.com/a/59893737/6320039) is a correct answer to your question. However, with recent JavaScript you can simplify even more thanks to [`array.includes`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/includes):
```js
$scope.vergleich = () =>
$scope.relrechtsform.includes(dataService.dic.alt.rechtsformKanlei || dataService.dic.neu.rechtsformKanlei)
```
|
59,893,690
|
```
$scope.vergleich = function () {
if ($scope.relrechtsform.indexOf(dataService.dic.alt.rechtsformKanlei || dataService.dic.neu.rechtsformKanlei ) !== -1) {
return true
} else {
return false; }
}
}
```
I am currently student and intelliJ tells me I have to simplify this if-statement but I have no idea how. Maybe somebody can help me.
|
2020/01/24
|
[
"https://Stackoverflow.com/questions/59893690",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
[Tân's version](https://stackoverflow.com/a/59893737/6320039) is a correct answer to your question. However, with recent JavaScript you can simplify even more thanks to [`array.includes`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/includes):
```js
$scope.vergleich = () =>
$scope.relrechtsform.includes(dataService.dic.alt.rechtsformKanlei || dataService.dic.neu.rechtsformKanlei)
```
|
You can just use your condition instead of using `IF else` statement -:
```
$scope.vergleich = function () {
return ($scope.relrechtsform.indexOf(dataService.dic.alt.rechtsformKanlei ||
dataService.dic.neu.rechtsformKanlei ) !== -1);
};
```
|
58,843,192
|
I have two different JSON object. One object is empList and other one is holidayList.
I want to add hours from each JSON object.Andthe sum of hours should be pushed to sumHoursList JSON object.I am doing this using Angular6.
I am not getting exactly how to iterate this to get the required result.
**Basically I want to add hours from both the datalist of empList , to that want to add hours from holiday list, and the sum value should
append in sumhourlist**
Below is my code.
```
this.empList = [
{
'id': 1,
'name': 'Name1',
datalist: [
{
"date": 1,
"hours": 6
},
{
"date": 2,
"hours": 0
},
{
"date": 3,
"hours": 12
}
]
},
{
'id': 2,
'name': 'Name2',
datalist:[
{
"date": 1,
"hours": 0
},
{
"date": 2,
"hours": 8
},
{
"date": 3,
"hours": 0
}
]
},
];
this.holidayList=[
{
"date": 1,
"hours": 0
},
{
"date": 2,
"hours": 8
},
{
"date": 3,
"hours": 12
}
]
sumHoursList = [
{
"date": 1,
"hours": 6
},
{
"date": 2,
"hours": 16
},
{
"date": 3,
"hours": 24
}
]
```
Can anyone please help me how to do this.
|
2019/11/13
|
[
"https://Stackoverflow.com/questions/58843192",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4675072/"
] |
Try modifying your ingress objects rewrite-target & path as below:
```
nginx.ingress.kubernetes.io/rewrite-target: /$1
path: /(.*)
```
and make sure you checked this [documentation](https://kubernetes.github.io/ingress-nginx/examples/rewrite/#rewrite-target)
Once you tried this let me know.
|
If you dont want to use @kishorebjv's solution another way would be to make the change in the `nginx.conf` itself.
```
location /home/?(.*) {
try_files $1 $1/ /index.html =404;
}
```
|
299,535
|
Chrome always quit when I click on the `X` button on a tab, without asking me anything!
Even when I close Chrome he do not alert me if I am willing to relay close it?
Many times it happened that accidentally I clicked on `X` button.
|
2011/06/20
|
[
"https://superuser.com/questions/299535",
"https://superuser.com",
"https://superuser.com/users/71640/"
] |
If you accidently close all your tabs you can reload Chrome and press `CTRL` + `SHIFT` + `T`.
This will restore your previous session for all your tabs.
You could also look for a Chrome extension such as [Windows Close Protector](https://chrome.google.com/webstore/detail/lnpifgapnmpninomacbhdlconlpikdai).
|
You can also "restore the last session," which will include text in text boxes, if you closed the program accidentally.
* Go to your Chrome shortcut, right click, select "send to desktop (create shortcut)"
* The new shortcut will be named Google Chrome (2), rename this to Restore Last Session
* Right click and select properties
* At the end of the target field (....\chrome.exe"), leave a space and add `--restore-last-session`
* Click Apply, then OK.
So now you have an easy way to get back all the tabs.
Note: It won't restore incognito windows.
|
299,535
|
Chrome always quit when I click on the `X` button on a tab, without asking me anything!
Even when I close Chrome he do not alert me if I am willing to relay close it?
Many times it happened that accidentally I clicked on `X` button.
|
2011/06/20
|
[
"https://superuser.com/questions/299535",
"https://superuser.com",
"https://superuser.com/users/71640/"
] |
If you accidently close all your tabs you can reload Chrome and press `CTRL` + `SHIFT` + `T`.
This will restore your previous session for all your tabs.
You could also look for a Chrome extension such as [Windows Close Protector](https://chrome.google.com/webstore/detail/lnpifgapnmpninomacbhdlconlpikdai).
|
If you don't mind installing a Chrome extension...
The Chrome Toolbox extension, written by Google, has an option called "Confirm before closing multiple tabs." You can find it here:
<https://chrome.google.com/webstore/detail/fjccknnhdnkbanjilpjddjhmkghmachn>
It has a number of other interesting options also.
|
299,535
|
Chrome always quit when I click on the `X` button on a tab, without asking me anything!
Even when I close Chrome he do not alert me if I am willing to relay close it?
Many times it happened that accidentally I clicked on `X` button.
|
2011/06/20
|
[
"https://superuser.com/questions/299535",
"https://superuser.com",
"https://superuser.com/users/71640/"
] |
Just to update this answer, Chrome now has a menu option for this. You can require a long press of CMD-Q so that any accidental press won't exit chrome.
On Mac click on the Chrome menu and check: "Warn Before Quitting"
|
You can also "restore the last session," which will include text in text boxes, if you closed the program accidentally.
* Go to your Chrome shortcut, right click, select "send to desktop (create shortcut)"
* The new shortcut will be named Google Chrome (2), rename this to Restore Last Session
* Right click and select properties
* At the end of the target field (....\chrome.exe"), leave a space and add `--restore-last-session`
* Click Apply, then OK.
So now you have an easy way to get back all the tabs.
Note: It won't restore incognito windows.
|
299,535
|
Chrome always quit when I click on the `X` button on a tab, without asking me anything!
Even when I close Chrome he do not alert me if I am willing to relay close it?
Many times it happened that accidentally I clicked on `X` button.
|
2011/06/20
|
[
"https://superuser.com/questions/299535",
"https://superuser.com",
"https://superuser.com/users/71640/"
] |
If you don't mind installing a Chrome extension...
The Chrome Toolbox extension, written by Google, has an option called "Confirm before closing multiple tabs." You can find it here:
<https://chrome.google.com/webstore/detail/fjccknnhdnkbanjilpjddjhmkghmachn>
It has a number of other interesting options also.
|
You can also "restore the last session," which will include text in text boxes, if you closed the program accidentally.
* Go to your Chrome shortcut, right click, select "send to desktop (create shortcut)"
* The new shortcut will be named Google Chrome (2), rename this to Restore Last Session
* Right click and select properties
* At the end of the target field (....\chrome.exe"), leave a space and add `--restore-last-session`
* Click Apply, then OK.
So now you have an easy way to get back all the tabs.
Note: It won't restore incognito windows.
|
299,535
|
Chrome always quit when I click on the `X` button on a tab, without asking me anything!
Even when I close Chrome he do not alert me if I am willing to relay close it?
Many times it happened that accidentally I clicked on `X` button.
|
2011/06/20
|
[
"https://superuser.com/questions/299535",
"https://superuser.com",
"https://superuser.com/users/71640/"
] |
Just to update this answer, Chrome now has a menu option for this. You can require a long press of CMD-Q so that any accidental press won't exit chrome.
On Mac click on the Chrome menu and check: "Warn Before Quitting"
|
If you don't mind installing a Chrome extension...
The Chrome Toolbox extension, written by Google, has an option called "Confirm before closing multiple tabs." You can find it here:
<https://chrome.google.com/webstore/detail/fjccknnhdnkbanjilpjddjhmkghmachn>
It has a number of other interesting options also.
|
20,699,509
|
This html form and the related php code works pretty well together. I need to add a word counter. Any suggestions.
```
<form action="form.php" method="POST">
<fieldset>
<input type="hidden" name='counter' value='2'/>
<p><label for="heading1"></label>
<input type="text" name="heading1" size="60" /></p>
<p><label for="input1"></label>
<textarea cols="width" rows="height" name="input1">...</textarea></p>
<p><label for="heading2"></label>
<input type="text" name="heading2" size="60" value="first para title..."></p>
<p><label for="input2"></label>
<textarea cols="width" rows="height" name="input2">...</textarea></p>
<br />
<fieldset>
<input type="submit" value="" />
<input type="reset" value="" />
</fieldset>
</form>
```
The related php code is found below.
```
<?php
$count=$_REQUEST['counter'];
for($i=1;$i<=$count;$i++)
{
echo "<p>" . $_REQUEST['heading'.$i] . "</p>";
echo "<p>" . $_REQUEST['input'.$i]. "</p>";
}
?>
```
|
2013/12/20
|
[
"https://Stackoverflow.com/questions/20699509",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2714362/"
] |
Example:
```
<textarea name="input1" onkeyup="window.alert(document.getElementsByName('input1')[0].value.trim().split(' ').length);"></textarea>
```
|
Use javascript, with an event on the change in the textarea(s).
Then you count the word when typing and update the counter.
|
20,699,509
|
This html form and the related php code works pretty well together. I need to add a word counter. Any suggestions.
```
<form action="form.php" method="POST">
<fieldset>
<input type="hidden" name='counter' value='2'/>
<p><label for="heading1"></label>
<input type="text" name="heading1" size="60" /></p>
<p><label for="input1"></label>
<textarea cols="width" rows="height" name="input1">...</textarea></p>
<p><label for="heading2"></label>
<input type="text" name="heading2" size="60" value="first para title..."></p>
<p><label for="input2"></label>
<textarea cols="width" rows="height" name="input2">...</textarea></p>
<br />
<fieldset>
<input type="submit" value="" />
<input type="reset" value="" />
</fieldset>
</form>
```
The related php code is found below.
```
<?php
$count=$_REQUEST['counter'];
for($i=1;$i<=$count;$i++)
{
echo "<p>" . $_REQUEST['heading'.$i] . "</p>";
echo "<p>" . $_REQUEST['input'.$i]. "</p>";
}
?>
```
|
2013/12/20
|
[
"https://Stackoverflow.com/questions/20699509",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2714362/"
] |
Like this:
```
var output = document.getElementById("counter"),
textarea = document.getElementById("textarea");
textarea.onkeyup = function (event) {
var words = textarea.value.split(" ");
output.value = words.length;
};
```
To make it easier, add IDs to your HTML elements like this:
```
<input type="hidden" name="counter" id="counter" value="0"/>
<textarea cols="width" rows="height" name="input2" id="textarea">...</textarea>
```
What this does: Every time the user releases types a letter into the textarea it will take the contents, split it on spaces and counts the number of words which is inserted into your hidden `counter` field. When the form is submitted the number of words will also be sent to the server.
However, if you don't need the number of words in the client (for instance showing the user how many words she has typed) then I suggest you do this in PHP. Look at the `str_split` function.
|
Use javascript, with an event on the change in the textarea(s).
Then you count the word when typing and update the counter.
|
20,699,509
|
This html form and the related php code works pretty well together. I need to add a word counter. Any suggestions.
```
<form action="form.php" method="POST">
<fieldset>
<input type="hidden" name='counter' value='2'/>
<p><label for="heading1"></label>
<input type="text" name="heading1" size="60" /></p>
<p><label for="input1"></label>
<textarea cols="width" rows="height" name="input1">...</textarea></p>
<p><label for="heading2"></label>
<input type="text" name="heading2" size="60" value="first para title..."></p>
<p><label for="input2"></label>
<textarea cols="width" rows="height" name="input2">...</textarea></p>
<br />
<fieldset>
<input type="submit" value="" />
<input type="reset" value="" />
</fieldset>
</form>
```
The related php code is found below.
```
<?php
$count=$_REQUEST['counter'];
for($i=1;$i<=$count;$i++)
{
echo "<p>" . $_REQUEST['heading'.$i] . "</p>";
echo "<p>" . $_REQUEST['input'.$i]. "</p>";
}
?>
```
|
2013/12/20
|
[
"https://Stackoverflow.com/questions/20699509",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2714362/"
] |
Like this:
```
var output = document.getElementById("counter"),
textarea = document.getElementById("textarea");
textarea.onkeyup = function (event) {
var words = textarea.value.split(" ");
output.value = words.length;
};
```
To make it easier, add IDs to your HTML elements like this:
```
<input type="hidden" name="counter" id="counter" value="0"/>
<textarea cols="width" rows="height" name="input2" id="textarea">...</textarea>
```
What this does: Every time the user releases types a letter into the textarea it will take the contents, split it on spaces and counts the number of words which is inserted into your hidden `counter` field. When the form is submitted the number of words will also be sent to the server.
However, if you don't need the number of words in the client (for instance showing the user how many words she has typed) then I suggest you do this in PHP. Look at the `str_split` function.
|
Example:
```
<textarea name="input1" onkeyup="window.alert(document.getElementsByName('input1')[0].value.trim().split(' ').length);"></textarea>
```
|
11,240,723
|
I have an issue of alphabetically sorting the contacts picked from the address book into section headers . I can arrange them alphabetically without the section headers but how to put them according to the names of the contacts ? I do not want to use the NSDictionary as I am able to do the sorting without it. Please view the code below :-
```
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return [arrayForLastName count];
}
-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
return [[alphabets sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)] objectAtIndex:section];
}
- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView{
return [NSArray arrayWithObjects:@"A",@"B",@"C",@"D",@"E",@"F",@"G",@"H",@"I",@"J",@"K",@"L",@"M",@"N",@"O",@"P",@"Q",@"R",@"S",@"T",@"U",@"V",@"W",@"X",@"Y",@"Z", nil];
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return [arrayForLastName count];
}
```
Any help would be appreciated thanx :)
|
2012/06/28
|
[
"https://Stackoverflow.com/questions/11240723",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1479368/"
] |
You can achieve this in following way -
1.Create an index array that contains all the required index -
```
NSArray *indexArray = [NSArray arrayWithObjects:@"A",@"B",@"C",@"D",@"E",@"F",@"G",@"H",@"I",@"J",@"K",@"L",@"M",@"N",@"O",@"P",@"Q",@"R",@"S",@"T",@"U",@"V",@"W",@"X",@"Y",@"Z", nil];
```
2.For Each index you need to have an array that will display row for those sections. SO you can have a dictionary that contain an array corresponding to each index.
Check this tutorial, it will help you in implementing this- <http://www.icodeblog.com/2010/12/10/implementing-uitableview-sections-from-an-nsarray-of-nsdictionary-objects/>
|
Try this code in table delegate methode.
```
1) - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return [dataArray1 count];
}
```
**return number of section in your table view.**
```
2) -(NSMutableArray *)selectedarray:(NSString *)countrynmae
{
NSString *strQuery=[NSString stringWithFormat:@" select * from Globle where Country='%@'",countrynmae];
NSMutableArray *dataarray=[Database executeQuery:strQuery];
return dataarray;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
NSDictionary *dict =[dataArray1 objectAtIndex:section];
NSString *strcountryname=[dict objectForKey:@"Country"];
NSMutableArray *arr6 = [self selectedarray:strcountryname ];
return [arr6 count];
}
```
**Return number of row in particular section**
```
3) - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
// create the parent view that will hold header Label
UIView* customView = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, 300.0, 44.0)];
// create the button object
UILabel * headerLabel = [[UILabel alloc] initWithFrame:CGRectZero];
headerLabel.backgroundColor = [UIColor clearColor];
headerLabel.opaque = NO;
headerLabel.textColor = [UIColor whiteColor];
headerLabel.font = [UIFont boldSystemFontOfSize:16];
headerLabel.frame = CGRectMake(20.0, -14.0, 300.0, 30.0);
NSDictionary *dict =[dataArray1 objectAtIndex:section];
headerLabel.text=[dict objectForKey:@"Country"];
headerLabel.textColor=[UIColor redColor];
[customView addSubview:headerLabel];
return customView;
}
```
**set header name for section**
```
4) - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
```
{
```
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell=[[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
cell.textLabel.textColor=[UIColor whiteColor];
cell.backgroundColor=[UIColor clearColor];
}
NSDictionary *dict =[dataArray1 objectAtIndex:indexPath.section];
NSString *countryname = [dict objectForKey:@"Country"];
NSString *strQuery = [NSString stringWithFormat:@"Select * from Globle where Country = '%@'",countryname];
NSMutableArray *arr = [Database executeQuery:strQuery];
NSDictionary *dict1 = [arr objectAtIndex:indexPath.row];
cell.textLabel.text=[dict1 objectForKey:@"Name"];
cell.textLabel.numberOfLines=1;
cell.textLabel.textColor=[UIColor blackColor];
cell.backgroundColor=[UIColor clearColor];
cell.textLabel.textAlignment=UITextAlignmentCenter;
NSString *strImage=[dict1 objectForKey:@"ImageName"];
UIImageView *imageView1 = [[UIImageView alloc] init];
UIImage *image1 = [[UIImage alloc] initWithContentsOfFile:
[[NSBundle mainBundle] pathForResource:strImage ofType:@"jpg"]];
imageView1.image = image1;
imageView1.frame = CGRectMake(6,2,50,42); // position it to the middle
[cell.contentView addSubview:imageView1];
return cell;
[tbl reloadData];
}
```
**return cell in uitable view**
|
17,649,574
|
I am migrating some plugin from `Linux` to `Windows`.
Plugin is written using `Perl` and it has the function called `system()` that will execute the shell commands.
But I am migrating to Windows now. Any way I can run the linux command in windows using system() Per function?
Some `Perl Module` avail for this ?
|
2013/07/15
|
[
"https://Stackoverflow.com/questions/17649574",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/799046/"
] |
You can run the `system()` command but there are caveats. A nice description is contained in [*Using system or exec safely on Windows*](http://blogs.perl.org/users/graham_knop/2011/12/using-system-or-exec-safely-on-windows.html). This article resulted in the [Win32::ShellQuote](http://p3rl.org/Win32%3a%3aShellQuote) module.
|
You want to run a linux command vie Perl in a windows shell? If so, try a Linux environment like Cygwin ([www.cygwin.com](http://www.cygwin.com)). Otherwise you have to migrate your system calls as well.
|
45,988
|
On Windows I can use Utilu Firefox collection (there also ie collection on his site).
How can I use multiple browser versions to see how my website works in different versions of different browsers in OS X?
For example I want to install [browsers with biggest market share](https://en.wikipedia.org/wiki/Browser_market_share#Summary_table):
* Internet Explorer
* Firefox 3.6, latest and previous
* Google Chrome latest and previous
* Safari (any older versions possible)
* Opera
|
2012/03/26
|
[
"https://apple.stackexchange.com/questions/45988",
"https://apple.stackexchange.com",
"https://apple.stackexchange.com/users/14692/"
] |
Firefox
-------
[Firefoxes](https://github.com/omgmog/install-all-firefox) is a shell scripts that will install all major versions of Firefox on OS X, and set up separate profiles so you can use them simultaneously. Currently it installs:
* Firefox 2.0.0.20
* Firefox 3.0.19
* Firefox 3.5.9
* Firefox 3.6.28
* Firefox 4.0.1
* Firefox 5.0.1
* Firefox 6.0.1
* Firefox 7.0.1
* Firefox 8.0.1
* Firefox 9.0.1
* Firefox 10.0.2
* Firefox 11.0
* Firefox Beta
* Firefox Aurora
* Firefox Nightly
* Firefox UX Nightly
You can set it up so it only installs the specific versions you want.
Optionally, the script can install Firebug for each version of Firefox too.
It will also set icons that contain the version number:

Safari
------
For Safari, check out [Multi-Safari](http://michelf.com/projects/multi-safari/).
Chrome/Chromium
---------------
For Chrome/Chromium, install any version you want, change the app name from `Chromium.app` to e.g. `Chromium 19.app` for clarity, then [disable auto-updates](http://dev.chromium.org/administrators/turning-off-auto-updates) for that version.
Opera
-----
Download old Opera versions here: <ftp://ftp.opera.com/pub/opera/mac/>
IE
--
Get VirtualBox and then run [this `ievms` script](https://github.com/xdissent/ievms). It will automatically download legal Windows images for testing purposes and set up virtual machines for every IE version you need.
|
[MultiFirefox](http://davemartorana.com/multifirefox/) supports what you need, and seems to have good reviews. A drawback with it is that it doesn't support keeping multiple versions open simultaneously.
|
45,988
|
On Windows I can use Utilu Firefox collection (there also ie collection on his site).
How can I use multiple browser versions to see how my website works in different versions of different browsers in OS X?
For example I want to install [browsers with biggest market share](https://en.wikipedia.org/wiki/Browser_market_share#Summary_table):
* Internet Explorer
* Firefox 3.6, latest and previous
* Google Chrome latest and previous
* Safari (any older versions possible)
* Opera
|
2012/03/26
|
[
"https://apple.stackexchange.com/questions/45988",
"https://apple.stackexchange.com",
"https://apple.stackexchange.com/users/14692/"
] |
Firefox
-------
[Firefoxes](https://github.com/omgmog/install-all-firefox) is a shell scripts that will install all major versions of Firefox on OS X, and set up separate profiles so you can use them simultaneously. Currently it installs:
* Firefox 2.0.0.20
* Firefox 3.0.19
* Firefox 3.5.9
* Firefox 3.6.28
* Firefox 4.0.1
* Firefox 5.0.1
* Firefox 6.0.1
* Firefox 7.0.1
* Firefox 8.0.1
* Firefox 9.0.1
* Firefox 10.0.2
* Firefox 11.0
* Firefox Beta
* Firefox Aurora
* Firefox Nightly
* Firefox UX Nightly
You can set it up so it only installs the specific versions you want.
Optionally, the script can install Firebug for each version of Firefox too.
It will also set icons that contain the version number:

Safari
------
For Safari, check out [Multi-Safari](http://michelf.com/projects/multi-safari/).
Chrome/Chromium
---------------
For Chrome/Chromium, install any version you want, change the app name from `Chromium.app` to e.g. `Chromium 19.app` for clarity, then [disable auto-updates](http://dev.chromium.org/administrators/turning-off-auto-updates) for that version.
Opera
-----
Download old Opera versions here: <ftp://ftp.opera.com/pub/opera/mac/>
IE
--
Get VirtualBox and then run [this `ievms` script](https://github.com/xdissent/ievms). It will automatically download legal Windows images for testing purposes and set up virtual machines for every IE version you need.
|
Internet Explorer
=================
Of course there is [Internet Explorer for Mac (PPC)](https://en.wikipedia.org/wiki/Internet_Explorer_for_Mac) but it's not very useful because it's based on different rendering engine (Tasman). It will run on OSX versions with Rosetta support. It can be downloaded from [Internet Archive](http://web.archive.org/web/20051221154243/www.microsoft.com/mac/downloads.aspx?pid=download&location=/mac/DOWNLOAD/IE/ie5_osx.xml&secid=30&ssid=10&flgnosysreq=True).
Some [Windows Internet Explorer versions](http://appdb.winehq.org/objectManager.php?sClass=application&iId=25) do work in wine (winetricks helps a lot):

Safari
======
There is [multi-safari](http://michelf.com/projects/multi-safari/) project. There are 1.x - 4.x versions and they may work or not depending on your OSX version (look at [compatibility grid](http://michelf.com/projects/multi-safari/#compatibility-grid) on his site).
Firefox
=======
I've found, that it's enough just to rename .app and then run it with different Firefox profiles.
* download all required version
* copy .apk`s in temporary place an rename them so you can distinguish one version from another
* put all renamed version to /Applications folder
* run needed firefox with -ProfileManager option and make a profile for each firefox (just in case)
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.