Search is not available for this dataset
qid
int64 1
74.7M
| question
stringlengths 1
70k
| date
stringlengths 10
10
| metadata
sequence | response_j
stringlengths 0
115k
| response_k
stringlengths 0
60.5k
|
---|---|---|---|---|---|
28,148,414 | I have a query and have tried to do some research but i am having trouble even trying to google what i am looking for and how to word it. Currently each div has a label and then an input field. i have made all these input fields with rounded edges. my problem is when i click in the chosen area a rectangular border appears around the edge. the image can be viewed here: `http://www.tiikoni.com/tis/view/?id=6128132`
how can i change the appearance of this border?
This is is my css code:
```
div input{
border: 2px solid #a1a1a1;
padding: 10px 40px;
background: #dddddd;
width: 300px;
border-radius: 25px;
}
```
This is part of my html:
```
<div class="fourth">
<label> Confirm Password: </label>
<input type="text" name="cPassword" class="iBox" id="cPassword" onkeyup="passwordValidation()" placeholder="confirm it!" autocomplete="off">
<p id="combination"></p>
</div>
``` | 2015/01/26 | [
"https://Stackoverflow.com/questions/28148414",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4486219/"
] | One solution is to remove default outline on focus using:
```
div input:focus{
outline: none;
}
```
```css
div input {
border: 2px solid #a1a1a1;
padding: 10px 40px;
background: #dddddd;
width: 300px;
border-radius: 25px;
}
div input:focus {
outline: none;
}
```
```html
<div class="fourth">
<label>Confirm Password:</label>
<input type="text" name="cPassword" class="iBox" id="cPassword" onkeyup="passwordValidation()" placeholder="confirm it!" autocomplete="off" />
<p id="combination"></p>
</div>
``` | It is not a border but an outline, so you can style it using the `outline` property. But things depend on *how* it should be changed. Removing it, changing its color is etc. easy; but setting rounded corners is not (you can only fake it), see [Outline radius?](https://stackoverflow.com/questions/5394116/outline-radius)
Simply removing the outline is bad for usability and accessibility, since the outline, “focus rectangle”, shows the user where the focus us. You might consider compensating for this by using some other way of indicating the focus. One simple possibility is to change the border color or style or both. So when focused, the element does not get an outline but its border changes so that it resembles the focus rectangle. The following illustrates the techniques and makes the focus rather apparent; tune to fit your overall design:
```css
div input{
border: 2px solid #a1a1a1;
padding: 10px 40px;
background: #dddddd;
width: 300px;
border-radius: 25px;
}
div input:focus {
outline: none;
border-color: red;
background: #ffd;
}
```
```html
<div class="fourth">
<label for="cPassword"> Confirm Password: </label>
<input type="text" name="cPassword" class="iBox" id="cPassword" onkeyup="passwordValidation()" placeholder="confirm it!" autocomplete="off">
<p id="combination"></p>
</div>
``` |
108,718 | I have a little question about a 2x2 design that keeps on confusing me. If I have this kind of 2x2 design where I can have these combinations in the conditions.
No/No, Yes/No, No/Yes, Yes/Yes. The interaction effect is the effect of the two IVs, right? As the Yes/Yes condition consist of both IVs, is the Yes/Yes condition here the same as the interaction effect of A and B?
![2x2](https://i.stack.imgur.com/9eGfa.png) | 2014/07/21 | [
"https://stats.stackexchange.com/questions/108718",
"https://stats.stackexchange.com",
"https://stats.stackexchange.com/users/40037/"
] | There is no kernel that outperforms all other for all problems, even when the class of problems is reduced to a particular domain. Linear SVM are a popular choice for text classification, because many text classification problems are [linearly separable](http://www.cs.cornell.edu/people/tj/publications/joachims_98a.pdf), and because [they scale well to large amount of data](http://cseweb.ucsd.edu/~akmenon/ResearchExam.pdf).
Still, you may try the three of them (linear, polygonal and radial basis function) and see which one performs better. The additional advantage of linear SVM is that there is only one parameter to tune (the regularization term). For polygonal and RBF you need to perform grid search (search over combinations of values for the regularization term and the rest of parameters, like the degree of the polynomial, for example). | In general the 'RBF' kernel will give the best results. However, it does suffer when dealing with large datasets so I would first try 'RBF' and if that is taking to long try switching to a linear kernel. HTH. |
108,718 | I have a little question about a 2x2 design that keeps on confusing me. If I have this kind of 2x2 design where I can have these combinations in the conditions.
No/No, Yes/No, No/Yes, Yes/Yes. The interaction effect is the effect of the two IVs, right? As the Yes/Yes condition consist of both IVs, is the Yes/Yes condition here the same as the interaction effect of A and B?
![2x2](https://i.stack.imgur.com/9eGfa.png) | 2014/07/21 | [
"https://stats.stackexchange.com/questions/108718",
"https://stats.stackexchange.com",
"https://stats.stackexchange.com/users/40037/"
] | Typically, for text represented as TF/IDFs you will use simple linear kernel since the dimensionality is high and there is no need to go even higher with a non-linear kernel.
Why do you bound the dimensionality to 192 features? It makes no sense to bound the dimensionality with a fixed set of features and then use non-linear kernels in an effort to artificially increase it.
If you do need to restrict dimensionality (e.g. for performance reasons) then the state of the art is to use a hashing trick to bound it. | In general the 'RBF' kernel will give the best results. However, it does suffer when dealing with large datasets so I would first try 'RBF' and if that is taking to long try switching to a linear kernel. HTH. |
55,558,064 | An guessing and answering game.
Each Card comprises a Suit, one of A,B,C,D,E,F,G, and a Rank, one of 1|2|3.
I need to have a function to guarantee input(String) whether is valid type. And also write an instance declaration so that the type is in the Show class.
I am not sure about the function toCard, how to express "String" in the function and meet it with the condition.
```
data Suit = A|B|C|D|E|F|G
deriving (Show , Eq)
data Rank = R1|R2|R3
deriving (Show, Eq)
data Card = Card Suit Rank
deriving (Show, Eq)
instance Show Card where show (Card a b)
= show a ++ show (tail show b)
toCard :: String -> Maybe Card
toCard all@(x:xs)
| (x=A|B|C|D|E|F)&&(xs==1|2|3) = Just Card
| otherwise = Nothing
```
edit toCard function, input should be any String, so i use a list expression, but it seems to be not correct, cause i try it in ghci, (x=A|B|C|D|E|F)&&(y==1|2|3) is not valid | 2019/04/07 | [
"https://Stackoverflow.com/questions/55558064",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9684220/"
] | 1) Firstly,
```
instance Show Card where show (Card a b)
= show a ++ show (tail show b)
```
You have automatically derived a `Show` instance for `Card`, so this will conflict (you can only have 1 instance), and further it won't compile. The `show` should go on a new line, and `tail` should be applied to the *result* of `show b`.
```
instance Show Card where
show (Card a b) = show a ++ " " + tail (show b)
```
2) Secondly,
```
toCard :: String -> Maybe Card
toCard all@(x:xs)
| (x=A|B|C|D|E|F)&&(xs==1|2|3) = Just Card
| otherwise = Nothing
```
The syntax `(x=A|B|C|D|E|F)&&(xs==1|2|3)` is pretty wild, and certainly not valid Haskell. The closest approximation would be something like, `x `elem` ['A','B','C','D','E','F'] && xs `elem` ["1","2","3"]`, but as you can see this rapidly becomes boilerplate-y. Also, `Just Card` makes no sense - you still need to use the `x` and `xs` to say what the card actually is! eg. `Just $ Card x xs` (though that still won't work because they're still character/string not Suit/Rank).
One solution would be to automatically derive a `Read` instance on `Rank`, `Suit`, and `Card`. However, the automatic derivation for `read` on `Card` would require you to input eg. `"Card A R1"`, so let's try using the instance on `Rank` and `Suit` to let us write a parser for `Card`s that doesn't require prefixed `"Card"`.
First attempt:
```
toCard :: String -> Maybe Card
toCard (x:xs) = Just $ Card (read [x] :: Suit) (read xs :: Rank)
```
Hmm, this doesn't really allow us to deal with bad inputs - problem being that `read` just throws errors instead of giving us a `Maybe`. Notice however that we use `[x]` rather than `x` because `read` applies to `[Char]` and `x :: Char`. Next attempt:
```
import Text.Read (readMaybe)
toCard :: String -> Maybe Card
toCard [] = Nothing
toCard (x:xs) = let mSuit = readMaybe [x] :: Suit
mRank = readMaybe xs :: Rank
in case (mSuit, mRank) of
(Just s, Just r) -> Just $ Card s r
_ -> Nothing
```
This copes better with bad inputs, but has started to get quite long. Here's two possible ways to shorten it again:
```hs
-- using the Maybe monad
toCard (x:xs) = do mSuit <- readMaybe [x]
mRank <- readMaybe xs
return $ Card mSuit mRank
-- using Applicative
toCard (x:xs) = Card <$> readMaybe [x] <*> readMaybe xs
``` | A parser library, though it comes with a steeper learning curve, makes this simpler. For this example, we'll use `Text.Parsec`, from the `parsec` library. Import it, and define a type alias for using in defining your parsers.
```
import Text.Parsec
type Parser = Parsec String () -- boilerplate
```
`Parsec String ()` indicates a type of parser that consumes a stream of characters, and can produce a value of type `()` after parsing is complete. (In this case, we only care about the parsing, not any computation done along side the parsing.)
For your core types, we'll define a `Show` instant by hand for `Rank` so that you don't need to strip the `R` off later. We'll also derive a `Read` instance for `Suit` to make it easier to convert a string like `"A"` to a `Suit` value like `A`.
```
data Suit = A|B|C|D|E|F|G deriving (Show, Read, Eq)
data Rank = R1|R2|R3 deriving (Eq)
-- Define Show yourself so you don't constantly have to remove the `R`
instance Show Rank where
show R1 = "1"
show R2 = "2"
show R3 = "3"
data Card = Card Suit Rank deriving Eq
instance Show Card where
show (Card s r) = show s ++ show r
```
With that out of the way, we can define some parsers for each type.
```
-- Because oneOf will fail if you don't get one
-- of the valid suit characters, read [s] is guaranteed
-- to succeed. Using read eliminates the need for a
-- large case statement like in rank, below.
suit :: Parser Suit
suit = do
s <- oneOf "ABCDEF"
return $ read [s]
rank :: Parser Rank
rank = do
n <- oneOf "123"
return $ case n of
'1' -> R1
'2' -> R2
'3' -> R3
-- A Card parser just combines the Suit and Rank parsers
card :: Parser Card
card = Card <$> suit <*> rank
-- parse returns an Either ParseError Card value;
-- you can ignore the exact error if the parser fails
-- to return Nothing instead.
toCard :: String -> Maybe Card
toCard s = case parse card "" s of
Left _ -> Nothing
Right c -> Just c
```
---
`oneOf` is a predefined parser that consumes exactly one of the items in the given list.
`parse` takes three arguments:
1. A parser
2. A "source name" (only used for error message; you can use any string you like)
3. The string to parse |
38,979,709 | Just upgraded from grails 2.3.11 to 3.2.0.M2
Have a problem with dbm-gorm-diff and other dbm-\* scripts
My app has multiproject structure. Domain classes placed in separate plugin.
Build.gradle
```
buildscript {
repositories {
mavenLocal()
maven { url "https://repo.grails.org/grails/core" }
}
dependencies {
classpath "org.grails:grails-gradle-plugin:$grailsVersion"
classpath "org.grails.plugins:hibernate5:6.0.0.M2"
classpath "org.grails.plugins:database-migration:2.0.0.RC4"
}
```
}
```
version "0.1"
group "core"
apply plugin:"eclipse"
apply plugin:"idea"
apply plugin:"org.grails.grails-plugin"
apply plugin:"org.grails.grails-plugin-publish"
configurations.all {
resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
}
repositories {
mavenLocal()
maven { url "https://repo.grails.org/grails/core" }
}
dependencyManagement {
imports {
mavenBom "org.grails:grails-bom:$grailsVersion"
}
applyMavenExclusions false
}
dependencies {
compile "org.springframework.boot:spring-boot-starter-logging"
compile "org.springframework.boot:spring-boot-autoconfigure"
compile "org.grails:grails-core"
compile "org.grails:grails-dependencies"
compile "org.grails.plugins:hibernate5"
compile "org.grails.plugins:cache"
compile "org.hibernate:hibernate-core:5.1.0.Final"
compile "org.hibernate:hibernate-ehcache:5.1.0.Final"
console "org.grails:grails-console"
profile "org.grails.profiles:plugin:3.2.0.M2"
provided "org.grails:grails-plugin-services"
provided "org.grails:grails-plugin-domain-class"
provided 'javax.servlet:javax.servlet-api:3.1.0'
runtime "org.grails.plugins:database-migration:2.0.0.RC4"
runtime "mysql:mysql-connector-java:5.1.39"
testCompile "org.grails:grails-plugin-testing"
}
grailsPublish {
// TODO: Provide values here
user = 'user'
key = 'key'
githubSlug = 'app/core'
license {
name = 'Apache-2.0'
}
title = "Core"
desc = "***"
developers = ["***"]
portalUser = ""
portalPassword = ""
}
sourceSets {
main {
resources {
srcDir "grails-app/migrations"
}
}
}
```
application.yml
```
grails:
profile: plugin
codegen:
defaultPackage: core
spring:
transactionManagement:
proxies: false
info:
app:
name: '@info.app.name@'
version: '@info.app.version@'
grailsVersion: '@info.app.grailsVersion@'
spring:
groovy:
template:
check-template-location: false
---
grails:
plugin:
databasemigration:
updateOnStart: true
updateOnStartFileNames:
- changelog.groovy
- changelog-part-2.groovy
hibernate:
cache:
queries: false
use_second_level_cache: true
use_query_cache: false
region.factory_class: 'org.hibernate.cache.ehcache.EhCacheRegionFactory'
dataSource:
dbCreate: none
driverClassName: "com.mysql.jdbc.Driver"
dialect: "org.hibernate.dialect.MySQL5InnoDBDialect"
url: "jdbc:mysql://localhost:3306/project?zeroDateTimeBehavior=convertToNull&autoreconnect=true&useUnicode=true&characterEncoding=UTF-8&characterSetResults=UTF-8"
username: "root"
password: "root"
properties:
jmxEnabled: true
initialSize: 5
maxActive: 50
minIdle: 5
maxIdle: 25
maxWait: 10000
maxAge: 600000
timeBetweenEvictionRunsMillis: 5000
minEvictableIdleTimeMillis: 60000
validationQuery: SELECT 1
validationQueryTimeout: 3
validationInterval: 15000
testOnBorrow: true
testWhileIdle: true
testOnReturn: false
jdbcInterceptors: ConnectionState
defaultTransactionIsolation: 2 # TRANSACTION_READ_COMMITTED
```
Stacktrace
```
2016-08-16 18:57:06.731 WARN 5736 --- [ main] o.s.mock.web.MockServletContext : Couldn't determine real path of resource class path resource [src/main/webapp/WEB-INF/sitemesh.xml]
java.io.FileNotFoundException: class path resource [src/main/webapp/WEB-INF/sitemesh.xml] cannot be resolved to URL because it does not exist
at org.springframework.core.io.ClassPathResource.getURL(ClassPathResource.java:187) ~[spring-core-4.3.1.RELEASE.jar:4.3.1.RELEASE]
at org.springframework.core.io.AbstractFileResolvingResource.getFile(AbstractFileResolvingResource.java:48) ~[spring-core-4.3.1.RELEASE.jar:4.3.1.RELEASE]
at org.springframework.mock.web.MockServletContext.getRealPath(MockServletContext.java:458) ~[spring-test-4.3.1.RELEASE.jar:4.3.1.RELEASE]
at org.grails.web.sitemesh.Grails5535Factory.<init>(Grails5535Factory.java:78) [grails-web-sitemesh-3.2.0.M2.jar:3.2.0.M2]
at org.grails.web.servlet.view.SitemeshLayoutViewResolver.loadSitemeshConfig(SitemeshLayoutViewResolver.java:105) [grails-web-gsp-3.2.0.M2.jar:3.2.0.M2]
at org.grails.web.servlet.view.SitemeshLayoutViewResolver.init(SitemeshLayoutViewResolver.java:67) [grails-web-gsp-3.2.0.M2.jar:3.2.0.M2]
at org.grails.web.servlet.view.SitemeshLayoutViewResolver.onApplicationEvent(SitemeshLayoutViewResolver.java:146) [grails-web-gsp-3.2.0.M2.jar:3.2.0.M2]
at org.grails.web.servlet.view.SitemeshLayoutViewResolver.onApplicationEvent(SitemeshLayoutViewResolver.java:42) [grails-web-gsp-3.2.0.M2.jar:3.2.0.M2]
at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:166) [spring-context-4.3.1.RELEASE.jar:4.3.1.RELEASE]
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:138) [spring-context-4.3.1.RELEASE.jar:4.3.1.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:382) [spring-context-4.3.1.RELEASE.jar:4.3.1.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:336) [spring-context-4.3.1.RELEASE.jar:4.3.1.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:877) [spring-context-4.3.1.RELEASE.jar:4.3.1.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:544) [spring-context-4.3.1.RELEASE.jar:4.3.1.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:759) [spring-boot-1.4.0.RC1.jar:1.4.0.RC1]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:369) [spring-boot-1.4.0.RC1.jar:1.4.0.RC1]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:313) [spring-boot-1.4.0.RC1.jar:1.4.0.RC1]
at grails.boot.GrailsApp.run(GrailsApp.groovy:55) [grails-core-3.2.0.M2.jar:3.2.0.M2]
at grails.ui.command.GrailsApplicationContextCommandRunner.run(GrailsApplicationContextCommandRunner.groovy:55) [grails-console-3.2.0.M2.jar:3.2.0.M2]
at grails.ui.command.GrailsApplicationContextCommandRunner.main(GrailsApplicationContextCommandRunner.groovy:102) [grails-console-3.2.0.M2.jar:3.2.0.M2]
2016-08-16 18:57:07.035 INFO 5736 --- [ main] .c.GrailsApplicationContextCommandRunner : Started GrailsApplicationContextCommandRunner in 21.719 seconds (JVM running for 23.484)
2016-08-16 18:57:07.035 INFO 5736 --- [ main] grails.boot.GrailsApp : Application starting in environment: development
Command execution error: Bean named 'sessionFactory' must be of type [org.springframework.beans.factory.FactoryBean], but was actually of type [org.hibernate.internal.SessionFactoryImpl]
2016-08-16 18:57:07.185 INFO 5736 --- [ Thread-7] g.u.s.DevelopmentWebApplicationContext : Closing grails.ui.support.DevelopmentWebApplicationContext@2abc224d: startup date [Tue Aug 16 18:56:48 MSK 2016]; root of context hierarchy
2016-08-16 18:57:07.382 INFO 5736 --- [ Thread-7] o.s.c.support.DefaultLifecycleProcessor : Stopping beans in phase -2147483648
2016-08-16 18:57:07.406 INFO 5736 --- [ Thread-7] o.s.j.e.a.AnnotationMBeanExporter : Unregistering JMX-exposed beans on shutdown
```
Can you help me? | 2016/08/16 | [
"https://Stackoverflow.com/questions/38979709",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6250067/"
] | Already found it. This is known issue - <https://github.com/grails-plugins/grails-database-migration/issues/81> | Discussed here: [Grails 3 schemaExport contains warning with FileNotFoundException that looks for sitemesh.xml](https://stackoverflow.com/questions/46189472/grails-3-schemaexport-contains-warning-with-filenotfoundexception-that-looks-for)
You can ignore it. Still a problem in Grails 4. |
9,638,009 | I have a following XAML:
```
<ComboBox
Name="groupComboBox"
ItemsSource="{Binding Path=MyServiceMap.Groups}"
DisplayMemberPath="{Binding Name}"/>
```
In the code behind i set this.DataContext to my viewModel.
```
private ServiceMap _serviceMap;
public ServiceMap MyServiceMap
{
get
{
return _serviceMap;
}
set
{
_serviceMap = value;
OnPropertyChanged("MyServiceMap");
}
}
```
My ServiceMap class is
```
public class ServiceMap
{
//other code
public List<Group> Groups = new List<Group>();
}
```
and finally:
```
public class Group
{
public string Name { get; set; }
}
```
Unfortunately, this is not working. How can i bind combobox to show Group Name? | 2012/03/09 | [
"https://Stackoverflow.com/questions/9638009",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1076067/"
] | There are two problems with your code. First is bindings are only work on properties, so the binding couldn't find the Group field. Change it to a property.
```
public class ServiceMap
{
public List<Group> Groups { get; set; }
}
```
The second one is that the DisplayMemberPath waits for a string not a binding. Change it simply to "Name".
```
<ComboBox Name="groupComboBox"
ItemsSource="{Binding Path=MyServiceMap.Groups}"
DisplayMemberPath="Name" />
``` | Have you tried DisplayMemberPath="Name"? |
64,168,266 | HTML:
```
<div class="form-row">
<div class="col-md-6 mb-3">
<label for="validationCustom03">Service</label>
<input type="text" class="form-control" id="validationCustom03" value="Describe service you need" required>
<div class="invalid-feedback">
Please write here a needed service.
</div>
</div>
</div>
```
CSS
```
#validationCustom03{
height: 100px;
}
input[id=validationCustom03]{
display:inline;
padding-top: 0px;
margin-top: 0px;
color:red;
}
```
Hello guys, I am trying to stylize the value of form - text input, but the only one thing I can reach is red color. My purpose is to remove break line before and after the text, to make is from the very first line in the input, please check out the picture. Thank you for your time and wisdom !
[![This is how it looks like](https://i.stack.imgur.com/oCo6t.jpg)](https://i.stack.imgur.com/oCo6t.jpg) | 2020/10/02 | [
"https://Stackoverflow.com/questions/64168266",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14219248/"
] | I think you should use a `<textarea>` form attribute instead of an `<input>` element. Here's an example:
```css
#validationCustom03{
height: 100px;
}
textarea[id=validationCustom03]{
display:inline;
padding-top: 0px;
margin-top: 0px;
color:red;
}
```
```html
<div class="form-row">
<div class="col-md-6 mb-3">
<label for="validationCustom03">Service</label><br>
<textarea rows="4" cols="50" name="comment" class="form-control" id="validationCustom03" form="usrform" value="Describe service you need" required>
Enter text here...</textarea>
<div class="invalid-feedback">
Please write here a needed service.
</div>
</div>
</div>
``` | you don't have a break-line here. it is just because the height of the input field is much bigger than the size of the font. |
18,304,382 | I have an application in Rails 3.2 which is ready to deploy. I am wondering should I upgrade it to Rails 4 or not. I also not sure about which of the gems might give issues with while upgrading.
Below is my Gemfile with several common gems.
Gemfile.rb
```
source 'https://rubygems.org'
gem 'rails', '3.2.8'
gem 'pg', '0.12.2'
gem 'bcrypt-ruby', '3.0.1'
gem 'will_paginate', '3.0.3'
gem 'bootstrap-will_paginate', '0.0.6'
gem 'simple_form', '2.0'
gem 'rails3-jquery-autocomplete', '1.0.10'
gem 'show_for', '0.1'
gem 'paperclip', '3.3.1'
gem 'cocoon', '1.1.1'
gem 'google_visualr', '2.1.0'
gem 'axlsx', '1.3.4'
gem 'acts_as_xlsx', '1.0.6'
gem 'devise' ,'2.1.2'
gem 'cancan', '1.6.8'
gem 'bootstrap-datepicker-rails', "0.6.32"
gem 'country_select', '1.1.3'
gem 'jquery-rails', '2.1.4'
gem 'annotate', '2.5.0', group: :development
gem 'ransack', '0.7.2'
gem "audited-activerecord", "3.0.0"
gem 'prawn', '1.0.0.rc2'
gem 'exception_notification', '3.0.1'
gem 'daemons', '1.1.9'
gem 'delayed_job_active_record', '0.4.3'
gem "delayed_job_web", '1.1.2'
gem "less-rails"
gem "therubyracer"
gem 'twitter-bootstrap-rails', '~>2.1.9'
gem "spreadsheet", "~> 0.8.8"
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails', '3.2.5'
gem 'coffee-rails', '3.2.2'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', :platforms => :ruby
gem 'uglifier', '1.2.3'
end
# To use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'
# To use Jbuilder templates for JSON
# gem 'jbuilder'
# Use unicorn as the app server
# gem 'unicorn'
# Deploy with Capistrano
# gem 'capistrano'
# To use debugger
# gem 'debugger'
group :development, :test do
gem 'rspec-rails', '2.11.0'
end
group :test do
gem 'capybara', '1.1.2'
gem 'factory_girl_rails', '4.1.0'
gem 'faker', '1.0.1'
end
```
I started working on this application last year (Nov 2012) after reading this great book at
<http://ruby.railstutorial.org/>. I have also checked out what's new in Rails 4 like strong parameters and it's all very tempting to try an upgrade.
But I am concerned about compatibility of these gems and effort it may take.
I need some advice from experienced guys in the community or someone who has tried upgrading before I move ahead. | 2013/08/18 | [
"https://Stackoverflow.com/questions/18304382",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1799633/"
] | I uploaded your gemfile to [Ready for Rails 4](http://www.ready4rails.net/), and it appears that you only have a couple gems that are not ready and one gem that is unknown. For some of the gems listed that do not have notes, I would suggest checking out their GitHub page (if they have one), and see if the gem has been updated recently on rubygems, just to confirm whether or not the gem works. | The asset pipeline has changed a bit, so you'll need to upgrade those gems. I had to use a fork of ransack in the context of active\_admin, but you might be fine.
I'd recommend that you create a branch, bump to Rails 4, and see what happens. It took me a day or two to upgrade from 3.2 to 4 a couple weeks ago on a fairly small (but production-with-customers) application. The [upgrade guide](http://edgeguides.rubyonrails.org/upgrading_ruby_on_rails.html) is pretty solid. |
18,304,382 | I have an application in Rails 3.2 which is ready to deploy. I am wondering should I upgrade it to Rails 4 or not. I also not sure about which of the gems might give issues with while upgrading.
Below is my Gemfile with several common gems.
Gemfile.rb
```
source 'https://rubygems.org'
gem 'rails', '3.2.8'
gem 'pg', '0.12.2'
gem 'bcrypt-ruby', '3.0.1'
gem 'will_paginate', '3.0.3'
gem 'bootstrap-will_paginate', '0.0.6'
gem 'simple_form', '2.0'
gem 'rails3-jquery-autocomplete', '1.0.10'
gem 'show_for', '0.1'
gem 'paperclip', '3.3.1'
gem 'cocoon', '1.1.1'
gem 'google_visualr', '2.1.0'
gem 'axlsx', '1.3.4'
gem 'acts_as_xlsx', '1.0.6'
gem 'devise' ,'2.1.2'
gem 'cancan', '1.6.8'
gem 'bootstrap-datepicker-rails', "0.6.32"
gem 'country_select', '1.1.3'
gem 'jquery-rails', '2.1.4'
gem 'annotate', '2.5.0', group: :development
gem 'ransack', '0.7.2'
gem "audited-activerecord", "3.0.0"
gem 'prawn', '1.0.0.rc2'
gem 'exception_notification', '3.0.1'
gem 'daemons', '1.1.9'
gem 'delayed_job_active_record', '0.4.3'
gem "delayed_job_web", '1.1.2'
gem "less-rails"
gem "therubyracer"
gem 'twitter-bootstrap-rails', '~>2.1.9'
gem "spreadsheet", "~> 0.8.8"
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails', '3.2.5'
gem 'coffee-rails', '3.2.2'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', :platforms => :ruby
gem 'uglifier', '1.2.3'
end
# To use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'
# To use Jbuilder templates for JSON
# gem 'jbuilder'
# Use unicorn as the app server
# gem 'unicorn'
# Deploy with Capistrano
# gem 'capistrano'
# To use debugger
# gem 'debugger'
group :development, :test do
gem 'rspec-rails', '2.11.0'
end
group :test do
gem 'capybara', '1.1.2'
gem 'factory_girl_rails', '4.1.0'
gem 'faker', '1.0.1'
end
```
I started working on this application last year (Nov 2012) after reading this great book at
<http://ruby.railstutorial.org/>. I have also checked out what's new in Rails 4 like strong parameters and it's all very tempting to try an upgrade.
But I am concerned about compatibility of these gems and effort it may take.
I need some advice from experienced guys in the community or someone who has tried upgrading before I move ahead. | 2013/08/18 | [
"https://Stackoverflow.com/questions/18304382",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1799633/"
] | I uploaded your gemfile to [Ready for Rails 4](http://www.ready4rails.net/), and it appears that you only have a couple gems that are not ready and one gem that is unknown. For some of the gems listed that do not have notes, I would suggest checking out their GitHub page (if they have one), and see if the gem has been updated recently on rubygems, just to confirm whether or not the gem works. | This brief handbook was worth every cent in our recent 3.2 to 4 migration.
<https://leanpub.com/upgradetorails4>
<https://github.com/alindeman/upgradingtorails4>
It lists in details how to handle gem upgrades, as well as individual details (with clear examples) of what's changed and how to manage your current Rails app through the upgrade.
To address your gem-specific concerns: Almost all our 40+ gems, except perhaps 5, had active either Rails 4 releases (or Github branches for Rails 4), or worked just fine with Rails 4 when left intact.
Having a healthy unit/functional test suite in your codebase would be vital for your confidence in the upgrade being successful. |
4,311,203 | In 2 different action listeners, a dialog will be shown when some conditions are met.
If both of the action listeners need to show dialog, 2 dialogs will be shown at the same time. But I want them to be shown one by one.
Simplified code:
```
SwingUtilities.invokeLater(new Runnable() {
public void run() {
JOptionPane.showMessageDialog(getTopLevelAncestor(), "dialog 1");
}
});
SwingUtilities.invokeLater(new Runnable() {
public void run() {
JOptionPane.showMessageDialog(getTopLevelAncestor(), "dialog 2");
}
});
```
Those 2 "SwingUtilities.invokeLater" invocations are in different classes. | 2010/11/30 | [
"https://Stackoverflow.com/questions/4311203",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/319106/"
] | Make a class that keeps track about that; this class would contain a queue of dialogs to display; whenever a dialog is closed, the first one of the queue is shown and removed from the queue. When another class needs to show a dialog, it's immediately shown if the queue is empty, or inserted into the queue else. | You need [`invokeAndWait()`](http://download.oracle.com/javase/6/docs/api/javax/swing/SwingUtilities.html#invokeAndWait%28java.lang.Runnable%29), this method waits until the Runnable has been finished.
Or in your situation, when the first dialog has been closed. |
4,311,203 | In 2 different action listeners, a dialog will be shown when some conditions are met.
If both of the action listeners need to show dialog, 2 dialogs will be shown at the same time. But I want them to be shown one by one.
Simplified code:
```
SwingUtilities.invokeLater(new Runnable() {
public void run() {
JOptionPane.showMessageDialog(getTopLevelAncestor(), "dialog 1");
}
});
SwingUtilities.invokeLater(new Runnable() {
public void run() {
JOptionPane.showMessageDialog(getTopLevelAncestor(), "dialog 2");
}
});
```
Those 2 "SwingUtilities.invokeLater" invocations are in different classes. | 2010/11/30 | [
"https://Stackoverflow.com/questions/4311203",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/319106/"
] | This is related to the modality of dialogs. There is quite useful article about this topic <http://java.sun.com/developer/technicalArticles/J2SE/Desktop/javase6/modality/>. Dialogs have different modality types with different priorities. You can solve your problem by creating the second dialog with lower priority:
```
JOptionPane pane = new JOptionPane("dialog 2", JOptionPane.INFORMATION_MESSAGE);
JDialog dialog = pane.createDialog("Message");
dialog.setModalityType(Dialog.ModalityType.DOCUMENT_MODAL);
dialog.setVisible(true);
```
Hopefully this helps. | You need [`invokeAndWait()`](http://download.oracle.com/javase/6/docs/api/javax/swing/SwingUtilities.html#invokeAndWait%28java.lang.Runnable%29), this method waits until the Runnable has been finished.
Or in your situation, when the first dialog has been closed. |
1,388,053 | In XAML, if you insert
```
<TextBlock Text="Hello World" />
```
You will see the words "Hello World".
If you insert
```
<TextBlock Text="{Binding}" />
```
it will trigger the data binding functionality. But what if I really wanted the display text to be "{Binding}"?"
Are there the equivalent of escape characters in XAML strings?
Or is my only solution to do this:
```
<TextBlock>Binding</TextBlock>
``` | 2009/09/07 | [
"https://Stackoverflow.com/questions/1388053",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/25216/"
] | You can escape the entire string with "{}":
```
<TextBlock Text="{}{Binding}"/>
```
Or individual curly braces can be escaped with a backslash:
```
<TextBlock Text="{Binding Foo,StringFormat='Hello \{0\}'}" />
``` | Try this:
```
<TextBlock Text="{Binding}" />
```
And unescape it when you read the value. |
1,388,053 | In XAML, if you insert
```
<TextBlock Text="Hello World" />
```
You will see the words "Hello World".
If you insert
```
<TextBlock Text="{Binding}" />
```
it will trigger the data binding functionality. But what if I really wanted the display text to be "{Binding}"?"
Are there the equivalent of escape characters in XAML strings?
Or is my only solution to do this:
```
<TextBlock>Binding</TextBlock>
``` | 2009/09/07 | [
"https://Stackoverflow.com/questions/1388053",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/25216/"
] | You can escape the entire string with "{}":
```
<TextBlock Text="{}{Binding}"/>
```
Or individual curly braces can be escaped with a backslash:
```
<TextBlock Text="{Binding Foo,StringFormat='Hello \{0\}'}" />
``` | You need to escape the { and } characters, so you'd end up with `<TextBlock Text="\{Binding\}" />` |
1,388,053 | In XAML, if you insert
```
<TextBlock Text="Hello World" />
```
You will see the words "Hello World".
If you insert
```
<TextBlock Text="{Binding}" />
```
it will trigger the data binding functionality. But what if I really wanted the display text to be "{Binding}"?"
Are there the equivalent of escape characters in XAML strings?
Or is my only solution to do this:
```
<TextBlock>Binding</TextBlock>
``` | 2009/09/07 | [
"https://Stackoverflow.com/questions/1388053",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/25216/"
] | You can escape the entire string with "{}":
```
<TextBlock Text="{}{Binding}"/>
```
Or individual curly braces can be escaped with a backslash:
```
<TextBlock Text="{Binding Foo,StringFormat='Hello \{0\}'}" />
``` | Escaping with '{}' as per Matt's response is the way to go, but for the sake of completeness you can also use a CDATA section:
```
<TextBlock>
<TextBlock.Text>
<![CDATA[{Binding}]]>
</TextBlock.Text>
</TextBlock>
```
A CDATA section is more useful for multiline text though. |
1,388,053 | In XAML, if you insert
```
<TextBlock Text="Hello World" />
```
You will see the words "Hello World".
If you insert
```
<TextBlock Text="{Binding}" />
```
it will trigger the data binding functionality. But what if I really wanted the display text to be "{Binding}"?"
Are there the equivalent of escape characters in XAML strings?
Or is my only solution to do this:
```
<TextBlock>Binding</TextBlock>
``` | 2009/09/07 | [
"https://Stackoverflow.com/questions/1388053",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/25216/"
] | Try this:
```
<TextBlock Text="{Binding}" />
```
And unescape it when you read the value. | You need to escape the { and } characters, so you'd end up with `<TextBlock Text="\{Binding\}" />` |
1,388,053 | In XAML, if you insert
```
<TextBlock Text="Hello World" />
```
You will see the words "Hello World".
If you insert
```
<TextBlock Text="{Binding}" />
```
it will trigger the data binding functionality. But what if I really wanted the display text to be "{Binding}"?"
Are there the equivalent of escape characters in XAML strings?
Or is my only solution to do this:
```
<TextBlock>Binding</TextBlock>
``` | 2009/09/07 | [
"https://Stackoverflow.com/questions/1388053",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/25216/"
] | Escaping with '{}' as per Matt's response is the way to go, but for the sake of completeness you can also use a CDATA section:
```
<TextBlock>
<TextBlock.Text>
<![CDATA[{Binding}]]>
</TextBlock.Text>
</TextBlock>
```
A CDATA section is more useful for multiline text though. | Try this:
```
<TextBlock Text="{Binding}" />
```
And unescape it when you read the value. |
1,388,053 | In XAML, if you insert
```
<TextBlock Text="Hello World" />
```
You will see the words "Hello World".
If you insert
```
<TextBlock Text="{Binding}" />
```
it will trigger the data binding functionality. But what if I really wanted the display text to be "{Binding}"?"
Are there the equivalent of escape characters in XAML strings?
Or is my only solution to do this:
```
<TextBlock>Binding</TextBlock>
``` | 2009/09/07 | [
"https://Stackoverflow.com/questions/1388053",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/25216/"
] | Escaping with '{}' as per Matt's response is the way to go, but for the sake of completeness you can also use a CDATA section:
```
<TextBlock>
<TextBlock.Text>
<![CDATA[{Binding}]]>
</TextBlock.Text>
</TextBlock>
```
A CDATA section is more useful for multiline text though. | You need to escape the { and } characters, so you'd end up with `<TextBlock Text="\{Binding\}" />` |
71,792,169 | I am working on an app but there is a problem with hamburger icon as it is not working. It is not opening the navigation menu when i am clicking on it. what is the problem please tell me? I am trying to solve it but dont know what is the problem with it. I am new to code please help me.
**Here is my fragment code**
```
public class HomeFragment extends Fragment{
NavigationView navigationView;
ActionBarDrawerToggle toggle;
DrawerLayout drawerLayout;
Toolbar toolbar;
private int[] images;
private SliderAdapter sliderAdapter;
public HomeFragment() {
// Required empty public constructor
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_home, container, false);
navigationView = view.findViewById(R.id.navmenu);
drawerLayout = view.findViewById(R.id.drawerlayout);
toolbar = view.findViewById(R.id.toolbar);
ActionBar mActionBar;
((AppCompatActivity) getActivity()).setSupportActionBar(toolbar);
Objects.requireNonNull(((AppCompatActivity) getActivity()).getSupportActionBar()).setTitle("");
toggle = new ActionBarDrawerToggle(getActivity(), drawerLayout, R.string.open, R.string.close);
drawerLayout.addDrawerListener(toggle);
toggle.syncState();
((AppCompatActivity) getActivity()).getSupportActionBar().setDisplayHomeAsUpEnabled(true);
((AppCompatActivity) getActivity()).getSupportActionBar().setHomeAsUpIndicator(R.drawable.menu3);
return view;
}
}
```
**Here is my XML file**
```
<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/drawerlayout"
tools:openDrawer="start"
android:background="@color/white"
tools:context=".HomeFragment">
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/reddark"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/Theme.AppCompat.Light">
<ImageView
android:layout_width="150dp"
android:layout_height="50dp"
android:layout_gravity="center_horizontal"
android:src="@drawable/backsssososos" />
</androidx.appcompat.widget.Toolbar>
<RelativeLayout
android:id="@+id/search_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/toolbar"
android:background="@color/reddark"
android:padding="10dp"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<EditText
android:id="@+id/searchbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/searchbardesign"
android:backgroundTint="#F8F8F8"
android:drawableLeft="@android:drawable/ic_menu_camera"
android:drawableRight="@android:drawable/ic_menu_search"
android:drawablePadding="22dp"
android:gravity="left|center"
android:hint="Enter City,Colony name..."
android:imeOptions="actionSearch"
android:inputType="text"
android:maxLines="1"
android:padding="10dp"
android:textColor="@color/black"
android:textColorHint="@android:color/darker_gray"
android:textSize="16dp" />
</RelativeLayout>
</com.google.android.material.appbar.AppBarLayout>
<androidx.core.widget.NestedScrollView
android:id="@+id/nestedScrollView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clipToPadding="true"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="10dp"
android:orientation="vertical">
<com.smarteist.autoimageslider.SliderView
android:id="@+id/imageSlider"
android:layout_width="match_parent"
android:layout_height="300dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:sliderAnimationDuration="600"
app:sliderAutoCycleDirection="back_and_forth"
app:sliderAutoCycleEnabled="true"
app:sliderIndicatorAnimationDuration="600"
app:sliderIndicatorGravity="center_horizontal|bottom"
app:sliderIndicatorMargin="15dp"
app:sliderIndicatorOrientation="horizontal"
app:sliderIndicatorPadding="3dp"
app:sliderIndicatorRadius="2dp"
app:sliderIndicatorSelectedColor="#5A5A5A"
app:sliderIndicatorUnselectedColor="#FFF"
app:sliderScrollTimeInSec="1"
app:sliderStartAutoCycle="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/text_file_2"></TextView>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/text_file_2">
</TextView>
</LinearLayout>
</androidx.core.widget.NestedScrollView>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
<com.google.android.material.navigation.NavigationView
android:id="@+id/navmenu"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:itemIconTint="@color/black"
android:theme="@style/NavigationDrawerStyle"
app:headerLayout="@layout/navheader"
app:itemTextColor="#151515"
app:menu="@menu/navigationmenu">
</com.google.android.material.navigation.NavigationView>
</androidx.drawerlayout.widget.DrawerLayout>
``` | 2022/04/08 | [
"https://Stackoverflow.com/questions/71792169",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11915666/"
] | you must attach toolbar in ActionBarDrawerToggle
```
mDrawerToogle = new ActionBarDrawerToggle(this, drawer,toolbar,R.string.navigation_drawer_open, R.string.navigation_drawer_close);
bar.setHomeButtonEnabled(true);
bar.setDisplayHomeAsUpEnabled(true);
mDrawerToogle.syncState();
drawer.setDrawerListener(mDrawerToogle);
``` | you have to handle this action by yourself
```
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == android.R.id.home) {
drawerLayout.openDrawer(Gravity.LEFT);
return true;
}
return super.onOptionsItemSelected(item);
}
```
also `syncState()` call should be placed in `onPostCreate` or even in `onResume`
btw. your empty constructor should at least call `super();` |
1,759,420 | I want to hide page extensions like stackoverflow does. How does the following work?
```
http://stackoverflow.com/tags/foo
http://stackoverflow.com/tags/bar
```
I've seen a lot of sites that do this, but I still don't know how this is accomplished (I have a LAMP stack). | 2009/11/18 | [
"https://Stackoverflow.com/questions/1759420",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/214135/"
] | When a web server gets a request for a URL, it has to decide how to handle it. The classic method was to map the head of the URL to a directory in the file system, then let the rest of the URL navigate to a file in the filesystem. As a result, URLs had file extensions.
But there's no need to do it that way, and most new web frameworks don't. They let the programmer define how to map a URL to code to run, so there's no need for file extensions, because there is no single file providing the response.
In your example, there isn't a "tags" directory containing files "foo" and "bar". The "tags" URL is mapped to code that uses the rest of the URL ("foo" or "bar") as a parameter in a query against the database of tag data. | If you're using Apache and you simply want to hide the file extensions of static HTML files you can use this `.htaccess` code:
```
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f # if the requested URL is not a file that exists
RewriteCond %{REQUEST_FILENAME} !-d # and it isn't a directory that exists either
RewriteCond %{REQUEST_FILENAME}\.html -f # but when you put ".html" on the end it is a file that exists
RewriteRule ^(.+)$ $1\.html [QSA] # then serve that file
</IfModule>
```
Apache `mod_rewrite` has been called "voodoo, but seriously cool voodoo".
The actual `.htaccess` code I use on a few sites is like that, but not identical:
```
<IfModule mod_rewrite.c>
RewriteEngine on
#RewriteRule ^$ index.php [QSA]
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.+)$ $1\.php [QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php/$1 [QSA]
</IfModule>
```
And here is some much longer but far more readable code to do the same thing on a Zeus server. On Zeus, it's called `rewrite.script`.
```
# http://drupal.org/node/46508
# get the document root
map path into SCRATCH:DOCROOT from /
# initialize our variables
set SCRATCH:ORIG_URL = %{URL}
set SCRATCH:REQUEST_URI = %{URL}
match URL into $ with ^(.*)\?(.*)$
if matched then
set SCRATCH:REQUEST_URI = $1
set SCRATCH:QUERY_STRING = $2
endif
# prepare to search for file, rewrite if its not found
set SCRATCH:REQUEST_FILENAME = %{SCRATCH:DOCROOT}
set SCRATCH:REQUEST_FILENAME . %{SCRATCH:REQUEST_URI}
# check to see if the file requested is an actual file or
# a directory with possibly an index. don't rewrite if so
look for file at %{SCRATCH:REQUEST_FILENAME}
if not exists then
look for dir at %{SCRATCH:REQUEST_FILENAME}
if not exists then
look for file at %{SCRATCH:REQUEST_FILENAME}.php
if exists then
set URL = %{SCRATCH:REQUEST_URI}.php?%{SCRATCH:QUERY_STRING}
else
set URL = /index.php/%{SCRATCH:REQUEST_URI}?%{SCRATCH:QUERY_STRING}
endif
endif
endif
goto END
``` |
1,759,420 | I want to hide page extensions like stackoverflow does. How does the following work?
```
http://stackoverflow.com/tags/foo
http://stackoverflow.com/tags/bar
```
I've seen a lot of sites that do this, but I still don't know how this is accomplished (I have a LAMP stack). | 2009/11/18 | [
"https://Stackoverflow.com/questions/1759420",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/214135/"
] | That's the beauty and the work of [ASP.NET MVC](http://www.asp.net/mvc/).
No "hiding" - it's just the way ASP.NET MVC handles URL's and maps those "routes" to controller actions on your controller classes.
Quite a big step away from the "classic" ASP.NET Webforms way of doing things. | Modern web development frameworks have support for elegant urls. Check out [Django](http://www.djangoproject.com/) or [Ruby on Rails](http://rubyonrails.org/). |
1,759,420 | I want to hide page extensions like stackoverflow does. How does the following work?
```
http://stackoverflow.com/tags/foo
http://stackoverflow.com/tags/bar
```
I've seen a lot of sites that do this, but I still don't know how this is accomplished (I have a LAMP stack). | 2009/11/18 | [
"https://Stackoverflow.com/questions/1759420",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/214135/"
] | That's the beauty and the work of [ASP.NET MVC](http://www.asp.net/mvc/).
No "hiding" - it's just the way ASP.NET MVC handles URL's and maps those "routes" to controller actions on your controller classes.
Quite a big step away from the "classic" ASP.NET Webforms way of doing things. | If you're using Apache and you simply want to hide the file extensions of static HTML files you can use this `.htaccess` code:
```
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f # if the requested URL is not a file that exists
RewriteCond %{REQUEST_FILENAME} !-d # and it isn't a directory that exists either
RewriteCond %{REQUEST_FILENAME}\.html -f # but when you put ".html" on the end it is a file that exists
RewriteRule ^(.+)$ $1\.html [QSA] # then serve that file
</IfModule>
```
Apache `mod_rewrite` has been called "voodoo, but seriously cool voodoo".
The actual `.htaccess` code I use on a few sites is like that, but not identical:
```
<IfModule mod_rewrite.c>
RewriteEngine on
#RewriteRule ^$ index.php [QSA]
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.+)$ $1\.php [QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php/$1 [QSA]
</IfModule>
```
And here is some much longer but far more readable code to do the same thing on a Zeus server. On Zeus, it's called `rewrite.script`.
```
# http://drupal.org/node/46508
# get the document root
map path into SCRATCH:DOCROOT from /
# initialize our variables
set SCRATCH:ORIG_URL = %{URL}
set SCRATCH:REQUEST_URI = %{URL}
match URL into $ with ^(.*)\?(.*)$
if matched then
set SCRATCH:REQUEST_URI = $1
set SCRATCH:QUERY_STRING = $2
endif
# prepare to search for file, rewrite if its not found
set SCRATCH:REQUEST_FILENAME = %{SCRATCH:DOCROOT}
set SCRATCH:REQUEST_FILENAME . %{SCRATCH:REQUEST_URI}
# check to see if the file requested is an actual file or
# a directory with possibly an index. don't rewrite if so
look for file at %{SCRATCH:REQUEST_FILENAME}
if not exists then
look for dir at %{SCRATCH:REQUEST_FILENAME}
if not exists then
look for file at %{SCRATCH:REQUEST_FILENAME}.php
if exists then
set URL = %{SCRATCH:REQUEST_URI}.php?%{SCRATCH:QUERY_STRING}
else
set URL = /index.php/%{SCRATCH:REQUEST_URI}?%{SCRATCH:QUERY_STRING}
endif
endif
endif
goto END
``` |
1,759,420 | I want to hide page extensions like stackoverflow does. How does the following work?
```
http://stackoverflow.com/tags/foo
http://stackoverflow.com/tags/bar
```
I've seen a lot of sites that do this, but I still don't know how this is accomplished (I have a LAMP stack). | 2009/11/18 | [
"https://Stackoverflow.com/questions/1759420",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/214135/"
] | What you want is clean URLS and you can do it with apache and .htaccess . There may be a better way, but here's how I have been doing it:
<http://evolt.org/Making_clean_URLs_with_Apache_and_PHP> | If you're using Apache and you simply want to hide the file extensions of static HTML files you can use this `.htaccess` code:
```
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f # if the requested URL is not a file that exists
RewriteCond %{REQUEST_FILENAME} !-d # and it isn't a directory that exists either
RewriteCond %{REQUEST_FILENAME}\.html -f # but when you put ".html" on the end it is a file that exists
RewriteRule ^(.+)$ $1\.html [QSA] # then serve that file
</IfModule>
```
Apache `mod_rewrite` has been called "voodoo, but seriously cool voodoo".
The actual `.htaccess` code I use on a few sites is like that, but not identical:
```
<IfModule mod_rewrite.c>
RewriteEngine on
#RewriteRule ^$ index.php [QSA]
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.+)$ $1\.php [QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php/$1 [QSA]
</IfModule>
```
And here is some much longer but far more readable code to do the same thing on a Zeus server. On Zeus, it's called `rewrite.script`.
```
# http://drupal.org/node/46508
# get the document root
map path into SCRATCH:DOCROOT from /
# initialize our variables
set SCRATCH:ORIG_URL = %{URL}
set SCRATCH:REQUEST_URI = %{URL}
match URL into $ with ^(.*)\?(.*)$
if matched then
set SCRATCH:REQUEST_URI = $1
set SCRATCH:QUERY_STRING = $2
endif
# prepare to search for file, rewrite if its not found
set SCRATCH:REQUEST_FILENAME = %{SCRATCH:DOCROOT}
set SCRATCH:REQUEST_FILENAME . %{SCRATCH:REQUEST_URI}
# check to see if the file requested is an actual file or
# a directory with possibly an index. don't rewrite if so
look for file at %{SCRATCH:REQUEST_FILENAME}
if not exists then
look for dir at %{SCRATCH:REQUEST_FILENAME}
if not exists then
look for file at %{SCRATCH:REQUEST_FILENAME}.php
if exists then
set URL = %{SCRATCH:REQUEST_URI}.php?%{SCRATCH:QUERY_STRING}
else
set URL = /index.php/%{SCRATCH:REQUEST_URI}?%{SCRATCH:QUERY_STRING}
endif
endif
endif
goto END
``` |
1,759,420 | I want to hide page extensions like stackoverflow does. How does the following work?
```
http://stackoverflow.com/tags/foo
http://stackoverflow.com/tags/bar
```
I've seen a lot of sites that do this, but I still don't know how this is accomplished (I have a LAMP stack). | 2009/11/18 | [
"https://Stackoverflow.com/questions/1759420",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/214135/"
] | What you want is clean URLS and you can do it with apache and .htaccess . There may be a better way, but here's how I have been doing it:
<http://evolt.org/Making_clean_URLs_with_Apache_and_PHP> | There are a couple of ways to do it under Apache+PHP, but the essential principle is to make a set of URIs (perhaps all URIs, depending on your site, but you may want different scripts to handle different portions of the site) translate to a single PHP file, which is told what object the user has requested.
The conceptually simplest way is to rewrite every URL to a script, which gets the URI through [`$_SERVER['REQUEST_URI']`](http://php.net/manual/en/reserved.variables.server.php) and interprets it as it likes.
The URI rewriting can be done with various methods including mod\_rewrite, mod\_alias and ErrorDocument (see Apache docs).
Another way is to set up more complex URL rewriting (probably using mod\_rewrite) to add the path as a GET variable.
There is also the [`$_SERVER['PATH_INFO']`](http://php.net/manual/en/reserved.variables.server.php) variable which is loaded with the *non-existent* portion of the path. This option requires little or no modification to Apache config files, but reduces the flexibility of your URLs a little. |
1,759,420 | I want to hide page extensions like stackoverflow does. How does the following work?
```
http://stackoverflow.com/tags/foo
http://stackoverflow.com/tags/bar
```
I've seen a lot of sites that do this, but I still don't know how this is accomplished (I have a LAMP stack). | 2009/11/18 | [
"https://Stackoverflow.com/questions/1759420",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/214135/"
] | When a web server gets a request for a URL, it has to decide how to handle it. The classic method was to map the head of the URL to a directory in the file system, then let the rest of the URL navigate to a file in the filesystem. As a result, URLs had file extensions.
But there's no need to do it that way, and most new web frameworks don't. They let the programmer define how to map a URL to code to run, so there's no need for file extensions, because there is no single file providing the response.
In your example, there isn't a "tags" directory containing files "foo" and "bar". The "tags" URL is mapped to code that uses the rest of the URL ("foo" or "bar") as a parameter in a query against the database of tag data. | Modern web development frameworks have support for elegant urls. Check out [Django](http://www.djangoproject.com/) or [Ruby on Rails](http://rubyonrails.org/). |
1,759,420 | I want to hide page extensions like stackoverflow does. How does the following work?
```
http://stackoverflow.com/tags/foo
http://stackoverflow.com/tags/bar
```
I've seen a lot of sites that do this, but I still don't know how this is accomplished (I have a LAMP stack). | 2009/11/18 | [
"https://Stackoverflow.com/questions/1759420",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/214135/"
] | When a web server gets a request for a URL, it has to decide how to handle it. The classic method was to map the head of the URL to a directory in the file system, then let the rest of the URL navigate to a file in the filesystem. As a result, URLs had file extensions.
But there's no need to do it that way, and most new web frameworks don't. They let the programmer define how to map a URL to code to run, so there's no need for file extensions, because there is no single file providing the response.
In your example, there isn't a "tags" directory containing files "foo" and "bar". The "tags" URL is mapped to code that uses the rest of the URL ("foo" or "bar") as a parameter in a query against the database of tag data. | There are a couple of ways to do it under Apache+PHP, but the essential principle is to make a set of URIs (perhaps all URIs, depending on your site, but you may want different scripts to handle different portions of the site) translate to a single PHP file, which is told what object the user has requested.
The conceptually simplest way is to rewrite every URL to a script, which gets the URI through [`$_SERVER['REQUEST_URI']`](http://php.net/manual/en/reserved.variables.server.php) and interprets it as it likes.
The URI rewriting can be done with various methods including mod\_rewrite, mod\_alias and ErrorDocument (see Apache docs).
Another way is to set up more complex URL rewriting (probably using mod\_rewrite) to add the path as a GET variable.
There is also the [`$_SERVER['PATH_INFO']`](http://php.net/manual/en/reserved.variables.server.php) variable which is loaded with the *non-existent* portion of the path. This option requires little or no modification to Apache config files, but reduces the flexibility of your URLs a little. |
1,759,420 | I want to hide page extensions like stackoverflow does. How does the following work?
```
http://stackoverflow.com/tags/foo
http://stackoverflow.com/tags/bar
```
I've seen a lot of sites that do this, but I still don't know how this is accomplished (I have a LAMP stack). | 2009/11/18 | [
"https://Stackoverflow.com/questions/1759420",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/214135/"
] | When a web server gets a request for a URL, it has to decide how to handle it. The classic method was to map the head of the URL to a directory in the file system, then let the rest of the URL navigate to a file in the filesystem. As a result, URLs had file extensions.
But there's no need to do it that way, and most new web frameworks don't. They let the programmer define how to map a URL to code to run, so there's no need for file extensions, because there is no single file providing the response.
In your example, there isn't a "tags" directory containing files "foo" and "bar". The "tags" URL is mapped to code that uses the rest of the URL ("foo" or "bar") as a parameter in a query against the database of tag data. | That's the beauty and the work of [ASP.NET MVC](http://www.asp.net/mvc/).
No "hiding" - it's just the way ASP.NET MVC handles URL's and maps those "routes" to controller actions on your controller classes.
Quite a big step away from the "classic" ASP.NET Webforms way of doing things. |
1,759,420 | I want to hide page extensions like stackoverflow does. How does the following work?
```
http://stackoverflow.com/tags/foo
http://stackoverflow.com/tags/bar
```
I've seen a lot of sites that do this, but I still don't know how this is accomplished (I have a LAMP stack). | 2009/11/18 | [
"https://Stackoverflow.com/questions/1759420",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/214135/"
] | That's the beauty and the work of [ASP.NET MVC](http://www.asp.net/mvc/).
No "hiding" - it's just the way ASP.NET MVC handles URL's and maps those "routes" to controller actions on your controller classes.
Quite a big step away from the "classic" ASP.NET Webforms way of doing things. | There are a couple of ways to do it under Apache+PHP, but the essential principle is to make a set of URIs (perhaps all URIs, depending on your site, but you may want different scripts to handle different portions of the site) translate to a single PHP file, which is told what object the user has requested.
The conceptually simplest way is to rewrite every URL to a script, which gets the URI through [`$_SERVER['REQUEST_URI']`](http://php.net/manual/en/reserved.variables.server.php) and interprets it as it likes.
The URI rewriting can be done with various methods including mod\_rewrite, mod\_alias and ErrorDocument (see Apache docs).
Another way is to set up more complex URL rewriting (probably using mod\_rewrite) to add the path as a GET variable.
There is also the [`$_SERVER['PATH_INFO']`](http://php.net/manual/en/reserved.variables.server.php) variable which is loaded with the *non-existent* portion of the path. This option requires little or no modification to Apache config files, but reduces the flexibility of your URLs a little. |
1,759,420 | I want to hide page extensions like stackoverflow does. How does the following work?
```
http://stackoverflow.com/tags/foo
http://stackoverflow.com/tags/bar
```
I've seen a lot of sites that do this, but I still don't know how this is accomplished (I have a LAMP stack). | 2009/11/18 | [
"https://Stackoverflow.com/questions/1759420",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/214135/"
] | When a web server gets a request for a URL, it has to decide how to handle it. The classic method was to map the head of the URL to a directory in the file system, then let the rest of the URL navigate to a file in the filesystem. As a result, URLs had file extensions.
But there's no need to do it that way, and most new web frameworks don't. They let the programmer define how to map a URL to code to run, so there's no need for file extensions, because there is no single file providing the response.
In your example, there isn't a "tags" directory containing files "foo" and "bar". The "tags" URL is mapped to code that uses the rest of the URL ("foo" or "bar") as a parameter in a query against the database of tag data. | What you want is clean URLS and you can do it with apache and .htaccess . There may be a better way, but here's how I have been doing it:
<http://evolt.org/Making_clean_URLs_with_Apache_and_PHP> |
37,724 | A company that's using the contracting firm said they'd pay me $X per hour, and the same amount for hours over 40 in a given week. Apparently there's an exemption from the 1.5x pay for certain engineering positions, which I was told this was. I was (and am) happy with the pay we agreed on.
So the contracting firm sent me a copy of the standard contract to read and sign. But the contract said I was to be paid 1.5x the amount of my normal rate for overtime.
Before signing, I sent them a message saying, "I think this is a mistake." And they came back and said, "You're right, it's supposed to be 1x for overtime." They sent me another copy, but it had the same mistake in it. At that point, I signed it since we were on the same page regarding the terms even though it was still wrong. My thinking was that it was just a piece of (digital) paper that was wrong, and in my favor anyway. The actual contract (the intangible agreement between the two parties) was correct and mutually agreed upon.
My question is, **with the contract as it stands, is there any risk that I am taking by not fixing it?** I'm getting paid the amount I expect (1x for overtime) and have no intentions to pull more out of them just because the written contract is wrong. I don't want to be in a bad situation, but I don't want to go through the hassle of changing something that doesn't matter either.
Note: I live/work in New York state | 2019/02/28 | [
"https://law.stackexchange.com/questions/37724",
"https://law.stackexchange.com",
"https://law.stackexchange.com/users/24585/"
] | Clearly in this case the writing does not reflect your actual agreement. If you were to bill for 1.5x your normal rate for hours over 40/week, relying on the writing, and it came to court, you might win, based on the general rule that matters explicitly covered in the written agreement are treated as final, and evidence of contradictory oral agreements are often not accepted to contradict the contract document. This is known as the *parole evidence* rule.
But you don't plan to issue such a bill, so that won't come up. I don't see that you are at any legal risk. But you could send the client a letter saying that you signed the contract document so as not to hold the job up, but you think there is a mistake in it (pointing out exactly where and what the error is). This would help establish your ethics and good faith, so that if somehow there was a problem over this later (although that seems unlikely) you can't be accused of any improper actions. Keep a copy of any such letter.
By the way, if you are an independent contractor, the governmental standard for overtime does not normally apply (in the US). If you are an **employee** of a consulting company, it may or may not, depending on your salary level and the kind of work you do. An independent contractor **can** contract for a higher rate for overtime hours, if the client is willing to agree. Many clients will not be willing. | The contract itself does not present much of a danger, but the fact that they messed this up repeatedly does raise the question of whether they will mess other things up. For instance, when they fill out your 1099/W2 form, will they do so based on your actual income, or based on the 1.5x rate? |
49,680,958 | I want to copy Numeric DS to Alpha DS. First Idea was MOVEA, but that does not seem to work. Error: "The Factor 2 or Result-Field of a MOVEA does not refer to an array"
```
D Alpha DS
D TBR1 5A
D TBR2 5A
D Num DS
D TBR1N 5 0
D TBR2N 5 0
C MOVEA Alpha Num
``` | 2018/04/05 | [
"https://Stackoverflow.com/questions/49680958",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/977711/"
] | There seem to be a lot of misconceptions about data structures in RPG. In the past month there have been two questions because someone thought he could coerce the data structure to be a UCS2 value. It won't work. The data structure is a fixed length character field using the job's CCSID. The fact that it has some internal structure is meaningless if you are using the data structure name as your variable.
This seems to be compounded by fixed form RPG's ability to implicitly define a field as character or numeric without giving it a data type. Stand alone fields and data structures treat this condition differently. See the following table:
```
field type | decimal positions | Implicit data type
----------------------------------------------------
stand alone | blank | A
| not blank | P
----------------------------------------------------
data | blank | A
structure | not blank | S
```
So for your definitions:
```
D Alpha DS
D TBR1 5A
D TBR2 5A
D Num DS
D TBR1N 5 0
D TBR2N 5 0
```
`Alpha` is CHAR(10)
`TBR1` is CHAR(5)
`TBR2` is CHAR(5)
`Num` is CHAR(10)
`TBR1N` is ZONED(5 0)
`TBR2N` is ZONED(5 0)
There are no arrays so you can not use `MOVEA` with any of these on both sides., but `MOVEL` would work to assign `Alpha` to `Num` like this:
```
C MOVEL Alpha Num
```
That being said, you should not be using Fixed Form any more. All supported versions of the OS support Free Form RPGIV, and you can gain some advantages by using it. Specifically to this case, the implicit numeric data type is not possible in Free Form. So you would have something like this:
```
dcl-ds Alpha Qualified;
tbr1 Char(5);
tbr2 Char(5);
end-ds;
dcl-ds Num Qualified;
tbr1n Zoned(5:0);
tbr2n Zoned(5:0);
end-ds;
Num = Alpha;
```
Data types are now explicit, and you can even qualify your data structures so that you can say something like this:
```
num.tbr1n = %dec(alpha.tbr1:5:0);
``` | First off, there's no such thing as a "numeric DS".
A data structure in RPG is just a collection of bytes. And since the compiler doesn't have a BYTE type, it simply treats it as SBCS characters.
You're issue is that your numeric subfields are defaulting to packed decimal. So your DS named NUM is only 6 bytes.
Define them as ZONED instead, so that both DS will be 10 bytes.
```
D Alpha DS
D TBR1 5A
D TBR2 5A
D Num DS
D TBR1N 5S 0
D TBR2N 5S 0
Num = Alpha;
```
But this kind of code really isn't a good idea in RPGIV..
Why can't you explicitly convert?
```
tbr1n = %dec(tbr1:5:0);
tbr2n = %dec(tbr2:5:0);
``` |
52,006,600 | I am fairly new to Spring Webapplication and need to do a little project for university. Currently I have a simple html site that displays some Data that I manually inserted into the database.
Now I am currently working on a new html file to insert Data through a seperate form.
On my "main" page I have a navbar, where I want to click on an item and get redirected to a specific page.
I tried redirecting the link directly to an html file in my resources folder, but it doesnt seem to work.
```
<li class="nav-item active">
<a class="nav-link" href="/inputbook.html">Add Book <span class="sr-only">(current)</span></a>
</li>
```
I also tried to link it by:
* "${pageContext.servletContext.contextPath}/inputbook.html" (Found that in another thread)
* "./inputbook.html"
* "../inputbook.html"
Is there a way to simply link this page or do I need to make an action + a method in a Controller?
Thank you!
UPDATE:
Something interresting just happened. I added the method to map the site in my controller.
When I try to open this site through the navbar, it tells me that it isnt mapped. Now (for testing, I have the form from the "inputbook.html" file also in my main page) when I input data through the main pages form, it saves it to the database and displays it correctly. After this process when I click on the Nav Bar again, it opens the "inputbook.html" site without any problems?
Controller:
```
@RequiredArgsConstructor
@Controller
@RequestMapping("/books")
public class BookController {
private final BookService bookService;
private final BookRepository bookRepository;
@GetMapping
public String showBooks(Model model) {
List<Book> books = bookService.findAll();
model.addAttribute("books",books);
return "books"; //view name
}
@PostMapping(value="/search")
public String serachByTitle(Model model, @RequestParam Optional<String> searchTerm) {//Parameter heißt wie Feld in html form
List<Book> books = searchTerm.map(bookService::findByTitleLike)
.orElseGet(bookService::findAll);
model.addAttribute("searchTerm",searchTerm.get());
model.addAttribute("books",books);
return "books";
}
@GetMapping("inputbook.html")
public String inputbook() {
return "inputbook"; // this returns the template name to be rendered from resources/templates. You don't need to provide the extension.
}
@PostMapping(value="/insert")
public String insertBook(Model model,@RequestParam String title) {
Book book = Book.builder()
.title(title)
.description("beschreibung")
.author("auth" )
.isbn(12353)
.creator("creator") // fake it till spring security
.creationTS(LocalDateTime.MIN)
.publisher("pub")
.available(true)
.deliveryTimeDay(2)
.build();
bookRepository.save(book);
return showBooks(model);
}
```
}
books.html("Main" Page)
```
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>Books</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css"
integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous"/>
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav mr-auto">
<li class="nav-item active">
<a class="nav-link" href="inputbook.html">Add Book <span class="sr-only">(current)</span></a>
</li>
<a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
</li>
<a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
</li>
</ul>
</div>
</nav>
<div class="container">
<form method="post" th:action="@{/books/search}">
<div class="form-group">
<label th:for="searchTerm">Searchterm</label>
<input type="text" class="form-control" th:name="searchTerm">
</div>
<button type="submit" class="btn btn-primary">Search</button>
</form>
**<form method="post" th:action="@{/books/insert}">
<div class="form-group">
<label th:for="title">Titel</label>
<input type="text" class="form-control" th:name="title">
</div>
<button type="submit" class="btn btn-primary">Save</button>
</form>**
<table class="table">
<thead>
<tr>
<th>Title</th>
<th>CreationTS</th>
<th>Author</th>
<th>Creator</th>
</tr>
</thead>
<tbody>
<tr th:each="book : ${books}">
<td th:text="${book.title}">Betreff</td>
<td th:text="${book.creationTS}">2018-01-01 10:01:01</td>
<td th:text="${book.author}">TestAuthor</td>
<td th:text="${book.creator}">TestCreator</td>
</tr>
</tbody>
</table>
</div>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"
integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo"
crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js"
integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49"
crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"
integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy"
crossorigin="anonymous"></script>
</body>
</html>
```
inputbook.html
```
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>Books</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css"
integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous"/>
</head>
<body>
<div class="container">
<form method="post" th:action="@{/books/insert}">
<div class="form-group">
<label th:for="title">Titel</label>
<input type="text" class="form-control" th:name="title">
</div>
<button type="submit" class="btn btn-primary">Save</button>
</form>
</div>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"
integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo"
crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js"
integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49"
crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"
integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy"
crossorigin="anonymous"></script>
</body>
</html>
``` | 2018/08/24 | [
"https://Stackoverflow.com/questions/52006600",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6057538/"
] | You can define a helper class to support piecewise construction:
```
template <typename T>
struct Piecewise_construct_wrapper : T {
template <typename Tuple>
Piecewise_construct_wrapper(Tuple&& t) :
Piecewise_construct_wrapper(std::forward<Tuple>(t),
std::make_index_sequence<std::tuple_size_v<Tuple>>{}) {}
template <typename Tuple, size_t... Indexes>
Piecewise_construct_wrapper(Tuple&& t, std::index_sequence<Indexes...>) :
T(std::get<Indexes>(std::forward<Tuple>(t))...) {}
};
```
Then you can make your `Composition` inherit `Piecewise_construct_wrapper<Mixins>...`:
```
template <typename... Mixins>
struct Composition : private Piecewise_construct_wrapper<Mixins>... {
template <typename... Packs>
Composition(Packs&&... packs)
: Piecewise_construct_wrapper<Mixins>(std::forward<Packs>(packs))...
{
}
};
``` | >
> I would like to avoid the indirection through constructMixin, and directly construct every inherited mixin object so that the need for a copy/move constructor on the mixin type can be avoided. Is this possible?
>
>
>
You would need the Mixins to opt-in to allowing piecewise construction directly. Unfortunately that's pretty repetitive, so you could use a macro like:
```
#define PIECEWISE_CONSTRUCT(Type) \
template <typename Tuple> \
Type(std::piecewise_construct_t, Tuple&& tuple) \
: Type(std::piecewise_construct, \
std::forward<Tuple>(tuple), \
std::make_index_sequence<std::tuple_size_v<Tuple>>()) \
{ } \
template <typename Tuple, size_t... Indexes> \
Type(std::piecewise_construct_t, Tuple&& tuple, \
std::index_sequence<Indexes...>) \
: Type(std::get<Indexes>(std::forward<Tuple>(tuple))...) \
{ }
```
To be used as:
```
struct MixinA : public MixinBase {
MixinA(int, const std::string&, const std::string&) {}
PIECEWISE_CONSTRUCT(MixinA)
};
struct MixinB : public MixinBase {
MixinB(const std::string&, const std::string&) {}
PIECEWISE_CONSTRUCT(MixinB)
};
template <typename... Mixins>
struct Composition : private Mixins... {
template <typename... Packs>
Composition(Packs&&... packs)
: Mixins(std::piecewise_construct, std::forward<Packs>(packs))...
{ }
};
```
Guaranteed copy elision unfortunately can't work in constructing subobjects - so this might be your best bet. I don't think you can do this any more directly without having some kind of nested packs? It's very possible that I'm just not creative enough though and would be very curious if somebody comes up with something better. |
37,669,768 | I'm trying to get data from my SendGrid account via their API. I'm using classic ASP. I found [some code that works](https://stackoverflow.com/questions/27368436/classic-asp-parse-json-xmlhttp-return) except that I need to add authorization for SendGrids API as described [in their documentation](https://sendgrid.com/docs/API_Reference/Web_API_v3/How_To_Use_The_Web_API_v3/authentication.html).
I've found several examples that seem to suggest I need to add xmlhttp.setRequestHeader after the xmlhttp.open and before the xmlhttp.send but when I uncomment the line "xmlhttp.setRequestHeader" below I get a 500 error in my browser. Can anyone tell me now to add the authorization part to the xmlhttp object?
**Edit for clarity:** When I comment the line "xmlhttp.setRequestHeader..." the script runs and returns the expected json result that says I need to authenticate. When I uncomment that line I get a 500 error. I have replaced my working api key (tested with a cURL command) with a generic placeholder in my code below. The real key is in place in the file on my server.
Heres the code I'm using:
```vb
<%@ Language=VBScript %>
<%
Set xmlhttp = CreateObject("Msxml2.ServerXMLHTTP.6.0")
xmlhttp.open "GET", "https://api.sendgrid.com/v3/campaigns?limit=10&offset=0 HTTP/1.1", false
'xmlhttp.setRequestHeader "Authorization", "Bearer my-correct-sendgrid-api-key"
xmlhttp.send ""
Response.AddHeader "Content-Type", "application/json;charset=UTF-8"
Response.Charset = "UTF-8"
pageReturn = xmlhttp.responseText
Set xmlhttp = Nothing
response.write pageReturn
%>
```
It seems the basics are working because the code above returns the expected json results, the error message that says I need to authenticate:
```js
{
errors: [
{
field: null,
message: "authorization required"
}
]
}
```
SendGrids documentation uses this example:
```none
GET https://api.sendgrid.com/v3/resource HTTP/1.1
Authorization: Bearer Your.API.Key-HERE
``` | 2016/06/07 | [
"https://Stackoverflow.com/questions/37669768",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2800784/"
] | Thanks everyone! Credit goes to [Kul-Tigin](https://stackoverflow.com/users/893670/kul-tigin) for pointing out my error, which was misinterpreting the comment "HTTP/1.1" for part of the url in SendGrids example.
When I changed:
```
xmlhttp.open "GET", "https://api.sendgrid.com/v3/campaigns?limit=10&offset=0 HTTP/1.1", false
xmlhttp.setRequestHeader "Authorization", "Bearer my-correct-sendgrid-api-key"
```
to:
```
xmlhttp.open "GET", "https://api.sendgrid.com/v3/campaigns?limit=10&offset=0", false
xmlhttp.setRequestHeader "Authorization", "Bearer my-correct-sendgrid-api-key"
```
It started working without errors. Here's the working code:
```
<!-- language: lang-js -->
<%@ Language=VBScript %>
<%
Set xmlhttp = CreateObject("Msxml2.ServerXMLHTTP.6.0")
xmlhttp.open "GET", "https://api.sendgrid.com/v3/campaigns?limit=10&offset=0", false
xmlhttp.setRequestHeader "Authorization", "Bearer my-correct-sendgrid-api-key"
xmlhttp.send ""
Response.AddHeader "Content-Type", "application/json;charset=UTF-8"
Response.Charset = "UTF-8"
pageReturn = xmlhttp.responseText
Set xmlhttp = Nothing
response.write pageReturn
%>
```
[SearchAndResQ](https://stackoverflow.com/users/1682881/searchandresq) I'll read the link you provided on error trapping. Thanks! | After [some discussion](https://stackoverflow.com/questions/37669768/classic-asp-xmlhttp-get-how-to-add-authentication-for-sendgrid-api/37682397#comment62836801_37669768) in the comments, it seems the issue is this line
```
xmlhttp.setRequestHeader "Authorization", "Bearer my-correct-sendgrid-api-key"
```
This is the correct way to set a HTTP Authorization header on a `IServerXMLHTTPRequest` instance.
The `Bearer my-correct-sendgrid-api-key` will need to be replaced with your actual API key or you'll likely have an error response.
According to the [documentation](https://sendgrid.com/docs/API_Reference/index.html);
>
> From [How To Use The Web API v3 - Authentication](https://sendgrid.com/docs/API_Reference/Web_API_v3/How_To_Use_The_Web_API_v3/authentication.html)
>
> *API Keys can be generated in your account - visit <https://app.sendgrid.com/settings/api_keys>. To use keys, you must set a plain text header named “Authorization” with the contents of the header being “Bearer XXX” where XXX is your API Secret Key.*
>
>
> |
37,669,768 | I'm trying to get data from my SendGrid account via their API. I'm using classic ASP. I found [some code that works](https://stackoverflow.com/questions/27368436/classic-asp-parse-json-xmlhttp-return) except that I need to add authorization for SendGrids API as described [in their documentation](https://sendgrid.com/docs/API_Reference/Web_API_v3/How_To_Use_The_Web_API_v3/authentication.html).
I've found several examples that seem to suggest I need to add xmlhttp.setRequestHeader after the xmlhttp.open and before the xmlhttp.send but when I uncomment the line "xmlhttp.setRequestHeader" below I get a 500 error in my browser. Can anyone tell me now to add the authorization part to the xmlhttp object?
**Edit for clarity:** When I comment the line "xmlhttp.setRequestHeader..." the script runs and returns the expected json result that says I need to authenticate. When I uncomment that line I get a 500 error. I have replaced my working api key (tested with a cURL command) with a generic placeholder in my code below. The real key is in place in the file on my server.
Heres the code I'm using:
```vb
<%@ Language=VBScript %>
<%
Set xmlhttp = CreateObject("Msxml2.ServerXMLHTTP.6.0")
xmlhttp.open "GET", "https://api.sendgrid.com/v3/campaigns?limit=10&offset=0 HTTP/1.1", false
'xmlhttp.setRequestHeader "Authorization", "Bearer my-correct-sendgrid-api-key"
xmlhttp.send ""
Response.AddHeader "Content-Type", "application/json;charset=UTF-8"
Response.Charset = "UTF-8"
pageReturn = xmlhttp.responseText
Set xmlhttp = Nothing
response.write pageReturn
%>
```
It seems the basics are working because the code above returns the expected json results, the error message that says I need to authenticate:
```js
{
errors: [
{
field: null,
message: "authorization required"
}
]
}
```
SendGrids documentation uses this example:
```none
GET https://api.sendgrid.com/v3/resource HTTP/1.1
Authorization: Bearer Your.API.Key-HERE
``` | 2016/06/07 | [
"https://Stackoverflow.com/questions/37669768",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2800784/"
] | After [some discussion](https://stackoverflow.com/questions/37669768/classic-asp-xmlhttp-get-how-to-add-authentication-for-sendgrid-api/37682397#comment62836801_37669768) in the comments, it seems the issue is this line
```
xmlhttp.setRequestHeader "Authorization", "Bearer my-correct-sendgrid-api-key"
```
This is the correct way to set a HTTP Authorization header on a `IServerXMLHTTPRequest` instance.
The `Bearer my-correct-sendgrid-api-key` will need to be replaced with your actual API key or you'll likely have an error response.
According to the [documentation](https://sendgrid.com/docs/API_Reference/index.html);
>
> From [How To Use The Web API v3 - Authentication](https://sendgrid.com/docs/API_Reference/Web_API_v3/How_To_Use_The_Web_API_v3/authentication.html)
>
> *API Keys can be generated in your account - visit <https://app.sendgrid.com/settings/api_keys>. To use keys, you must set a plain text header named “Authorization” with the contents of the header being “Bearer XXX” where XXX is your API Secret Key.*
>
>
> | this works for getting access to a remote api from classic asp.
the inverse is creating an api en classic asp and the client needs to send us a token auth
in this case you get this value: Request.ServerVariables("HTTP\_Authorization")
this one takes to me weeks and weeks inderstanding, but i know how to and want to share with all te asp developers. asp forever |
37,669,768 | I'm trying to get data from my SendGrid account via their API. I'm using classic ASP. I found [some code that works](https://stackoverflow.com/questions/27368436/classic-asp-parse-json-xmlhttp-return) except that I need to add authorization for SendGrids API as described [in their documentation](https://sendgrid.com/docs/API_Reference/Web_API_v3/How_To_Use_The_Web_API_v3/authentication.html).
I've found several examples that seem to suggest I need to add xmlhttp.setRequestHeader after the xmlhttp.open and before the xmlhttp.send but when I uncomment the line "xmlhttp.setRequestHeader" below I get a 500 error in my browser. Can anyone tell me now to add the authorization part to the xmlhttp object?
**Edit for clarity:** When I comment the line "xmlhttp.setRequestHeader..." the script runs and returns the expected json result that says I need to authenticate. When I uncomment that line I get a 500 error. I have replaced my working api key (tested with a cURL command) with a generic placeholder in my code below. The real key is in place in the file on my server.
Heres the code I'm using:
```vb
<%@ Language=VBScript %>
<%
Set xmlhttp = CreateObject("Msxml2.ServerXMLHTTP.6.0")
xmlhttp.open "GET", "https://api.sendgrid.com/v3/campaigns?limit=10&offset=0 HTTP/1.1", false
'xmlhttp.setRequestHeader "Authorization", "Bearer my-correct-sendgrid-api-key"
xmlhttp.send ""
Response.AddHeader "Content-Type", "application/json;charset=UTF-8"
Response.Charset = "UTF-8"
pageReturn = xmlhttp.responseText
Set xmlhttp = Nothing
response.write pageReturn
%>
```
It seems the basics are working because the code above returns the expected json results, the error message that says I need to authenticate:
```js
{
errors: [
{
field: null,
message: "authorization required"
}
]
}
```
SendGrids documentation uses this example:
```none
GET https://api.sendgrid.com/v3/resource HTTP/1.1
Authorization: Bearer Your.API.Key-HERE
``` | 2016/06/07 | [
"https://Stackoverflow.com/questions/37669768",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2800784/"
] | Thanks everyone! Credit goes to [Kul-Tigin](https://stackoverflow.com/users/893670/kul-tigin) for pointing out my error, which was misinterpreting the comment "HTTP/1.1" for part of the url in SendGrids example.
When I changed:
```
xmlhttp.open "GET", "https://api.sendgrid.com/v3/campaigns?limit=10&offset=0 HTTP/1.1", false
xmlhttp.setRequestHeader "Authorization", "Bearer my-correct-sendgrid-api-key"
```
to:
```
xmlhttp.open "GET", "https://api.sendgrid.com/v3/campaigns?limit=10&offset=0", false
xmlhttp.setRequestHeader "Authorization", "Bearer my-correct-sendgrid-api-key"
```
It started working without errors. Here's the working code:
```
<!-- language: lang-js -->
<%@ Language=VBScript %>
<%
Set xmlhttp = CreateObject("Msxml2.ServerXMLHTTP.6.0")
xmlhttp.open "GET", "https://api.sendgrid.com/v3/campaigns?limit=10&offset=0", false
xmlhttp.setRequestHeader "Authorization", "Bearer my-correct-sendgrid-api-key"
xmlhttp.send ""
Response.AddHeader "Content-Type", "application/json;charset=UTF-8"
Response.Charset = "UTF-8"
pageReturn = xmlhttp.responseText
Set xmlhttp = Nothing
response.write pageReturn
%>
```
[SearchAndResQ](https://stackoverflow.com/users/1682881/searchandresq) I'll read the link you provided on error trapping. Thanks! | If you cannot access the error logs, you could trap the error using `On Error Resume Next` and see what the error description tells you.
```
<%@ Language=VBScript %>
<%
Set xmlhttp = CreateObject("Msxml2.ServerXMLHTTP.6.0")
xmlhttp.open "GET", "https://api.sendgrid.com/v3/campaigns?limit=10&offset=0", false
On Error Resume Next
xmlhttp.setRequestHeader "Authorization", "Bearer xx.xxxxx.xxxx"
If Err.Number<>0 Then
Response.Write "Error:" & Err.Description & "<br>"
End If
On Error GoTo 0
xmlhttp.send ""
Response.AddHeader "Content-Type", "application/json;charset=UTF-8"
Response.Charset = "UTF-8"
pageReturn = xmlhttp.responseText
Set xmlhttp = Nothing
response.write pageReturn
%>
```
See : [On Error Statement](https://msdn.microsoft.com/en-us/library/53f3k80h(v=vs.84).aspx) |
37,669,768 | I'm trying to get data from my SendGrid account via their API. I'm using classic ASP. I found [some code that works](https://stackoverflow.com/questions/27368436/classic-asp-parse-json-xmlhttp-return) except that I need to add authorization for SendGrids API as described [in their documentation](https://sendgrid.com/docs/API_Reference/Web_API_v3/How_To_Use_The_Web_API_v3/authentication.html).
I've found several examples that seem to suggest I need to add xmlhttp.setRequestHeader after the xmlhttp.open and before the xmlhttp.send but when I uncomment the line "xmlhttp.setRequestHeader" below I get a 500 error in my browser. Can anyone tell me now to add the authorization part to the xmlhttp object?
**Edit for clarity:** When I comment the line "xmlhttp.setRequestHeader..." the script runs and returns the expected json result that says I need to authenticate. When I uncomment that line I get a 500 error. I have replaced my working api key (tested with a cURL command) with a generic placeholder in my code below. The real key is in place in the file on my server.
Heres the code I'm using:
```vb
<%@ Language=VBScript %>
<%
Set xmlhttp = CreateObject("Msxml2.ServerXMLHTTP.6.0")
xmlhttp.open "GET", "https://api.sendgrid.com/v3/campaigns?limit=10&offset=0 HTTP/1.1", false
'xmlhttp.setRequestHeader "Authorization", "Bearer my-correct-sendgrid-api-key"
xmlhttp.send ""
Response.AddHeader "Content-Type", "application/json;charset=UTF-8"
Response.Charset = "UTF-8"
pageReturn = xmlhttp.responseText
Set xmlhttp = Nothing
response.write pageReturn
%>
```
It seems the basics are working because the code above returns the expected json results, the error message that says I need to authenticate:
```js
{
errors: [
{
field: null,
message: "authorization required"
}
]
}
```
SendGrids documentation uses this example:
```none
GET https://api.sendgrid.com/v3/resource HTTP/1.1
Authorization: Bearer Your.API.Key-HERE
``` | 2016/06/07 | [
"https://Stackoverflow.com/questions/37669768",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2800784/"
] | If you cannot access the error logs, you could trap the error using `On Error Resume Next` and see what the error description tells you.
```
<%@ Language=VBScript %>
<%
Set xmlhttp = CreateObject("Msxml2.ServerXMLHTTP.6.0")
xmlhttp.open "GET", "https://api.sendgrid.com/v3/campaigns?limit=10&offset=0", false
On Error Resume Next
xmlhttp.setRequestHeader "Authorization", "Bearer xx.xxxxx.xxxx"
If Err.Number<>0 Then
Response.Write "Error:" & Err.Description & "<br>"
End If
On Error GoTo 0
xmlhttp.send ""
Response.AddHeader "Content-Type", "application/json;charset=UTF-8"
Response.Charset = "UTF-8"
pageReturn = xmlhttp.responseText
Set xmlhttp = Nothing
response.write pageReturn
%>
```
See : [On Error Statement](https://msdn.microsoft.com/en-us/library/53f3k80h(v=vs.84).aspx) | this works for getting access to a remote api from classic asp.
the inverse is creating an api en classic asp and the client needs to send us a token auth
in this case you get this value: Request.ServerVariables("HTTP\_Authorization")
this one takes to me weeks and weeks inderstanding, but i know how to and want to share with all te asp developers. asp forever |
37,669,768 | I'm trying to get data from my SendGrid account via their API. I'm using classic ASP. I found [some code that works](https://stackoverflow.com/questions/27368436/classic-asp-parse-json-xmlhttp-return) except that I need to add authorization for SendGrids API as described [in their documentation](https://sendgrid.com/docs/API_Reference/Web_API_v3/How_To_Use_The_Web_API_v3/authentication.html).
I've found several examples that seem to suggest I need to add xmlhttp.setRequestHeader after the xmlhttp.open and before the xmlhttp.send but when I uncomment the line "xmlhttp.setRequestHeader" below I get a 500 error in my browser. Can anyone tell me now to add the authorization part to the xmlhttp object?
**Edit for clarity:** When I comment the line "xmlhttp.setRequestHeader..." the script runs and returns the expected json result that says I need to authenticate. When I uncomment that line I get a 500 error. I have replaced my working api key (tested with a cURL command) with a generic placeholder in my code below. The real key is in place in the file on my server.
Heres the code I'm using:
```vb
<%@ Language=VBScript %>
<%
Set xmlhttp = CreateObject("Msxml2.ServerXMLHTTP.6.0")
xmlhttp.open "GET", "https://api.sendgrid.com/v3/campaigns?limit=10&offset=0 HTTP/1.1", false
'xmlhttp.setRequestHeader "Authorization", "Bearer my-correct-sendgrid-api-key"
xmlhttp.send ""
Response.AddHeader "Content-Type", "application/json;charset=UTF-8"
Response.Charset = "UTF-8"
pageReturn = xmlhttp.responseText
Set xmlhttp = Nothing
response.write pageReturn
%>
```
It seems the basics are working because the code above returns the expected json results, the error message that says I need to authenticate:
```js
{
errors: [
{
field: null,
message: "authorization required"
}
]
}
```
SendGrids documentation uses this example:
```none
GET https://api.sendgrid.com/v3/resource HTTP/1.1
Authorization: Bearer Your.API.Key-HERE
``` | 2016/06/07 | [
"https://Stackoverflow.com/questions/37669768",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2800784/"
] | Thanks everyone! Credit goes to [Kul-Tigin](https://stackoverflow.com/users/893670/kul-tigin) for pointing out my error, which was misinterpreting the comment "HTTP/1.1" for part of the url in SendGrids example.
When I changed:
```
xmlhttp.open "GET", "https://api.sendgrid.com/v3/campaigns?limit=10&offset=0 HTTP/1.1", false
xmlhttp.setRequestHeader "Authorization", "Bearer my-correct-sendgrid-api-key"
```
to:
```
xmlhttp.open "GET", "https://api.sendgrid.com/v3/campaigns?limit=10&offset=0", false
xmlhttp.setRequestHeader "Authorization", "Bearer my-correct-sendgrid-api-key"
```
It started working without errors. Here's the working code:
```
<!-- language: lang-js -->
<%@ Language=VBScript %>
<%
Set xmlhttp = CreateObject("Msxml2.ServerXMLHTTP.6.0")
xmlhttp.open "GET", "https://api.sendgrid.com/v3/campaigns?limit=10&offset=0", false
xmlhttp.setRequestHeader "Authorization", "Bearer my-correct-sendgrid-api-key"
xmlhttp.send ""
Response.AddHeader "Content-Type", "application/json;charset=UTF-8"
Response.Charset = "UTF-8"
pageReturn = xmlhttp.responseText
Set xmlhttp = Nothing
response.write pageReturn
%>
```
[SearchAndResQ](https://stackoverflow.com/users/1682881/searchandresq) I'll read the link you provided on error trapping. Thanks! | this works for getting access to a remote api from classic asp.
the inverse is creating an api en classic asp and the client needs to send us a token auth
in this case you get this value: Request.ServerVariables("HTTP\_Authorization")
this one takes to me weeks and weeks inderstanding, but i know how to and want to share with all te asp developers. asp forever |
35,189,387 | Why the below code doesn't print any output whereas if we remove parallel, it prints 0, 1?
```
IntStream.iterate(0, i -> ( i + 1 ) % 2)
.parallel()
.distinct()
.limit(10)
.forEach(System.out::println);
```
Though I know ideally limit should be placed before distinct, but my question is more related with the difference caused by adding parallel processing. | 2016/02/03 | [
"https://Stackoverflow.com/questions/35189387",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2645833/"
] | [Stream.iterate](https://docs.oracle.com/javase/8/docs/api/java/util/stream/Stream.html#iterate-T-java.util.function.UnaryOperator-) returns 'an infinite sequential ordered Stream'. Therefore, making a sequential stream parallel is not too useful.
According to the description of the [Stream package](https://docs.oracle.com/javase/8/docs/api/java/util/stream/package-summary.html):
>
> For parallel streams, relaxing the ordering constraint can sometimes enable more efficient execution. Certain aggregate operations, such as filtering duplicates (distinct()) or grouped reductions (Collectors.groupingBy()) can be implemented more efficiently if ordering of elements is not relevant. Similarly, operations that are intrinsically tied to encounter order, such as limit(), may require buffering to ensure proper ordering, undermining the benefit of parallelism. In cases where the stream has an encounter order, but the user does not particularly care about that encounter order, explicitly de-ordering the stream with unordered() may improve parallel performance for some stateful or terminal operations. However, most stream pipelines, such as the "sum of weight of blocks" example above, still parallelize efficiently even under ordering constraints.
>
>
>
this seems to be the case in your case, using unordered(), it prints 0,1.
```
IntStream.iterate(0, i -> (i + 1) % 2)
.parallel()
.unordered()
.distinct()
.limit(10)
.forEach(System.out::println);
``` | This code has a major problem, even without the parallel:
After .distinct(), the stream will only have 2 elements- so the limit never kicks in- it will print the two elements and then continue wasting your CPU time indefinitely. This might have been what you intended though.
With parallel and limit, I believe the problem is exacerbated due to the way the work is divided. I haven't traced all the way through the parallel stream code, but here is my guess:
The parallel code divides the work between multiple threads, which all chug along indefinitely as they never fill their quota. The system probably waits for each thread to finish so it can combine their results to ensure distinctness in order- but this will never happen in the case you provide.
Without the order requirement, results from each worker thread can be immediately uses after being checked against a global distinctness set.
Without limit, I suspect that different code is used to handle infinite streams: instead of waiting for the required 10 to fill up, results are reported as discovered. Its a little like making an iterator that reports hasNext() = true, first produces 0, then 1, then the next() call hangs forever without producing a result- in the parallel case something is waiting for several reports so it can properly combine/order them before outputting, while in the serial case it does what it can then hangs.
Ill try to find the exact difference in call stack with and without distinct() or limit(), but so far it seems very difficult to navigate the rather complex stream library calling sequence. |
35,189,387 | Why the below code doesn't print any output whereas if we remove parallel, it prints 0, 1?
```
IntStream.iterate(0, i -> ( i + 1 ) % 2)
.parallel()
.distinct()
.limit(10)
.forEach(System.out::println);
```
Though I know ideally limit should be placed before distinct, but my question is more related with the difference caused by adding parallel processing. | 2016/02/03 | [
"https://Stackoverflow.com/questions/35189387",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2645833/"
] | The real cause is that *ordered parallel* `.distinct()` is the full barrier operation as [described](https://docs.oracle.com/javase/8/docs/api/java/util/stream/Stream.html#distinct--) in documentation:
>
> Preserving stability for `distinct()` in parallel pipelines is relatively expensive (requires that the operation act as a full barrier, with substantial buffering overhead), and stability is often not needed.
>
>
>
The "full barrier operation" means that all the upstream operations must be performed before the downstream can start. There are only two full barrier operations in Stream API: `.sorted()` (every time) and `.distinct()` (in ordered parallel case). As you have non short-circuit infinite stream supplied to the `.distinct()` you end up with infinite loop. By contract `.distinct()` cannot just emit elements to the downstream in any order: it should always emit the first repeating element. While it's theoretically possible to implement parallel ordered `.distinct()` better, it would be much more complex implementation.
As for solution, @user140547 is right: add `.unordered()` before `.distinct()` this switches `distinct()` algorithm to unordered one (which just uses shared `ConcurrentHashMap` to store all the observed elements and emits every new element to the downstream). Note that adding `.unordered()` *after* `.distinct()` will not help. | [Stream.iterate](https://docs.oracle.com/javase/8/docs/api/java/util/stream/Stream.html#iterate-T-java.util.function.UnaryOperator-) returns 'an infinite sequential ordered Stream'. Therefore, making a sequential stream parallel is not too useful.
According to the description of the [Stream package](https://docs.oracle.com/javase/8/docs/api/java/util/stream/package-summary.html):
>
> For parallel streams, relaxing the ordering constraint can sometimes enable more efficient execution. Certain aggregate operations, such as filtering duplicates (distinct()) or grouped reductions (Collectors.groupingBy()) can be implemented more efficiently if ordering of elements is not relevant. Similarly, operations that are intrinsically tied to encounter order, such as limit(), may require buffering to ensure proper ordering, undermining the benefit of parallelism. In cases where the stream has an encounter order, but the user does not particularly care about that encounter order, explicitly de-ordering the stream with unordered() may improve parallel performance for some stateful or terminal operations. However, most stream pipelines, such as the "sum of weight of blocks" example above, still parallelize efficiently even under ordering constraints.
>
>
>
this seems to be the case in your case, using unordered(), it prints 0,1.
```
IntStream.iterate(0, i -> (i + 1) % 2)
.parallel()
.unordered()
.distinct()
.limit(10)
.forEach(System.out::println);
``` |
35,189,387 | Why the below code doesn't print any output whereas if we remove parallel, it prints 0, 1?
```
IntStream.iterate(0, i -> ( i + 1 ) % 2)
.parallel()
.distinct()
.limit(10)
.forEach(System.out::println);
```
Though I know ideally limit should be placed before distinct, but my question is more related with the difference caused by adding parallel processing. | 2016/02/03 | [
"https://Stackoverflow.com/questions/35189387",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2645833/"
] | I know the code is not correct and as suggested in the solution too, if we move the limit before distinct, we won't have infinite loop.
Parallel function is using fork and join concept to allocate the work, which allocates all the available thread for the work, rather than single thread.
We are rightly expecting infinite loop, as multiple thread is infinitely processing a data and nothing stopping them, as the limit of 10 is never hitting after distinct.
It might be possible that it keeps trying to fork and never tries to join to move it forward. But still I believe its a defect in the java with more than anything else. | This code has a major problem, even without the parallel:
After .distinct(), the stream will only have 2 elements- so the limit never kicks in- it will print the two elements and then continue wasting your CPU time indefinitely. This might have been what you intended though.
With parallel and limit, I believe the problem is exacerbated due to the way the work is divided. I haven't traced all the way through the parallel stream code, but here is my guess:
The parallel code divides the work between multiple threads, which all chug along indefinitely as they never fill their quota. The system probably waits for each thread to finish so it can combine their results to ensure distinctness in order- but this will never happen in the case you provide.
Without the order requirement, results from each worker thread can be immediately uses after being checked against a global distinctness set.
Without limit, I suspect that different code is used to handle infinite streams: instead of waiting for the required 10 to fill up, results are reported as discovered. Its a little like making an iterator that reports hasNext() = true, first produces 0, then 1, then the next() call hangs forever without producing a result- in the parallel case something is waiting for several reports so it can properly combine/order them before outputting, while in the serial case it does what it can then hangs.
Ill try to find the exact difference in call stack with and without distinct() or limit(), but so far it seems very difficult to navigate the rather complex stream library calling sequence. |
35,189,387 | Why the below code doesn't print any output whereas if we remove parallel, it prints 0, 1?
```
IntStream.iterate(0, i -> ( i + 1 ) % 2)
.parallel()
.distinct()
.limit(10)
.forEach(System.out::println);
```
Though I know ideally limit should be placed before distinct, but my question is more related with the difference caused by adding parallel processing. | 2016/02/03 | [
"https://Stackoverflow.com/questions/35189387",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2645833/"
] | The real cause is that *ordered parallel* `.distinct()` is the full barrier operation as [described](https://docs.oracle.com/javase/8/docs/api/java/util/stream/Stream.html#distinct--) in documentation:
>
> Preserving stability for `distinct()` in parallel pipelines is relatively expensive (requires that the operation act as a full barrier, with substantial buffering overhead), and stability is often not needed.
>
>
>
The "full barrier operation" means that all the upstream operations must be performed before the downstream can start. There are only two full barrier operations in Stream API: `.sorted()` (every time) and `.distinct()` (in ordered parallel case). As you have non short-circuit infinite stream supplied to the `.distinct()` you end up with infinite loop. By contract `.distinct()` cannot just emit elements to the downstream in any order: it should always emit the first repeating element. While it's theoretically possible to implement parallel ordered `.distinct()` better, it would be much more complex implementation.
As for solution, @user140547 is right: add `.unordered()` before `.distinct()` this switches `distinct()` algorithm to unordered one (which just uses shared `ConcurrentHashMap` to store all the observed elements and emits every new element to the downstream). Note that adding `.unordered()` *after* `.distinct()` will not help. | This code has a major problem, even without the parallel:
After .distinct(), the stream will only have 2 elements- so the limit never kicks in- it will print the two elements and then continue wasting your CPU time indefinitely. This might have been what you intended though.
With parallel and limit, I believe the problem is exacerbated due to the way the work is divided. I haven't traced all the way through the parallel stream code, but here is my guess:
The parallel code divides the work between multiple threads, which all chug along indefinitely as they never fill their quota. The system probably waits for each thread to finish so it can combine their results to ensure distinctness in order- but this will never happen in the case you provide.
Without the order requirement, results from each worker thread can be immediately uses after being checked against a global distinctness set.
Without limit, I suspect that different code is used to handle infinite streams: instead of waiting for the required 10 to fill up, results are reported as discovered. Its a little like making an iterator that reports hasNext() = true, first produces 0, then 1, then the next() call hangs forever without producing a result- in the parallel case something is waiting for several reports so it can properly combine/order them before outputting, while in the serial case it does what it can then hangs.
Ill try to find the exact difference in call stack with and without distinct() or limit(), but so far it seems very difficult to navigate the rather complex stream library calling sequence. |
35,189,387 | Why the below code doesn't print any output whereas if we remove parallel, it prints 0, 1?
```
IntStream.iterate(0, i -> ( i + 1 ) % 2)
.parallel()
.distinct()
.limit(10)
.forEach(System.out::println);
```
Though I know ideally limit should be placed before distinct, but my question is more related with the difference caused by adding parallel processing. | 2016/02/03 | [
"https://Stackoverflow.com/questions/35189387",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2645833/"
] | The real cause is that *ordered parallel* `.distinct()` is the full barrier operation as [described](https://docs.oracle.com/javase/8/docs/api/java/util/stream/Stream.html#distinct--) in documentation:
>
> Preserving stability for `distinct()` in parallel pipelines is relatively expensive (requires that the operation act as a full barrier, with substantial buffering overhead), and stability is often not needed.
>
>
>
The "full barrier operation" means that all the upstream operations must be performed before the downstream can start. There are only two full barrier operations in Stream API: `.sorted()` (every time) and `.distinct()` (in ordered parallel case). As you have non short-circuit infinite stream supplied to the `.distinct()` you end up with infinite loop. By contract `.distinct()` cannot just emit elements to the downstream in any order: it should always emit the first repeating element. While it's theoretically possible to implement parallel ordered `.distinct()` better, it would be much more complex implementation.
As for solution, @user140547 is right: add `.unordered()` before `.distinct()` this switches `distinct()` algorithm to unordered one (which just uses shared `ConcurrentHashMap` to store all the observed elements and emits every new element to the downstream). Note that adding `.unordered()` *after* `.distinct()` will not help. | I know the code is not correct and as suggested in the solution too, if we move the limit before distinct, we won't have infinite loop.
Parallel function is using fork and join concept to allocate the work, which allocates all the available thread for the work, rather than single thread.
We are rightly expecting infinite loop, as multiple thread is infinitely processing a data and nothing stopping them, as the limit of 10 is never hitting after distinct.
It might be possible that it keeps trying to fork and never tries to join to move it forward. But still I believe its a defect in the java with more than anything else. |
13,182,664 | Currently I have a jqGrid in html. I am looking for a way to pull the data from the HTML elements, not from the jqGrid object, and put each column into an array. I've looked at a bunch of examples and been unable to find something that works the way I need it..
This is what I have currently. It pulls the jgGrid, which is a .d class and loads it into dTags. Then I grab the tableId and try and pull the row data(I actually need column data was just using for an example) and am having no luck. Any help would be much appreciated.
```
function generateXML()
{
// get class tags d, np, ch
var dTags = $(".d");
var npTags = $(".np");
var chTags = $(".ch");
for(var i = 0; i<dTags.size(); i++)
{
log(dTags.size());
var tableId = dTags[i].id;
var tableName = "#" + tableId + " td:nth-child(0)";
log(tableName);
var colArray = $(tableName).map(function(){
return $(this).text();
}).get();
log(JSON.stringify(colArray));
}
}
```
HTML - Looks like this
```
<table id="polarizationTable" class="d" ></table>
```
The html the jqGrid generates looks like this...
![table](https://i.stack.imgur.com/Y96YE.png)
and the code that generates that is..
```
<div class="ui-jqgrid ui-widget ui-widget-content ui-corner-all" id="gbox_polarizationTable" dir="ltr" style="width: 729px; "><div class="ui-widget-overlay jqgrid-overlay" id="lui_polarizationTable"></div><div class="loading ui-state-default ui-state-active" id="load_polarizationTable" style="display: none; ">Loading...</div><div class="ui-jqgrid-view" id="gview_polarizationTable" style="width: 729px; "><div class="ui-jqgrid-titlebar ui-widget-header ui-corner-top ui-helper-clearfix"><a role="link" href="javascript:void(0)" class="ui-jqgrid-titlebar-close HeaderButton" style="right: 0px; "><span class="ui-icon ui-icon-circle-triangle-n"></span></a><span class="ui-jqgrid-title">Polarization Table</span></div><div style="width: 729px; " class="ui-state-default ui-jqgrid-hdiv"><div class="ui-jqgrid-hbox"><table class="ui-jqgrid-htable" style="width: 711px; " role="grid" aria-labelledby="gbox_polarizationTable" cellspacing="0" cellpadding="0" border="0"><thead><tr class="ui-jqgrid-labels" role="rowheader"><th id="polarizationTable_TestTime" role="columnheader" class="ui-state-default ui-th-column ui-th-ltr" style="width: 97px; "><span class="ui-jqgrid-resize ui-jqgrid-resize-ltr" style="cursor: col-resize; "> </span><div id="jqgh_polarizationTable_TestTime" class="ui-jqgrid-sortable">Minutes<span class="s-ico" style="display:none"><span sort="asc" class="ui-grid-ico-sort ui-icon-asc ui-state-disabled ui-icon ui-icon-triangle-1-n ui-sort-ltr"></span><span sort="desc" class="ui-grid-ico-sort ui-icon-desc ui-state-disabled ui-icon ui-icon-triangle-1-s ui-sort-ltr"></span></span></div></th><th id="polarizationTable_RdgA" role="columnheader" class="ui-state-default ui-th-column ui-th-ltr" style="width: 97px; "><span class="ui-jqgrid-resize ui-jqgrid-resize-ltr" style="cursor: col-resize; "> </span><div id="jqgh_polarizationTable_RdgA" class="ui-jqgrid-sortable">Reading A<span class="s-ico" style="display:none"><span sort="asc" class="ui-grid-ico-sort ui-icon-asc ui-state-disabled ui-icon ui-icon-triangle-1-n ui-sort-ltr"></span><span sort="desc" class="ui-grid-ico-sort ui-icon-desc ui-state-disabled ui-icon ui-icon-triangle-1-s ui-sort-ltr"></span></span></div></th><th id="polarizationTable_CorrA" role="columnheader" class="ui-state-default ui-th-column ui-th-ltr" style="width: 97px; "><span class="ui-jqgrid-resize ui-jqgrid-resize-ltr" style="cursor: col-resize; "> </span><div id="jqgh_polarizationTable_CorrA" class="ui-jqgrid-sortable">Corr A<span class="s-ico" style="display:none"><span sort="asc" class="ui-grid-ico-sort ui-icon-asc ui-state-disabled ui-icon ui-icon-triangle-1-n ui-sort-ltr"></span><span sort="desc" class="ui-grid-ico-sort ui-icon-desc ui-state-disabled ui-icon ui-icon-triangle-1-s ui-sort-ltr"></span></span></div></th><th id="polarizationTable_RdgB" role="columnheader" class="ui-state-default ui-th-column ui-th-ltr" style="width: 97px; "><span class="ui-jqgrid-resize ui-jqgrid-resize-ltr" style="cursor: col-resize; "> </span><div id="jqgh_polarizationTable_RdgB" class="ui-jqgrid-sortable">Reading B<span class="s-ico" style="display:none"><span sort="asc" class="ui-grid-ico-sort ui-icon-asc ui-state-disabled ui-icon ui-icon-triangle-1-n ui-sort-ltr"></span><span sort="desc" class="ui-grid-ico-sort ui-icon-desc ui-state-disabled ui-icon ui-icon-triangle-1-s ui-sort-ltr"></span></span></div></th><th id="polarizationTable_CorrB" role="columnheader" class="ui-state-default ui-th-column ui-th-ltr" style="width: 97px; "><span class="ui-jqgrid-resize ui-jqgrid-resize-ltr" style="cursor: col-resize; "> </span><div id="jqgh_polarizationTable_CorrB" class="ui-jqgrid-sortable">Corr B<span class="s-ico" style="display:none"><span sort="asc" class="ui-grid-ico-sort ui-icon-asc ui-state-disabled ui-icon ui-icon-triangle-1-n ui-sort-ltr"></span><span sort="desc" class="ui-grid-ico-sort ui-icon-desc ui-state-disabled ui-icon ui-icon-triangle-1-s ui-sort-ltr"></span></span></div></th><th id="polarizationTable_RdgC" role="columnheader" class="ui-state-default ui-th-column ui-th-ltr" style="width: 97px; "><span class="ui-jqgrid-resize ui-jqgrid-resize-ltr" style="cursor: col-resize; "> </span><div id="jqgh_polarizationTable_RdgC" class="ui-jqgrid-sortable">Reading C<span class="s-ico" style="display:none"><span sort="asc" class="ui-grid-ico-sort ui-icon-asc ui-state-disabled ui-icon ui-icon-triangle-1-n ui-sort-ltr"></span><span sort="desc" class="ui-grid-ico-sort ui-icon-desc ui-state-disabled ui-icon ui-icon-triangle-1-s ui-sort-ltr"></span></span></div></th><th id="polarizationTable_CorrC" role="columnheader" class="ui-state-default ui-th-column ui-th-ltr" style="width: 94px; "><span class="ui-jqgrid-resize ui-jqgrid-resize-ltr" style="cursor: col-resize; "> </span><div id="jqgh_polarizationTable_CorrC" class="ui-jqgrid-sortable">Corr C<span class="s-ico" style="display:none"><span sort="asc" class="ui-grid-ico-sort ui-icon-asc ui-state-disabled ui-icon ui-icon-triangle-1-n ui-sort-ltr"></span><span sort="desc" class="ui-grid-ico-sort ui-icon-desc ui-state-disabled ui-icon ui-icon-triangle-1-s ui-sort-ltr"></span></span></div></th></tr></thead></table></div></div><div class="ui-jqgrid-bdiv" style="height: 250px; width: 729px; "><div style="position:relative;"><div></div><table id="polarizationTable" class="d ui-jqgrid-btable" tabindex="1" cellspacing="0" cellpadding="0" border="0" role="grid" aria-multiselectable="false" aria-labelledby="gbox_polarizationTable" style="width: 711px; "><tbody><tr class="jqgfirstrow" role="row" style="height:auto"><td role="gridcell" style="height: 0px; width: 97px; "></td><td role="gridcell" style="height: 0px; width: 97px; "></td><td role="gridcell" style="height: 0px; width: 97px; "></td><td role="gridcell" style="height: 0px; width: 97px; "></td><td role="gridcell" style="height: 0px; width: 97px; "></td><td role="gridcell" style="height: 0px; width: 97px; "></td><td role="gridcell" style="height: 0px; width: 94px; "></td></tr><tr role="row" id="1" tabindex="0" class="ui-widget-content jqgrow ui-row-ltr ui-state-highlight" aria-selected="true"><td role="gridcell" style="text-align:center;" title="0.25" aria-describedby="polarizationTable_TestTime">0.25</td><td role="gridcell" style="text-align:center;" title="" aria-describedby="polarizationTable_RdgA"> </td><td role="gridcell" style="text-align:center;" title="" aria-describedby="polarizationTable_CorrA"> </td><td role="gridcell" style="text-align:center;" title="" aria-describedby="polarizationTable_RdgB"> </td><td role="gridcell" style="text-align:center;" title="" aria-describedby="polarizationTable_CorrB"> </td><td role="gridcell" style="text-align:center;" title="" aria-describedby="polarizationTable_RdgC"> </td><td role="gridcell" style="text-align:center;" title="" aria-describedby="polarizationTable_CorrC"> </td></tr><tr role="row" id="2" tabindex="-1" class="ui-widget-content jqgrow ui-row-ltr"><td role="gridcell" style="text-align:center;" title="0.5" aria-describedby="polarizationTable_TestTime">0.5</td><td role="gridcell" style="text-align:center;" title="" aria-describedby="polarizationTable_RdgA"> </td><td role="gridcell" style="text-align:center;" title="" aria-describedby="polarizationTable_CorrA"> </td><td role="gridcell" style="text-align:center;" title="" aria-describedby="polarizationTable_RdgB"> </td><td role="gridcell" style="text-align:center;" title="" aria-describedby="polarizationTable_CorrB"> </td><td role="gridcell" style="text-align:center;" title="" aria-describedby="polarizationTable_RdgC"> </td><td role="gridcell" style="text-align:center;" title="" aria-describedby="polarizationTable_CorrC"> </td></tr><tr role="row" id="3" tabindex="-1" class="ui-widget-content jqgrow ui-row-ltr"><td role="gridcell" style="text-align:center;" title="0.75" aria-describedby="polarizationTable_TestTime">0.75</td><td role="gridcell" style="text-align:center;" title="" aria-describedby="polarizationTable_RdgA"> </td><td role="gridcell" style="text-align:center;" title="" aria-describedby="polarizationTable_CorrA"> </td><td role="gridcell" style="text-align:center;" title="" aria-describedby="polarizationTable_RdgB"> </td><td role="gridcell" style="text-align:center;" title="" aria-describedby="polarizationTable_CorrB"> </td><td role="gridcell" style="text-align:center;" title="" aria-describedby="polarizationTable_RdgC"> </td><td role="gridcell" style="text-align:center;" title="" aria-describedby="polarizationTable_CorrC"> </td></tr><tr role="row" id="4" tabindex="-1" class="ui-widget-content jqgrow ui-row-ltr"><td role="gridcell" style="text-align:center;" title="1" aria-describedby="polarizationTable_TestTime">1</td><td role="gridcell" style="text-align:center;" title="" aria-describedby="polarizationTable_RdgA"> </td><td role="gridcell" style="text-align:center;" title="" aria-describedby="polarizationTable_CorrA"> </td><td role="gridcell" style="text-align:center;" title="" aria-describedby="polarizationTable_RdgB"> </td><td role="gridcell" style="text-align:center;" title="" aria-describedby="polarizationTable_CorrB"> </td><td role="gridcell" style="text-align:center;" title="" aria-describedby="polarizationTable_RdgC"> </td><td role="gridcell" style="text-align:center;" title="" aria-describedby="polarizationTable_CorrC"> </td></tr><tr role="row" id="5" tabindex="-1" class="ui-widget-content jqgrow ui-row-ltr"><td role="gridcell" style="text-align:center;" title="2" aria-describedby="polarizationTable_TestTime">2</td><td role="gridcell" style="text-align:center;" title="" aria-describedby="polarizationTable_RdgA"> </td><td role="gridcell" style="text-align:center;" title="" aria-describedby="polarizationTable_CorrA"> </td><td role="gridcell" style="text-align:center;" title="" aria-describedby="polarizationTable_RdgB"> </td><td role="gridcell" style="text-align:center;" title="" aria-describedby="polarizationTable_CorrB"> </td><td role="gridcell" style="text-align:center;" title="" aria-describedby="polarizationTable_RdgC"> </td><td role="gridcell" style="text-align:center;" title="" aria-describedby="polarizationTable_CorrC"> </td></tr><tr role="row" id="6" tabindex="-1" class="ui-widget-content jqgrow ui-row-ltr"><td role="gridcell" style="text-align:center;" title="3" aria-describedby="polarizationTable_TestTime">3</td><td role="gridcell" style="text-align:center;" title="" aria-describedby="polarizationTable_RdgA"> </td><td role="gridcell" style="text-align:center;" title="" aria-describedby="polarizationTable_CorrA"> </td><td role="gridcell" style="text-align:center;" title="" aria-describedby="polarizationTable_RdgB"> </td><td role="gridcell" style="text-align:center;" title="" aria-describedby="polarizationTable_CorrB"> </td><td role="gridcell" style="text-align:center;" title="" aria-describedby="polarizationTable_RdgC"> </td><td role="gridcell" style="text-align:center;" title="" aria-describedby="polarizationTable_CorrC"> </td></tr><tr role="row" id="7" tabindex="-1" class="ui-widget-content jqgrow ui-row-ltr"><td role="gridcell" style="text-align:center;" title="4" aria-describedby="polarizationTable_TestTime">4</td><td role="gridcell" style="text-align:center;" title="" aria-describedby="polarizationTable_RdgA"> </td><td role="gridcell" style="text-align:center;" title="" aria-describedby="polarizationTable_CorrA"> </td><td role="gridcell" style="text-align:center;" title="" aria-describedby="polarizationTable_RdgB"> </td><td role="gridcell" style="text-align:center;" title="" aria-describedby="polarizationTable_CorrB"> </td><td role="gridcell" style="text-align:center;" title="" aria-describedby="polarizationTable_RdgC"> </td><td role="gridcell" style="text-align:center;" title="" aria-describedby="polarizationTable_CorrC"> </td></tr><tr role="row" id="8" tabindex="-1" class="ui-widget-content jqgrow ui-row-ltr"><td role="gridcell" style="text-align:center;" title="5" aria-describedby="polarizationTable_TestTime">5</td><td role="gridcell" style="text-align:center;" title="" aria-describedby="polarizationTable_RdgA"> </td><td role="gridcell" style="text-align:center;" title="" aria-describedby="polarizationTable_CorrA"> </td><td role="gridcell" style="text-align:center;" title="" aria-describedby="polarizationTable_RdgB"> </td><td role="gridcell" style="text-align:center;" title="" aria-describedby="polarizationTable_CorrB"> </td><td role="gridcell" style="text-align:center;" title="" aria-describedby="polarizationTable_RdgC"> </td><td role="gridcell" style="text-align:center;" title="" aria-describedby="polarizationTable_CorrC"> </td></tr><tr role="row" id="9" tabindex="-1" class="ui-widget-content jqgrow ui-row-ltr"><td role="gridcell" style="text-align:center;" title="6" aria-describedby="polarizationTable_TestTime">6</td><td role="gridcell" style="text-align:center;" title="" aria-describedby="polarizationTable_RdgA"> </td><td role="gridcell" style="text-align:center;" title="" aria-describedby="polarizationTable_CorrA"> </td><td role="gridcell" style="text-align:center;" title="" aria-describedby="polarizationTable_RdgB"> </td><td role="gridcell" style="text-align:center;" title="" aria-describedby="polarizationTable_CorrB"> </td><td role="gridcell" style="text-align:center;" title="" aria-describedby="polarizationTable_RdgC"> </td><td role="gridcell" style="text-align:center;" title="" aria-describedby="polarizationTable_CorrC"> </td></tr><tr role="row" id="10" tabindex="-1" class="ui-widget-content jqgrow ui-row-ltr"><td role="gridcell" style="text-align:center;" title="7" aria-describedby="polarizationTable_TestTime">7</td><td role="gridcell" style="text-align:center;" title="" aria-describedby="polarizationTable_RdgA"> </td><td role="gridcell" style="text-align:center;" title="" aria-describedby="polarizationTable_CorrA"> </td><td role="gridcell" style="text-align:center;" title="" aria-describedby="polarizationTable_RdgB"> </td><td role="gridcell" style="text-align:center;" title="" aria-describedby="polarizationTable_CorrB"> </td><td role="gridcell" style="text-align:center;" title="" aria-describedby="polarizationTable_RdgC"> </td><td role="gridcell" style="text-align:center;" title="" aria-describedby="polarizationTable_CorrC"> </td></tr><tr role="row" id="11" tabindex="-1" class="ui-widget-content jqgrow ui-row-ltr"><td role="gridcell" style="text-align:center;" title="8" aria-describedby="polarizationTable_TestTime">8</td><td role="gridcell" style="text-align:center;" title="" aria-describedby="polarizationTable_RdgA"> </td><td role="gridcell" style="text-align:center;" title="" aria-describedby="polarizationTable_CorrA"> </td><td role="gridcell" style="text-align:center;" title="" aria-describedby="polarizationTable_RdgB"> </td><td role="gridcell" style="text-align:center;" title="" aria-describedby="polarizationTable_CorrB"> </td><td role="gridcell" style="text-align:center;" title="" aria-describedby="polarizationTable_RdgC"> </td><td role="gridcell" style="text-align:center;" title="" aria-describedby="polarizationTable_CorrC"> </td></tr><tr role="row" id="12" tabindex="-1" class="ui-widget-content jqgrow ui-row-ltr"><td role="gridcell" style="text-align:center;" title="9" aria-describedby="polarizationTable_TestTime">9</td><td role="gridcell" style="text-align:center;" title="" aria-describedby="polarizationTable_RdgA"> </td><td role="gridcell" style="text-align:center;" title="" aria-describedby="polarizationTable_CorrA"> </td><td role="gridcell" style="text-align:center;" title="" aria-describedby="polarizationTable_RdgB"> </td><td role="gridcell" style="text-align:center;" title="" aria-describedby="polarizationTable_CorrB"> </td><td role="gridcell" style="text-align:center;" title="" aria-describedby="polarizationTable_RdgC"> </td><td role="gridcell" style="text-align:center;" title="" aria-describedby="polarizationTable_CorrC"> </td></tr><tr role="row" id="13" tabindex="-1" class="ui-widget-content jqgrow ui-row-ltr"><td role="gridcell" style="text-align:center;" title="10" aria-describedby="polarizationTable_TestTime">10</td><td role="gridcell" style="text-align:center;" title="" aria-describedby="polarizationTable_RdgA"> </td><td role="gridcell" style="text-align:center;" title="" aria-describedby="polarizationTable_CorrA"> </td><td role="gridcell" style="text-align:center;" title="" aria-describedby="polarizationTable_RdgB"> </td><td role="gridcell" style="text-align:center;" title="" aria-describedby="polarizationTable_CorrB"> </td><td role="gridcell" style="text-align:center;" title="" aria-describedby="polarizationTable_RdgC"> </td><td role="gridcell" style="text-align:center;" title="" aria-describedby="polarizationTable_CorrC"> </td></tr></tbody></table></div></div></div><div class="ui-jqgrid-resize-mark" id="rs_mpolarizationTable"> </div></div>
```
Essentially I need the data from Minutes, Reading A, Corr A, etc.. into respective arrays... later down the road I will be building an custom XML file from this data. Hope this clears things up a bit. | 2012/11/01 | [
"https://Stackoverflow.com/questions/13182664",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1688975/"
] | You can use `:nth-child` and the `.map()` function:
```
var minutes = jQuery('.ui-jqgrid-bdiv tr.ui-widget-content td:nth-child(1)')
.map(function(){
return $(this).html();
});
var readingA = jQuery('.ui-jqgrid-bdiv tr.ui-widget-content td:nth-child(2)')
.map(function(){
return $(this).html();
});
/// and so on...
```
With a little bit of work you could wrap this in a `.each()` handler to step each column name programmatically, rather than manually specifying them all. | It's not quite clear what you want to do, but at the first look you can just use [getCol](http://www.trirand.com/jqgridwiki/doku.php?id=wiki%3amethods) method of jqGrid instead of your current code. |
4,340,016 | I am asked to provide two random variables, $X=(X\_1,X\_2)$ and $Y = (Y\_1, Y\_2),$ taking values in $\mathbb{N\_{0}}^2,$ such that $X\_1, Y\_1$ and $X\_2, Y\_2$, respectively, have the same distribution but $X$ and $Y$ don't.
Let's suppose $X\_1, Y\_1$ have the Poisson distribution and let's say $X\_2, Y\_2$ the uniform one. It is unclear to my, why $X, Y$ would not necessarily have the same distribution. Can somebody provide an example of a bivariate random variable satisfying the required property ?
Thanks. | 2021/12/22 | [
"https://math.stackexchange.com/questions/4340016",
"https://math.stackexchange.com",
"https://math.stackexchange.com/users/996159/"
] | All four variables have the same distribution. $X\_1$ independent of $X\_2$ while $Y\_1=Y\_2$. | To make this more concrete. $X\_{1}$ is the red die; $X\_{2}$ is the blue
die; $Y\_{1}$ is the green die and $Y\_{2}$ is the same throw of the green die
as $Y\_{1}$. |
18,774,863 | What does PHP syntax `$var1[] = $var2` mean?
Note the `[]` after `$var1` varable. | 2013/09/12 | [
"https://Stackoverflow.com/questions/18774863",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1163755/"
] | It means that `$var1` is an array, and this syntax means you are inserting `$var2` into a new element at the end of the array.
So if your array had 2 elements before, like this:
```
$var1=( 1 => 3, 2 => 4)
```
and the value of $var2 was 5, it would not look like this:
```
$var1=( 1 => 3, 2 => 4, 3 => 5)
```
It also means that if $var2 was an array itself, you have just created a two dimensional array. Assuming the following:
```
$var1=( 1 => 3, 2 => 4)
$var2=( 1 => 10, 2=>20)
```
doing a `$var1[]=$var2;` wouls result in an array like this:
```
$var1=( 1 => 3, 2 => 4, 3 => (1 =>10, 2 => 20))
```
As an aside, if you haven't used multi-dimensional arrays yet, accessing the data is quite simple. If I wanted to use the value 20 from our new array, I could do it in this manner:
```
echo $var1[3][2];
```
Note the second set of square brackets - basically you are saying I want to access element two of the array inside element 3 of the $var1 array.
On that note, there is one thing to be aware of. If you are working with multi-dimensional arrays, this syntax can catch you out inside a loop structure of some sort. Lets say you have a two dimensional array where you store some records and want to get more from the database:
```
$var1 = (
1 => (id =>1, age => 25, posts => 40),
2 => (id =>2, age => 29, posts => 140),
3 => (id =>3, age => 32, posts => 12)
)
```
A loop like this following:
```
while($row=someDatabaseRow)
{
$var1[]=$row['id']; // value 4
$var1[]=$row['age']; // value 21
$var1[]=$row['posts']; // value 34
}
```
will infact insert a new element for every execution, hence your array would end up looking like this:
```
$var1 = (
1 => (id =>1, age => 25, posts => 40),
2 => (id =>2, age => 29, posts => 140),
3 => (id =>3, age => 32, posts => 12),
4 => 4,
5 => 21,
6 => 34
)
```
The correct way would be to assemble the array first, then append it to your current array to maintain the strucutre, like this:
```
while($row=someDatabaseRow)
{
$tempArr= array();
$tempArr[]=$row['id']; // value 4
$tempArr[]=$row['age']; // value 21
$tempArr[]=$row['posts']; // value 34
$var1[]=$tempArr;
}
```
Now your array would look like you expected, namely:
```
$var1 = (
1 => (id =>1, age => 25, posts => 40),
2 => (id =>2, age => 29, posts => 140),
3 => (id =>3, age => 32, posts => 12)
4 => (id =>4, age => 21, posts => 34)
)
``` | It means that you're pushing the value of `var2` to array `var1`. |
18,774,863 | What does PHP syntax `$var1[] = $var2` mean?
Note the `[]` after `$var1` varable. | 2013/09/12 | [
"https://Stackoverflow.com/questions/18774863",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1163755/"
] | It means that you're pushing the value of `var2` to array `var1`. | It basically makes $var1 an array and adding to it's end a value of $var2.
```
$var1 = NULL;
$var2 = 'abc';
$var1[] = $var2;
```
$var1 is now an array containing one value: 'abc' |
18,774,863 | What does PHP syntax `$var1[] = $var2` mean?
Note the `[]` after `$var1` varable. | 2013/09/12 | [
"https://Stackoverflow.com/questions/18774863",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1163755/"
] | It means that `$var1` is an array, and this syntax means you are inserting `$var2` into a new element at the end of the array.
So if your array had 2 elements before, like this:
```
$var1=( 1 => 3, 2 => 4)
```
and the value of $var2 was 5, it would not look like this:
```
$var1=( 1 => 3, 2 => 4, 3 => 5)
```
It also means that if $var2 was an array itself, you have just created a two dimensional array. Assuming the following:
```
$var1=( 1 => 3, 2 => 4)
$var2=( 1 => 10, 2=>20)
```
doing a `$var1[]=$var2;` wouls result in an array like this:
```
$var1=( 1 => 3, 2 => 4, 3 => (1 =>10, 2 => 20))
```
As an aside, if you haven't used multi-dimensional arrays yet, accessing the data is quite simple. If I wanted to use the value 20 from our new array, I could do it in this manner:
```
echo $var1[3][2];
```
Note the second set of square brackets - basically you are saying I want to access element two of the array inside element 3 of the $var1 array.
On that note, there is one thing to be aware of. If you are working with multi-dimensional arrays, this syntax can catch you out inside a loop structure of some sort. Lets say you have a two dimensional array where you store some records and want to get more from the database:
```
$var1 = (
1 => (id =>1, age => 25, posts => 40),
2 => (id =>2, age => 29, posts => 140),
3 => (id =>3, age => 32, posts => 12)
)
```
A loop like this following:
```
while($row=someDatabaseRow)
{
$var1[]=$row['id']; // value 4
$var1[]=$row['age']; // value 21
$var1[]=$row['posts']; // value 34
}
```
will infact insert a new element for every execution, hence your array would end up looking like this:
```
$var1 = (
1 => (id =>1, age => 25, posts => 40),
2 => (id =>2, age => 29, posts => 140),
3 => (id =>3, age => 32, posts => 12),
4 => 4,
5 => 21,
6 => 34
)
```
The correct way would be to assemble the array first, then append it to your current array to maintain the strucutre, like this:
```
while($row=someDatabaseRow)
{
$tempArr= array();
$tempArr[]=$row['id']; // value 4
$tempArr[]=$row['age']; // value 21
$tempArr[]=$row['posts']; // value 34
$var1[]=$tempArr;
}
```
Now your array would look like you expected, namely:
```
$var1 = (
1 => (id =>1, age => 25, posts => 40),
2 => (id =>2, age => 29, posts => 140),
3 => (id =>3, age => 32, posts => 12)
4 => (id =>4, age => 21, posts => 34)
)
``` | That's shorthand for [`array_push()`](http://php.net/manual/en/function.array-push.php)
It will make `$var1` and array (if it isn't already) and push `$var2` in to it. |
18,774,863 | What does PHP syntax `$var1[] = $var2` mean?
Note the `[]` after `$var1` varable. | 2013/09/12 | [
"https://Stackoverflow.com/questions/18774863",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1163755/"
] | That's shorthand for [`array_push()`](http://php.net/manual/en/function.array-push.php)
It will make `$var1` and array (if it isn't already) and push `$var2` in to it. | It basically makes $var1 an array and adding to it's end a value of $var2.
```
$var1 = NULL;
$var2 = 'abc';
$var1[] = $var2;
```
$var1 is now an array containing one value: 'abc' |
18,774,863 | What does PHP syntax `$var1[] = $var2` mean?
Note the `[]` after `$var1` varable. | 2013/09/12 | [
"https://Stackoverflow.com/questions/18774863",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1163755/"
] | It means that `$var1` is an array, and this syntax means you are inserting `$var2` into a new element at the end of the array.
So if your array had 2 elements before, like this:
```
$var1=( 1 => 3, 2 => 4)
```
and the value of $var2 was 5, it would not look like this:
```
$var1=( 1 => 3, 2 => 4, 3 => 5)
```
It also means that if $var2 was an array itself, you have just created a two dimensional array. Assuming the following:
```
$var1=( 1 => 3, 2 => 4)
$var2=( 1 => 10, 2=>20)
```
doing a `$var1[]=$var2;` wouls result in an array like this:
```
$var1=( 1 => 3, 2 => 4, 3 => (1 =>10, 2 => 20))
```
As an aside, if you haven't used multi-dimensional arrays yet, accessing the data is quite simple. If I wanted to use the value 20 from our new array, I could do it in this manner:
```
echo $var1[3][2];
```
Note the second set of square brackets - basically you are saying I want to access element two of the array inside element 3 of the $var1 array.
On that note, there is one thing to be aware of. If you are working with multi-dimensional arrays, this syntax can catch you out inside a loop structure of some sort. Lets say you have a two dimensional array where you store some records and want to get more from the database:
```
$var1 = (
1 => (id =>1, age => 25, posts => 40),
2 => (id =>2, age => 29, posts => 140),
3 => (id =>3, age => 32, posts => 12)
)
```
A loop like this following:
```
while($row=someDatabaseRow)
{
$var1[]=$row['id']; // value 4
$var1[]=$row['age']; // value 21
$var1[]=$row['posts']; // value 34
}
```
will infact insert a new element for every execution, hence your array would end up looking like this:
```
$var1 = (
1 => (id =>1, age => 25, posts => 40),
2 => (id =>2, age => 29, posts => 140),
3 => (id =>3, age => 32, posts => 12),
4 => 4,
5 => 21,
6 => 34
)
```
The correct way would be to assemble the array first, then append it to your current array to maintain the strucutre, like this:
```
while($row=someDatabaseRow)
{
$tempArr= array();
$tempArr[]=$row['id']; // value 4
$tempArr[]=$row['age']; // value 21
$tempArr[]=$row['posts']; // value 34
$var1[]=$tempArr;
}
```
Now your array would look like you expected, namely:
```
$var1 = (
1 => (id =>1, age => 25, posts => 40),
2 => (id =>2, age => 29, posts => 140),
3 => (id =>3, age => 32, posts => 12)
4 => (id =>4, age => 21, posts => 34)
)
``` | It basically makes $var1 an array and adding to it's end a value of $var2.
```
$var1 = NULL;
$var2 = 'abc';
$var1[] = $var2;
```
$var1 is now an array containing one value: 'abc' |
181,657 | I applied for PhD at some top US universities (Electrical & Computer Engineering dept).
I received an email from a professor at one of the places, about a position in his group, to work on a very specific topic. If I am interested, an interview could be set up to discuss things further.
However, I am not interested in this topic at all. From the email, it is clear that funding is available only for this topic.
**Question**: If I reject this offer, does it hurt my chances of getting admitted by a different faculty member at the same department?
My question is based on the following assumption: Faculty members *sit together* and pick a few candidates each, from the pool of applicants. The faculty member who contacted me had picked me. Therefore, if I reject his offer, I would not be considered by the other faculty members, because they have already picked other candidates.
Is this how it usually works? | 2022/01/27 | [
"https://academia.stackexchange.com/questions/181657",
"https://academia.stackexchange.com",
"https://academia.stackexchange.com/users/66924/"
] | >
> My question is based on the following assumption: Faculty members sit together and pick a few candidates each, from the pool of applicants. The faculty member who contacted me had picked me.
>
>
>
As Buffy said, in the US, candidates are normally chosen by committee, and there is no one-to-one matching between students and advisors. This is different than the situation in Europe.
>
> Therefore, if I reject his offer, I would not be considered by the other faculty members, because they have already picked other candidates.
>
>
>
Things will vary widely across academia, so it is hard to give general advice (and I'm not familiar with EECE departments, so take my advice for what it's worth). But the committee does generally try to ensure some rough alignment between the students' interests and the department's needs. It could be that the department is only interested in you because you seem like a good match to this project / advisor, and so declining this project would probably result in your not being admitted. Or it could be that they really like you and are offering you this opportunity on top of a forthcoming admissions offer. It is really impossible to say what they might be thinking, but it's certainly *possible* that rejecting this offer could reduce your odds of admission.
>
> If I am interested, an interview could be set up to discuss things further. However, I am not interested in this topic at all.
>
>
>
Still, I'm not sure any of this matters. You are not interested in the project, and getting an offer of admission based on your willingness to work on this odious project would not be very useful. So, I recommend being straightforward with them: perhaps you are willing to meet with the professor and discuss further, but your initial reaction is that the project doesn't seem like a strong match to your skills or interests. If this means they don't admit you, that's better than getting admitted but not being able to find a suitable advisor once you're there.
By the way, you might want to keep an open mind with respect to the project. Sometimes working on a less interesting project with an awesome advisor is worth it. And sometimes apparently uninteresting projects turn out to be connected to things you are interested in. | It seems unlikely that it would hurt you generally and if the professor had such an attitude that it would, you'd be in trouble there anyway. Someone would need an especially vindictive personality to behave like that.
Most US doctoral admissions is handled by a committee and most students start with no thesis advisor. Funding is also normally through TA positions. So, I think the one opportunity may have been special. The funding available from the professor was most likely via a grant for a specific project. And, you might still be subject to decisions of a committee even if you wanted to accept. Professors aren't normally "officers of the university" with power to act on their own.
It isn't normally like your supposed scenario. An admissions committee will be composed of a few professors from a much larger number. Sometimes it is given as a "reward" to people recently tenured.
For more on how admissions works in the US, see the answer for the US here: [How does the admissions process work for Ph.D. programs in Country X?](https://academia.stackexchange.com/q/176908/75368)
---
For completeness, there are a few departments at a few universities in US that use a different system. |
181,657 | I applied for PhD at some top US universities (Electrical & Computer Engineering dept).
I received an email from a professor at one of the places, about a position in his group, to work on a very specific topic. If I am interested, an interview could be set up to discuss things further.
However, I am not interested in this topic at all. From the email, it is clear that funding is available only for this topic.
**Question**: If I reject this offer, does it hurt my chances of getting admitted by a different faculty member at the same department?
My question is based on the following assumption: Faculty members *sit together* and pick a few candidates each, from the pool of applicants. The faculty member who contacted me had picked me. Therefore, if I reject his offer, I would not be considered by the other faculty members, because they have already picked other candidates.
Is this how it usually works? | 2022/01/27 | [
"https://academia.stackexchange.com/questions/181657",
"https://academia.stackexchange.com",
"https://academia.stackexchange.com/users/66924/"
] | >
> My question is based on the following assumption: Faculty members sit together and pick a few candidates each, from the pool of applicants. The faculty member who contacted me had picked me.
>
>
>
As Buffy said, in the US, candidates are normally chosen by committee, and there is no one-to-one matching between students and advisors. This is different than the situation in Europe.
>
> Therefore, if I reject his offer, I would not be considered by the other faculty members, because they have already picked other candidates.
>
>
>
Things will vary widely across academia, so it is hard to give general advice (and I'm not familiar with EECE departments, so take my advice for what it's worth). But the committee does generally try to ensure some rough alignment between the students' interests and the department's needs. It could be that the department is only interested in you because you seem like a good match to this project / advisor, and so declining this project would probably result in your not being admitted. Or it could be that they really like you and are offering you this opportunity on top of a forthcoming admissions offer. It is really impossible to say what they might be thinking, but it's certainly *possible* that rejecting this offer could reduce your odds of admission.
>
> If I am interested, an interview could be set up to discuss things further. However, I am not interested in this topic at all.
>
>
>
Still, I'm not sure any of this matters. You are not interested in the project, and getting an offer of admission based on your willingness to work on this odious project would not be very useful. So, I recommend being straightforward with them: perhaps you are willing to meet with the professor and discuss further, but your initial reaction is that the project doesn't seem like a strong match to your skills or interests. If this means they don't admit you, that's better than getting admitted but not being able to find a suitable advisor once you're there.
By the way, you might want to keep an open mind with respect to the project. Sometimes working on a less interesting project with an awesome advisor is worth it. And sometimes apparently uninteresting projects turn out to be connected to things you are interested in. | I am currently a professor at a US university. After reading Buffy's and cag51's responses, I want to clarify that this:
>
> Most US doctoral admissions is handled by a committee and most
> students start with no thesis advisor. Funding is also normally
> through TA positions. So, I think the one opportunity may have been
> special. The funding available from the professor was most likely via
> a grant for a specific project. And, you might still be subject to
> decisions of a committee even if you wanted to accept. Professors
> aren't normally "officers of the university" with power to act on
> their own.
>
>
>
is not universally true. It is certainly true in some places. However, I have worked at 2 R1 universities and in both cases, the committee part of admissions decisions is more of a quality check. At both universities, faculty identify and request to admit a particular set of students to work in their lab and with the understanding that they will be the primary advisors. Students are admitted with this understanding.
Whether this would affect later applications to faculty positions...I would say that it is unlikely, but not impossible. As Buffy suggested, one route to retaliation would be a vindictive person. This is possible, but faculty positions are committee decisions in pretty much all cases Any objection of a candidate would have to be justified and the others on the committee would have to agree. This scenario you're concerned about is thus *possible*, but super unlikely. In most cases, having wanted to admit a grad student, missing out, and then having them apply later as a strong faculty candidate would probably bias me *towards*, rather than away from admitting them. I would ethically have to suppress that tendency, however.
Bottom line, your instinct is right. Go to the program/advisor that fits your interests most closely. Grad school can be pretty fun if you're doing something you're really passionate about and pretty awful if you're doing something you hate. |
28,852,008 | If I have this string given by a ffmpeg command when you try to get information about a video:
>
> Copyright (c) 2000-2015 the FFmpeg developers built with gcc 4.4.7
> (GCC) 20120313 (Red Hat 4.4.7-11) configuration:
> --prefix=/usr/local/cpffmpeg --enable-shared --enable-nonfree --enable-gpl --enable-pthreads --enable-libopencore-amrnb --enable-decoder=liba52 --enable-libopencore-amrwb --enable-libfaac --enable-libmp3lame --enable-libtheora --enable-libvorbis --enable-libx264 --enable-libxvid --extra-cflags=-I/usr/local/cpffmpeg/include/ --extra-ldflags=-L/usr/local/cpffmpeg/lib --enable-version3 --extra-version=syslint libavutil 54. 19.100 / 54. 19.100 libavcodec 56. 26.100 / 56. 26.100 libavformat 56. 23.106 / 56. 23.106 libavdevice 56. 4.100 / 56. 4.100 libavfilter 5. 11.102 / 5. 11.102
> libswscale 3. 1.101 / 3. 1.101 libswresample 1. 1.100 / 1. 1.100
> libpostproc 53. 3.100 / 53. 3.100Input #0, mov,mp4,m4a,3gp,3g2,mj2,
> from '/var/zpanel/hostdata/zadmin/public\_html/chandelier.mp4':
> Metadata: major\_brand : isom minor\_version : 512 compatible\_brands:
> isomiso2avc1mp41 URL : Follow Me On > www.hamhame1.in compilation : 0
> title : Follow Me On > www.hamhame1.in artist : Follow Me On >
> www.hamhame1.in album : Follow Me On > www.hamhame1.in date : Follow
> Me On > www.hamhame1.in genre : Follow Me On > www.hamhame1.in comment
> : Follow Me On > www.hamhame1.in composer : Follow Me On >
> www.hamhame1.in original\_artist : Follow Me On > www.hamhame1.in
> copyright : Follow Me On > www.hamhame1.in encoder : Follow Me On >
> www.hamhame1.in album\_artist : Follow Me On > www.hamhame1.in
> season\_number : 0 episode\_sort : 0 track : 0 disc : 0 media\_type : 0
> Duration: 00:03:51.35, start: 0.000000, bitrate: 2778 kb/s Stream
> 0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, **1920x1080** [SAR 1:1 > DAR 16:9], 2646 kb/s, 23.98 fps, 23.98 tbr, 90k tbn, 47.95
> tbc (default) Metadata: handler\_name : VideoHandler Stream #0:1(und):
> Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 125 kb/s
> (default) Metadata: handler\_name : SoundHandlerAt least one output
> file must be specified
>
>
>
In this case video dimension is: 1920x1080
How can I export video dimension knowing that yuv420p and [SAR 1:1 > DAR 16:9] might be different (and also that. 1920x1080 could be 402x250 or 24x59). I'm not really interested in using third-party classes. | 2015/03/04 | [
"https://Stackoverflow.com/questions/28852008",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2922834/"
] | Try this regex:
```
(\b[^0]\d+x[^0]\d+\b)
```
Demo <https://regex101.com/r/bM6cN0/1>
Don't parse everything with regex, bro. | Something like `\d{2,5}x\d{2,5}` should do the work.
Test: <https://regex101.com/r/cV8mE0/1> |
28,852,008 | If I have this string given by a ffmpeg command when you try to get information about a video:
>
> Copyright (c) 2000-2015 the FFmpeg developers built with gcc 4.4.7
> (GCC) 20120313 (Red Hat 4.4.7-11) configuration:
> --prefix=/usr/local/cpffmpeg --enable-shared --enable-nonfree --enable-gpl --enable-pthreads --enable-libopencore-amrnb --enable-decoder=liba52 --enable-libopencore-amrwb --enable-libfaac --enable-libmp3lame --enable-libtheora --enable-libvorbis --enable-libx264 --enable-libxvid --extra-cflags=-I/usr/local/cpffmpeg/include/ --extra-ldflags=-L/usr/local/cpffmpeg/lib --enable-version3 --extra-version=syslint libavutil 54. 19.100 / 54. 19.100 libavcodec 56. 26.100 / 56. 26.100 libavformat 56. 23.106 / 56. 23.106 libavdevice 56. 4.100 / 56. 4.100 libavfilter 5. 11.102 / 5. 11.102
> libswscale 3. 1.101 / 3. 1.101 libswresample 1. 1.100 / 1. 1.100
> libpostproc 53. 3.100 / 53. 3.100Input #0, mov,mp4,m4a,3gp,3g2,mj2,
> from '/var/zpanel/hostdata/zadmin/public\_html/chandelier.mp4':
> Metadata: major\_brand : isom minor\_version : 512 compatible\_brands:
> isomiso2avc1mp41 URL : Follow Me On > www.hamhame1.in compilation : 0
> title : Follow Me On > www.hamhame1.in artist : Follow Me On >
> www.hamhame1.in album : Follow Me On > www.hamhame1.in date : Follow
> Me On > www.hamhame1.in genre : Follow Me On > www.hamhame1.in comment
> : Follow Me On > www.hamhame1.in composer : Follow Me On >
> www.hamhame1.in original\_artist : Follow Me On > www.hamhame1.in
> copyright : Follow Me On > www.hamhame1.in encoder : Follow Me On >
> www.hamhame1.in album\_artist : Follow Me On > www.hamhame1.in
> season\_number : 0 episode\_sort : 0 track : 0 disc : 0 media\_type : 0
> Duration: 00:03:51.35, start: 0.000000, bitrate: 2778 kb/s Stream
> 0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, **1920x1080** [SAR 1:1 > DAR 16:9], 2646 kb/s, 23.98 fps, 23.98 tbr, 90k tbn, 47.95
> tbc (default) Metadata: handler\_name : VideoHandler Stream #0:1(und):
> Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 125 kb/s
> (default) Metadata: handler\_name : SoundHandlerAt least one output
> file must be specified
>
>
>
In this case video dimension is: 1920x1080
How can I export video dimension knowing that yuv420p and [SAR 1:1 > DAR 16:9] might be different (and also that. 1920x1080 could be 402x250 or 24x59). I'm not really interested in using third-party classes. | 2015/03/04 | [
"https://Stackoverflow.com/questions/28852008",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2922834/"
] | Use `ffprobe`. It is from the FFmpeg project. **No need for regex** (if your input has two video streams then that is two sets of info to process). You can limit the parsing to specific streams and modify outputs to display whatever parameter(s) you want.
Example 1: `widthxheight`
=========================
```
ffprobe -v error -select_streams v:0 -show_entries stream=width,height -of csv=s=x:p=0 input.mp4
```
Result:
```
1280x720
```
Example 2: With keys
====================
```
ffprobe -v error -select_streams v:0 -show_entries stream=width,height -of default=noprint_wrappers=1 input.mp4
```
Result:
```
width=1280
height=720
```
### Also see
* [FFprobe Documentation](https://ffmpeg.org/ffprobe.html)
* [FFmpeg Wiki: FFprobe](https://trac.ffmpeg.org/wiki/FFprobeTips) | Something like `\d{2,5}x\d{2,5}` should do the work.
Test: <https://regex101.com/r/cV8mE0/1> |
4,039,176 | I work for a company that built interactive seating charts using Javascript. Here's an example: <http://seatgeek.com/event/show/457624/miami-dolphins-at-new-york-jets-2010-12-12/>. In many ways they mimic the functionality of Google Maps.
We're dealing with an odd problem--performance for the maps is fine in all browsers except IE8. I'm including IE6 and IE7 in the "all browsers" category. We're seeing markedly worse JS performance in IE8. When you try to drag the map in IE8, it locks up a bit and there's a noticeable lag. But that's not a problem in IE6 or IE7.
We've isolated that the problem is related to the markers on the map. It's much more prevalent when you zoom in and there are more markers displayed.
We've done some benchmarking using [dynaTrace](http://ajax.dynatrace.com/pages/) and it seems the delay is not caused by JS processing, per se, but rather by what dynaTrace refers to as "rendering". Seems surprising that the newer version of IE would have worse rendering. | 2010/10/28 | [
"https://Stackoverflow.com/questions/4039176",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/135156/"
] | Have you run the script Profiler in the IE8 Developer Tools? It will tell you exactly how much time is spent on each function.
See: [Link](https://learn.microsoft.com/en-us/archive/blogs/ie/introducing-the-ie8-developer-tools-jscript-profiler) | IE8 renders PNGs differently. Try replacing them with a stub gif image and see what happens. Also, your site is super slow: images do not get pre-loaded and there is a ton of them. This type of rendering could easily be done by raphaeljs without using any images (the originals are probably vectors -- export them as paths and render with raphael).
Also, you totally screwed up the compression: you don't need the alpha channel and using a palette is a ton better in your case. |
71,105 | The [official FAQ](http://us.battle.net/support/en/article/diablo-iii-installation-troubleshooting-mac#10) says that FileVault and FileVault2 are incompatible with Diablo 3. How can I install Diablo 3 on my Mac if my harddrive uses FileVault? | 2012/05/30 | [
"https://gaming.stackexchange.com/questions/71105",
"https://gaming.stackexchange.com",
"https://gaming.stackexchange.com/users/26598/"
] | Blizzard's archive format is incompatible with FileVault due to its [low level nature](http://www.quora.com/Blizzard-Entertainment/What-about-Blizzards-game-install-process-is-incompatible-with-Apples-Filevault). To get around this problem, you need to move the installer to a partition that does not use FileVault. I would also recommend installing it to a partition that does not use FileVault as well, in case later game updates use the MPQ archive format as well.
I was able to use the following steps to get around this:
* Created a new partition of suitable size (I went with 50GB)
* Moved the installer to that new partition
* Created an "Applications" folder on that partition
* Launched the D3 installer from the new partition
* Selected the "Applications" folder on the new parition
This allows you to keep FileVault enabled on your primary partition while also installing Diablo3. That is, you get the best of both worlds at the cost of creating a special partition for Diablo3. This way you do not have to disable FileVault for your entire computer. | I wasn't aware of the issues with Diablo 3 and FileVault, but just confirmed that I have FileVault turned on for my primary HD where Diablo 3 is installed. One difference that I can tell between my setup and yours may be that I turned on FV **after** I had installed Diablo 3.
A few weeks back I installed a new drive in my Mac and the first thing I setup, after running the OSX Lion upgrade was to start the Diablo 3 download and install. It wasn't till a week later that I realized that I forgot to turn on FileVault and that's when I turned it on. So it could be that a way around the issue is to have FileVault turned off when installing Diablo 3 and then turning it on afterwards. |
253,541 | How to get Field values of a list item using CSOM Powershell?
I am using below code:
```
foreach($field in $List.Fields)
{
write-host $field
}
```
I am getting the values as output:
```
Microsoft.SharePoint.Client.Field
Microsoft.SharePoint.Client.FieldDataTime
Microsoft.SharePoint.Client.FieldLookup
```
But I want all field values like ID, Title, Created By etc. | 2018/11/30 | [
"https://sharepoint.stackexchange.com/questions/253541",
"https://sharepoint.stackexchange.com",
"https://sharepoint.stackexchange.com/users/78229/"
] | Your code does not retrieve any list items. This is an example of how you do it:
```
$listItems = $list.GetItems([Microsoft.SharePoint.Client.CamlQuery]::CreateAllItemsQuery())
$ctx.load($listItems)
$ctx.executeQuery()
foreach($listItem in $listItems)
{
Write-Host "ID - " $listItem["ID"] "Title - " $listItem["Title"]
}
```
Credits to: <https://www.c-sharpcorner.com/article/list-item-operations-using-csom-with-powershell-for-sharepoi/> | If you want to get list item values, you can use this
```
$web=Get-SPWeb "http://www.myspapp/sites/myspweb"
$list=$web.Lists["MyListNAme"]
foreach($item in $list.Items)
{
Write-Host $item["ID"] $item["Title"]
}
```
If you want to get column names only, you can use this
```
$web=Get-SPWeb "http://www.myspapp/sites/myspweb"
$list=$web.Lists["MyListNAme"]
foreach($field in $list.Fields)
{
Write-Host $field
}
``` |
253,541 | How to get Field values of a list item using CSOM Powershell?
I am using below code:
```
foreach($field in $List.Fields)
{
write-host $field
}
```
I am getting the values as output:
```
Microsoft.SharePoint.Client.Field
Microsoft.SharePoint.Client.FieldDataTime
Microsoft.SharePoint.Client.FieldLookup
```
But I want all field values like ID, Title, Created By etc. | 2018/11/30 | [
"https://sharepoint.stackexchange.com/questions/253541",
"https://sharepoint.stackexchange.com",
"https://sharepoint.stackexchange.com/users/78229/"
] | Your code does not retrieve any list items. This is an example of how you do it:
```
$listItems = $list.GetItems([Microsoft.SharePoint.Client.CamlQuery]::CreateAllItemsQuery())
$ctx.load($listItems)
$ctx.executeQuery()
foreach($listItem in $listItems)
{
Write-Host "ID - " $listItem["ID"] "Title - " $listItem["Title"]
}
```
Credits to: <https://www.c-sharpcorner.com/article/list-item-operations-using-csom-with-powershell-for-sharepoi/> | You need to get the item/s first (either by CAML query or by id) and the property values are accessible via:
```
$item.FieldValues
```
So you can get the values you are after like so:
```
$item.FieldValues.Title
$item.FieldValues.ID
``` |
73,827,697 | I have a table to track the mailbox and groups. 1 mailbox will have 3 different groups. I want to check each day's connected status of all mailboxes and groups. I have created the below query but it returns multiple rows. I want to aggregate data like the one below. Could someone please help!
```
Select cast (CreatedDate as Date), Connected, GroupOrMbx, GroupType
from [dbo].[Mbx_test]
group by cast (CreatedDate as Date), Connected, GroupOrMbx, GroupType
```
Expected output:
[![enter image description here](https://i.stack.imgur.com/IKbpn.png)](https://i.stack.imgur.com/IKbpn.png)
Table & data
```
CREATE TABLE [dbo].[Mbx_test](
[GroupOrMbx] [varchar](10) NOT NULL,
[GroupName] [varchar](255) NULL,
[GroupEmail] [varchar](255) NULL,
[GroupType] [varchar](10) NULL,
[MBXName] [varchar](255) NULL,
[MBXEmail] [varchar](255) NULL,
[Connected] [bit] NOT NULL,
[CreatedDate] [datetime] NOT NULL
)
INSERT INTO Mbx_test
VALUES
('mbx', NULL, NULL,NULL,'mbx1','mbx1@test.com',1,'2022-09-22'),
('group', 'group1','group1@test.com','W','mbx1','mbx1@test.com',1,'2022-09-22'),
('group', 'group2','group2@test.com','M','mbx1','mbx1@test.com',1,'2022-09-22'),
('group', 'group3','group3@test.com','R','mbx1','mbx1@test.com',1,'2022-09-22'),
('mbx', NULL, NULL,NULL,'mbx2','mbx2@test.com',1,'2022-09-22'),
('group', 'group4','group4@test.com','W','mbx2','mbx2@test.com',1,'2022-09-22'),
('group', 'group5','group5@test.com','M','mbx2','mbx2@test.com',1,'2022-09-22'),
('group', 'group6','group6@test.com','R','mbx2','mbx2@test.com',1,'2022-09-22'),
('mbx', NULL, NULL,NULL,'mbx3','mbx3@test.com',0,'2022-09-22'),
('group', 'group7','group7@test.com','W','mbx3','mbx3@test.com',0,'2022-09-22'),
('group', 'group8','group8@test.com','M','mbx3','mbx3@test.com',0,'2022-09-22'),
('group', 'group9','group9@test.com','R','mbx3','mbx3@test.com',0,'2022-09-22'),
('mbx', NULL, NULL,NULL,'mbx4','mbx4@test.com',0,'2022-09-22'),
('group', 'group10','group10@test.com','W','mbx4','mbx4@test.com',0,'2022-09-22'),
('group', 'group11','group11@test.com','M','mbx4','mbx4@test.com',0,'2022-09-22'),
('group', 'group12','group12@test.com','R','mbx4','mbx4@test.com',0,'2022-09-22')
```
Code is saved here
<https://dbfiddle.uk/WRW7xKeO> | 2022/09/23 | [
"https://Stackoverflow.com/questions/73827697",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8756709/"
] | A statement using conditional aggregation returns the expected results:
```
SELECT
CreatedDate,
Connected,
COUNT(CASE WHEN GroupOrMbx = 'mbx' THEN GroupOrMbx END) AS [Mbx],
COUNT(CASE WHEN GroupOrMbx = 'group' THEN GroupOrMbx END) AS [Group],
COUNT(CASE WHEN GroupType = 'W' THEN GroupType END) AS [W],
COUNT(CASE WHEN GroupType = 'M' THEN GroupType END) AS [M],
COUNT(CASE WHEN GroupType = 'R' THEN GroupType END) AS [R]
FROM Mbx_test
GROUP BY CreatedDate, Connected
``` | It's not pretty but you can do the whole thing using a load of sub-queries
```
WITH TestDates AS
(
SELECT DISTINCT CreatedDate FROM Mbx_test
)
SELECT
CreatedDate,
'Yes' Connected,
(SELECT COUNT(*) FROM Mbx_Test WHERE Mbx_Test.CreatedDate = TestDates.CreatedDate AND GroupOrMbx = 'mbx' AND Connected = 1) Mbx,
(SELECT COUNT(*) FROM Mbx_Test WHERE Mbx_Test.CreatedDate = TestDates.CreatedDate AND GroupOrMbx = 'group' AND Connected = 1) [Group],
(SELECT COUNT(*) FROM Mbx_Test WHERE Mbx_Test.CreatedDate = TestDates.CreatedDate AND GroupOrMbx = 'group' AND GroupType = 'W' AND Connected = 1) W,
(SELECT COUNT(*) FROM Mbx_Test WHERE Mbx_Test.CreatedDate = TestDates.CreatedDate AND GroupOrMbx = 'group' AND GroupType = 'M' AND Connected = 1) M,
(SELECT COUNT(*) FROM Mbx_Test WHERE Mbx_Test.CreatedDate = TestDates.CreatedDate AND GroupOrMbx = 'group' AND GroupType = 'R' AND Connected = 1) R
FROM
TestDates
UNION
SELECT
CreatedDate,
'No' Connected,
(SELECT COUNT(*) FROM Mbx_Test WHERE Mbx_Test.CreatedDate = TestDates.CreatedDate AND GroupOrMbx = 'mbx' AND Connected = 0) Mbx,
(SELECT COUNT(*) FROM Mbx_Test WHERE Mbx_Test.CreatedDate = TestDates.CreatedDate AND GroupOrMbx = 'group' AND Connected = 0) [Group],
(SELECT COUNT(*) FROM Mbx_Test WHERE Mbx_Test.CreatedDate = TestDates.CreatedDate AND GroupOrMbx = 'group' AND GroupType = 'W' AND Connected = 0) W,
(SELECT COUNT(*) FROM Mbx_Test WHERE Mbx_Test.CreatedDate = TestDates.CreatedDate AND GroupOrMbx = 'group' AND GroupType = 'M' AND Connected = 0) M,
(SELECT COUNT(*) FROM Mbx_Test WHERE Mbx_Test.CreatedDate = TestDates.CreatedDate AND GroupOrMbx = 'group' AND GroupType = 'R' AND Connected = 0) R
FROM
TestDates
``` |
19,475,475 | I tried to use the code below :
```
read choice
case $choice in
"1") less /var/log/messages
if [$? -ne 0]; then
less /var/log/syslog
fi
;;
etc
etc
etc
*) echo "Please enter a choice between 1 and 20";;
esac
```
when executing ./myScript.sh I got this :
```
./myScript.sh: line 4: [1: command not found
```
I can't find the problem ! | 2013/10/20 | [
"https://Stackoverflow.com/questions/19475475",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2899642/"
] | In your `if` statement, put space after `[` and before `]`, as
```
if [ $? -ne 0 ]; then
``` | At (4, 8) and (4, 16) are the problems. Place a space between (4, 7) and (4, 8) and another space between (4, 15) and (4, 16). These ordered pairs are like (line, column).
Do it like this on line 4:
```sh
if [ $? -ne 0 ]; then
``` |
1,206,750 | Let $$f(x)= \sum\_{n=0}^{\infty} \frac{x^n}{n!} $$
for $x\in \mathbb R$.
Show $f′ =f$.
**Note:** Do not use the fact that $f(x) = e^x$. This is true but has not been established at this point in the text. | 2015/03/25 | [
"https://math.stackexchange.com/questions/1206750",
"https://math.stackexchange.com",
"https://math.stackexchange.com/users/130272/"
] | If the series converges uniformly to $f$ then you may use termwise derivative then for any $x \in Dom f$ we have
$$\require{cancel} f' (x) = \frac{d}{dx}\bigg(\sum\_{n=0}^{\infty} \frac{x^n}{n!}\bigg) = \sum\_{n=0}^{\infty} \frac{d}{dx}\bigg(\frac{x^n}{n!}\bigg) = \sum\_{n=1}^{\infty} \frac{n x^{n-1}}{n!} = \sum\_{n=1}^{\infty} \frac{\cancel nx^{n-1}}{\cancel n(n-1)!} = \sum\_{n=0}^{\infty} \frac{x^n}{n!} = f(x)$$ | Here is a proof which avoids uniform convergence.
Let $$f(x) = \sum\_{n = 0}^{\infty}\frac{x^{n}}{n!}\tag{1}$$ Using multiplication of infinite series it is easy to show that $$f(x)f(y) = f(x + y)\tag{2}$$ for all real $x, y$ (the proof of this also requires binomial theorem for positive integer index).
Next we can see that if $0 < x < 2$ then we have
\begin{align}
\frac{f(x) - 1}{x} &= 1 + \frac{x}{2!} + \frac{x^{2}}{3!} + \cdots\notag\\
&\leq 1 + \frac{x}{2} + \frac{x^{2}}{2^{2}} + \frac{x^{3}}{2^{3}} + \cdots\notag\\
&= 1 + \frac{x/2}{1 - (x/2)} = 1 + \frac{x}{2 - x}\notag
\end{align}
Thus for $0 < x < 2$ we have $$1 \leq \frac{f(x) - 1}{x}\leq 1 + \frac{x}{2 - x}\tag{3}$$ and taking limits when $x \to 0^{+}$ and using Squeeze theorem we get $$\lim\_{x \to 0^{+}}\frac{f(x) - 1}{x} = 1\tag{4}$$ This also shows that $$\lim\_{x \to 0^{+}}f(x) = \lim\_{x \to 0^{+}}1 + x\cdot\frac{f(x) - 1}{x} = 1 + 0\cdot 1 = 1\tag{5}$$ Again using equation $(2)$ we have $$f(x)f(-x) = f(x + (-x)) = f(0) = 1$$ so that $f(-x) = 1/f(x)$ and therefore
\begin{align}
\lim\_{x \to 0^{-}}\frac{f(x) - 1}{x}&= \lim\_{y \to 0^{+}}\frac{1 - f(-y)}{y}\text{ (putting }x = -y)\notag\\
&= \lim\_{y \to 0^{+}}\frac{f(y) - 1}{y}\cdot\frac{1}{f(y)}\notag\\
&= 1\cdot 1 = 1\text{ (using equations (4) and (5))}\notag
\end{align}
It now follows that $$\lim\_{x \to 0}\frac{f(x) - 1}{x} = 1\tag{6}$$ Finally we have
\begin{align}
f'(x) &= \lim\_{h \to 0}\frac{f(x + h) - f(x)}{h}\notag\\
&= \lim\_{h \to 0}\frac{f(x)f(h) - f(x)}{h}\notag\\
&= \lim\_{h \to 0}f(x)\cdot\frac{f(h) - 1}{h}\notag\\
&= f(x)\cdot 1 = f(x)\text{ (using equation (6))}\notag
\end{align} |
41,660,580 | I have environment variables in my application.properties like this `spring.mail.username=${username}`
The `${username}` is declare in eclipse environment variable. When I build maven package and install, then deploy it to tcServer. The TC Server does not know `${username}`. Another word, the environment variables do not include in the war file during build.
How do I get the environment variable in eclipse to include in war file for deployment? | 2017/01/15 | [
"https://Stackoverflow.com/questions/41660580",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3184890/"
] | Use a click counter, so when you click on the button the second time, it shows the "edit" button and resets the counter back to 0.
When you then click on the "ok" button it changes back to the "edit" button, and because you now have done the first edit, next time you click on the button it changes to "ok" right away.
```
$('.edit').each(function() {
var clickCounter = 0, // Sets click counter to 0 - No clicks done yet
firstEdit = false; // Sets first edit to false
$(this).on('click', function() {
clickCounter++;
if( clickCounter == 2 || firstEdit == true ) {
$(this).toggle();
$(this).next('.ok').toggle();
clickCounter = 0; // Reset counter
firstEdit = true;
}
});
});
$('.ok').on('click', function() {
$(this).toggle();
$(this).prev('.edit').toggle();
});
```
[Working Fiddle](https://jsfiddle.net/9zw2a2x3/3) | ```
$(window).ready(function(){
$('.edit').each(function(){
var counter=0;//add a counter to each edit button
this.on('click',function(){
counter++;//increase counter
console.log(counter);
if(counter===2){//if button clicked twice
$(this).toggle();
//show the ok button which is just next to the edit button
$(this).next(".ok").toggle();
counter=0;//reset counter
}
});
});
});
```
or taking pure ES6:
```
window.onload=function(){//when the page is loaded
var imgs=[...document.getElementsByClassName("edit")];//get all edit imgs
imgs.forEach(img=>{//loop trough images
var counter=0;//add a counter for each image
img.onclick=function(){
counter++;//onclick increase counter
if(conter===2){//if img was clicked twice
this.src="ok.png";//replace the img
counter=0;
}
}
});
};
``` |
41,660,580 | I have environment variables in my application.properties like this `spring.mail.username=${username}`
The `${username}` is declare in eclipse environment variable. When I build maven package and install, then deploy it to tcServer. The TC Server does not know `${username}`. Another word, the environment variables do not include in the war file during build.
How do I get the environment variable in eclipse to include in war file for deployment? | 2017/01/15 | [
"https://Stackoverflow.com/questions/41660580",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3184890/"
] | Use a click counter, so when you click on the button the second time, it shows the "edit" button and resets the counter back to 0.
When you then click on the "ok" button it changes back to the "edit" button, and because you now have done the first edit, next time you click on the button it changes to "ok" right away.
```
$('.edit').each(function() {
var clickCounter = 0, // Sets click counter to 0 - No clicks done yet
firstEdit = false; // Sets first edit to false
$(this).on('click', function() {
clickCounter++;
if( clickCounter == 2 || firstEdit == true ) {
$(this).toggle();
$(this).next('.ok').toggle();
clickCounter = 0; // Reset counter
firstEdit = true;
}
});
});
$('.ok').on('click', function() {
$(this).toggle();
$(this).prev('.edit').toggle();
});
```
[Working Fiddle](https://jsfiddle.net/9zw2a2x3/3) | You can use one class to control and change the state of your button:
```
$('.edit').on('click',function(){
if ($(this).hasClass('is-state1')) {
$(this).next(".ok").toggle();
$(this).toggle();
}
$(this).toggleClass('is-state1');
});
$('.ok').on('click',function(){
$(this).toggle();
$(this).next(".edit").toggle();
});
```
Also I'm thinking you are wrong in `ok` button event as you want change your previous and not your next button:
```
$('.ok').on('click',function(){
$(this).toggle();
$(this).prev(".edit").toggle();
});
``` |
15,852,123 | I am learning to write thread-safe programs and how to evaluate codes which are not thread safe.
A class is considered thread-safe if it function correctly when executed by multiple threads.
My Counter.java is not a thread-safe one, however the output was printed as expected from 0-9 for all 3 threads.
Can anyone explains why? and how thread-safety works?
```
public class Counter {
private int count = 0;
public void increment() {
count++;
}
public void decrement() {
count--;
}
public void print() {
System.out.println(count);
}
}
public class CountThread extends Thread {
private Counter counter = new Counter();
public CountThread(String name) {
super(name);
}
public void run() {
for (int i=0; i<10; i++) {
System.out.print("Thread " + getName() + " ");
counter.print();
counter.increment();
}
}
}
public class CounterMain {
public static void main(String[] args) {
CountThread threadOne = new CountThread("1");
CountThread threadTwo = new CountThread("2");
CountThread threadThree = new CountThread("3");
threadOne.start();
threadTwo.start();
threadThree.start();
}
}
``` | 2013/04/06 | [
"https://Stackoverflow.com/questions/15852123",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/247814/"
] | Your code runs fine in your specific test. That doesn't mean it will always work fine. Try iterating a lot more times, and you'll probably start seeing anomalies.
Your test is a bit like if you tested that a bridge can support 20 trucks by riding on the bridge with a single car. It doesn't demonstrate anything. And demonstrating that th code is thread-safe using a test is almost impossible. Only careful reading and understanding of all the potential problems can guarantee that. A non thread-safe program might work fine for years and suddenly have a bug.
To make you counter safe, use an AtomicInteger.
EDIT :
Also, as noted by @SpringRush, you're not sharing a single counter between threads. Each thread has its own counter. So your code is actually thread-safe, but I don't think it does what you intend it to do. | Your `Counter` is not shared through the 3 threads, instead, each thread has a unique `Counter` |
15,852,123 | I am learning to write thread-safe programs and how to evaluate codes which are not thread safe.
A class is considered thread-safe if it function correctly when executed by multiple threads.
My Counter.java is not a thread-safe one, however the output was printed as expected from 0-9 for all 3 threads.
Can anyone explains why? and how thread-safety works?
```
public class Counter {
private int count = 0;
public void increment() {
count++;
}
public void decrement() {
count--;
}
public void print() {
System.out.println(count);
}
}
public class CountThread extends Thread {
private Counter counter = new Counter();
public CountThread(String name) {
super(name);
}
public void run() {
for (int i=0; i<10; i++) {
System.out.print("Thread " + getName() + " ");
counter.print();
counter.increment();
}
}
}
public class CounterMain {
public static void main(String[] args) {
CountThread threadOne = new CountThread("1");
CountThread threadTwo = new CountThread("2");
CountThread threadThree = new CountThread("3");
threadOne.start();
threadTwo.start();
threadThree.start();
}
}
``` | 2013/04/06 | [
"https://Stackoverflow.com/questions/15852123",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/247814/"
] | Your `Counter` is not shared through the 3 threads, instead, each thread has a unique `Counter` | So that's actually thread-safe. For every CountThread, there's one counter. To make it not thread safe, change the counter variable to:
```
private static Counter counter = new Counter();
```
Then it wouldn't be thread safe because different threads could be modifying the counter state at the same time. |
15,852,123 | I am learning to write thread-safe programs and how to evaluate codes which are not thread safe.
A class is considered thread-safe if it function correctly when executed by multiple threads.
My Counter.java is not a thread-safe one, however the output was printed as expected from 0-9 for all 3 threads.
Can anyone explains why? and how thread-safety works?
```
public class Counter {
private int count = 0;
public void increment() {
count++;
}
public void decrement() {
count--;
}
public void print() {
System.out.println(count);
}
}
public class CountThread extends Thread {
private Counter counter = new Counter();
public CountThread(String name) {
super(name);
}
public void run() {
for (int i=0; i<10; i++) {
System.out.print("Thread " + getName() + " ");
counter.print();
counter.increment();
}
}
}
public class CounterMain {
public static void main(String[] args) {
CountThread threadOne = new CountThread("1");
CountThread threadTwo = new CountThread("2");
CountThread threadThree = new CountThread("3");
threadOne.start();
threadTwo.start();
threadThree.start();
}
}
``` | 2013/04/06 | [
"https://Stackoverflow.com/questions/15852123",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/247814/"
] | Your `Counter` is not shared through the 3 threads, instead, each thread has a unique `Counter` | Try with this:
```
public class ThreadSafeCounter {
AtomicInteger value = new AtomicInteger(0);
public ThreadSafeCounter(AtomicInteger value) {
this.value = value;
}
public void increment() {
value.incrementAndGet();
}
public void decrement() {
value.decrementAndGet();
}
public AtomicInteger getValue() {
return value;
}
```
} |
15,852,123 | I am learning to write thread-safe programs and how to evaluate codes which are not thread safe.
A class is considered thread-safe if it function correctly when executed by multiple threads.
My Counter.java is not a thread-safe one, however the output was printed as expected from 0-9 for all 3 threads.
Can anyone explains why? and how thread-safety works?
```
public class Counter {
private int count = 0;
public void increment() {
count++;
}
public void decrement() {
count--;
}
public void print() {
System.out.println(count);
}
}
public class CountThread extends Thread {
private Counter counter = new Counter();
public CountThread(String name) {
super(name);
}
public void run() {
for (int i=0; i<10; i++) {
System.out.print("Thread " + getName() + " ");
counter.print();
counter.increment();
}
}
}
public class CounterMain {
public static void main(String[] args) {
CountThread threadOne = new CountThread("1");
CountThread threadTwo = new CountThread("2");
CountThread threadThree = new CountThread("3");
threadOne.start();
threadTwo.start();
threadThree.start();
}
}
``` | 2013/04/06 | [
"https://Stackoverflow.com/questions/15852123",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/247814/"
] | Your code runs fine in your specific test. That doesn't mean it will always work fine. Try iterating a lot more times, and you'll probably start seeing anomalies.
Your test is a bit like if you tested that a bridge can support 20 trucks by riding on the bridge with a single car. It doesn't demonstrate anything. And demonstrating that th code is thread-safe using a test is almost impossible. Only careful reading and understanding of all the potential problems can guarantee that. A non thread-safe program might work fine for years and suddenly have a bug.
To make you counter safe, use an AtomicInteger.
EDIT :
Also, as noted by @SpringRush, you're not sharing a single counter between threads. Each thread has its own counter. So your code is actually thread-safe, but I don't think it does what you intend it to do. | So that's actually thread-safe. For every CountThread, there's one counter. To make it not thread safe, change the counter variable to:
```
private static Counter counter = new Counter();
```
Then it wouldn't be thread safe because different threads could be modifying the counter state at the same time. |
15,852,123 | I am learning to write thread-safe programs and how to evaluate codes which are not thread safe.
A class is considered thread-safe if it function correctly when executed by multiple threads.
My Counter.java is not a thread-safe one, however the output was printed as expected from 0-9 for all 3 threads.
Can anyone explains why? and how thread-safety works?
```
public class Counter {
private int count = 0;
public void increment() {
count++;
}
public void decrement() {
count--;
}
public void print() {
System.out.println(count);
}
}
public class CountThread extends Thread {
private Counter counter = new Counter();
public CountThread(String name) {
super(name);
}
public void run() {
for (int i=0; i<10; i++) {
System.out.print("Thread " + getName() + " ");
counter.print();
counter.increment();
}
}
}
public class CounterMain {
public static void main(String[] args) {
CountThread threadOne = new CountThread("1");
CountThread threadTwo = new CountThread("2");
CountThread threadThree = new CountThread("3");
threadOne.start();
threadTwo.start();
threadThree.start();
}
}
``` | 2013/04/06 | [
"https://Stackoverflow.com/questions/15852123",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/247814/"
] | Your code runs fine in your specific test. That doesn't mean it will always work fine. Try iterating a lot more times, and you'll probably start seeing anomalies.
Your test is a bit like if you tested that a bridge can support 20 trucks by riding on the bridge with a single car. It doesn't demonstrate anything. And demonstrating that th code is thread-safe using a test is almost impossible. Only careful reading and understanding of all the potential problems can guarantee that. A non thread-safe program might work fine for years and suddenly have a bug.
To make you counter safe, use an AtomicInteger.
EDIT :
Also, as noted by @SpringRush, you're not sharing a single counter between threads. Each thread has its own counter. So your code is actually thread-safe, but I don't think it does what you intend it to do. | Try with this:
```
public class ThreadSafeCounter {
AtomicInteger value = new AtomicInteger(0);
public ThreadSafeCounter(AtomicInteger value) {
this.value = value;
}
public void increment() {
value.incrementAndGet();
}
public void decrement() {
value.decrementAndGet();
}
public AtomicInteger getValue() {
return value;
}
```
} |
50,106,748 | Please could someone guide me on a good practice using 'Error Handling' approaches with my 'working' (Swift 4) code below... (eg: 'Guards', 'Do', 'Catch', Throw', 'if', 'else')...
//// Import ////
import UIKit
import CoreData
//// Custom Function ////
func insertCoreData(){
if let coreData = (UIApplication.shared.delegate as? AppDelegate)?.persistentContainer.viewContext {
let data = MyEntity(entity: MyEntity.entity(), insertInto: coreData)
data.name = "Joe Blogs"
data.country = "United Kingdom"
try? coreData.save()
print("Data Saved...")
}
}
//// Output Function ///
insertCoreData() // Working and Gives | 2018/04/30 | [
"https://Stackoverflow.com/questions/50106748",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | you can do this by updating the default style. you must update the AndroidManifest.template.xml by somethink like
```
<application android:persistent="%persistent%"
android:restoreAnyVersion="%restoreAnyVersion%"
android:label="%label%"
android:debuggable="%debuggable%"
android:largeHeap="%largeHeap%"
android:icon="%icon%"
android:theme="@style/myAppTheme"
android:hardwareAccelerated="%hardwareAccelerated%">
```
and then you must provide a style.xml with the setting you need (like make the statusbar translucent)
exemple of style.xml :
```
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="myAppTheme" parent="@android:style/Theme.Material.Light.NoActionBar">
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>
<item name="android:windowDrawsSystemBarBackgrounds">false</item>
<item name="android:colorPrimary">#ff2b2e38</item>
<item name="android:colorAccent">#ff0288d1</item>
<item name="android:windowBackground">@drawable/splash_screen</item>
<item name="android:statusBarColor">#ff0087b4</item>
</style>
</resources>
```
see exemple of a demo app that override the default style at <https://github.com/Zeus64/alcinoe> (demo is alfmxcontrols) | You can set the status bar and navigation bar background transparent with my code in github:
<https://github.com/viniciusfbb/fmx_tutorials/tree/master/delphi_system_bars/>
In this case you need to use:
```
uses
iPub.FMX.SystemBars;
...
Form1.SystemBars.StatusBarBackgroundColor := TAlphaColors.Null;
Form1.SystemBars.NavigationBarBackgroundColor := TAlphaColors.Null;
Form1.SystemBars.Visibility := TipFormSystemBars.TVisibilityMode.VisibleAndOverlap;
``` |
52,550,699 | I have set the state of a array as [] empty, in componentDidMount i am getting the API Response.. now i want to set the state of the empty array with the new array of json response how can i do this?
```
constructor(props)
{
super(props)
this.state = {
categoryList : []
}
}
componentDidMount()
{
axios.get('http:xxxxxxxxxxxxxxxxxxxxxxx')
.then(res =>
{
this.setState = {
categoryList : res.data.body.category_list(json path)
}
})
.catch(function(error) {
console.log('Error on Authentication' + error);
})
}
``` | 2018/09/28 | [
"https://Stackoverflow.com/questions/52550699",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10319533/"
] | 1. If you are using Bitrise, go to 'Xcode Archive & Export for iOS' step.
2. Scroll down and expand the 'Debug' section. Scroll down to 'Do a clean Xcode build before the archive?' and change this to 'yes'.
3. Save your settings start a new build, do not rebuild as it will use the old settings. | I resolve this issue by setting the build system to Legacy.
Open the `PROJECT_NAME.workspace file`
Then in the top menu select `File > Workspace Settings`
Then change `Build System` to `Legacy Build System` |
51,617,624 | I have two lists named `extra` and `be` in my code.
`extra` output is `[7,27]` and
`be` output is
```python
'Feed Forage', '', '', '', 'Social Play', '', 'Feed Forage', 'Nonsocial Play', '', 'Nonsocial Play', '', '', '', '', 'Nonsocial Play', '', '', '', '', '', '', '', '', 'Social Play', '', '', '', '', '', '', '', '', 'Nonsocial Play', 'Groom', 'Feed Forage', '', '', 'Nonsocial Play', '', '', 'Feed Forage', '', 'Feed Forage', '', 'Feed Forage', '', 'Social Play', '', 'Social Play', '', '', 'Social Play', '', '', '', '', '', 'Feed Forage', '', '', '', '', 'Feed Forage', '', '', '', '', 'Feed Forage', '', '', 'Feed Forage', '', '', '', '', '', 'Feed Forage', '', '', '', 'Groom', 'Groom', '', '', '', '', 'Groom', 'Groom', 'Groom', '', 'Groom', '', '', '', 'Feed Forage', '', '', 'Feed Forage', 'Nonsocial Play', '', '', '', 'Pace', '', '', '', 'Feed Forage', '', 'Nonsocial Play', '', 'Feed Forage', '', 'Social Play', '', 'Feed Forage', '', 'Social Play', '', 'Social Play', '', '', '', '', '', 'Nonsocial Play', '', 'Social Play', '', '', '', '', 'Feed Forage', '', '', '', '', '', '', '', 'Nonsocial Play', '', 'Nonsocial Play', '', 'Feed Forage', 'Social Play', '', '', '', 'Feed Forage', '', 'Nonsocial Play', '', '', 'Feed Forage', '', '', '', '', 'Self Groom', '', '', 'Groom', '', '', 'Self Groom', '', '', '', '', '', 'Groom', '', '', 'Self Groom', '', '', 'Feed Forage', '', '', '', '', '', 'Pace', '', 'Self Groom', '', '', '', 'Self Groom', '', 'Self Groom', '', 'Social Play', '', 'Social Play', '', 'Self Groom', 'Groom', '', '', 'Groom', '', 'Groom', '', 'Groom', 'Groom', 'Groom', '', '', 'Self Groom', '', 'Groom', '', 'Groom', '', 'Feed Forage', '', 'Feed Forage', '', 'Feed Forage', '', '', '', '', '', '', '', 'Feed Forage', '', '', '', '', 'Feed Forage', 'Nonsocial Play', '', '', 'Self Groom', 'Nonsocial Play', '', '', '', 'Groom', '', '', 'Groom', '', 'Groom', '', '', 'Groom', '', '', 'Groom', '', '', 'Groom', '', '', '', '', '', '', 'Groom', 'Groom', '', 'Groom', '', '', 'Groom', '', '', '', 'Self Groom', '', '', '', '', '', '', 'Groom', '', 'Groom', '', 'Feed Forage', '']
```
I need to find the 7th and 27th word elements of `extra` (i.e. elements don't count if they are an empty string). It should be `Nonsocial Play` and `Groom` but the for-loop I have only prints `Nonsocial Play`
These are the for-loops I am using:
```
for x in extra:
count = 0
for y in be:
if y != '':
if x == count:
print(be[x])
count += 1
elif x != count:
count += 1
```
If you have any idea why it isn't working, please let me know!
EDIT: I want to print these statements but I also need to delete them | 2018/07/31 | [
"https://Stackoverflow.com/questions/51617624",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10000684/"
] | I created simple function `filter_iter(itr)` that filters the iterable in argument `itr` from any empty values. Then you can access the resulting filtered list with values from list `extra`:
```
extra = [7,27]
be = ['Feed Forage', '', '', '', 'Social Play', '', 'Feed Forage', 'Nonsocial Play', '', 'Nonsocial Play', '', '', '', '', 'Nonsocial Play', '', '', '', '', '', '', '', '', 'Social Play', '', '', '', '', '', '', '', '', 'Nonsocial Play', 'Groom', 'Feed Forage', '', '', 'Nonsocial Play', '', '', 'Feed Forage', '', 'Feed Forage', '', 'Feed Forage', '', 'Social Play', '', 'Social Play', '', '', 'Social Play', '', '', '', '', '', 'Feed Forage', '', '', '', '', 'Feed Forage', '', '', '', '', 'Feed Forage', '', '', 'Feed Forage', '', '', '', '', '', 'Feed Forage', '', '', '', 'Groom', 'Groom', '', '', '', '', 'Groom', 'Groom', 'Groom', '', 'Groom', '', '', '', 'Feed Forage', '', '', 'Feed Forage', 'Nonsocial Play', '', '', '', 'Pace', '', '', '', 'Feed Forage', '', 'Nonsocial Play', '', 'Feed Forage', '', 'Social Play', '', 'Feed Forage', '', 'Social Play', '', 'Social Play', '', '', '', '', '', 'Nonsocial Play', '', 'Social Play', '', '', '', '', 'Feed Forage', '', '', '', '', '', '', '', 'Nonsocial Play', '', 'Nonsocial Play', '', 'Feed Forage', 'Social Play', '', '', '', 'Feed Forage', '', 'Nonsocial Play', '', '', 'Feed Forage', '', '', '', '', 'Self Groom', '', '', 'Groom', '', '', 'Self Groom', '', '', '', '', '', 'Groom', '', '', 'Self Groom', '', '', 'Feed Forage', '', '', '', '', '', 'Pace', '', 'Self Groom', '', '', '', 'Self Groom', '', 'Self Groom', '', 'Social Play', '', 'Social Play', '', 'Self Groom', 'Groom', '', '', 'Groom', '', 'Groom', '', 'Groom', 'Groom', 'Groom', '', '', 'Self Groom', '', 'Groom', '', 'Groom', '', 'Feed Forage', '', 'Feed Forage', '', 'Feed Forage', '', '', '', '', '', '', '', 'Feed Forage', '', '', '', '', 'Feed Forage', 'Nonsocial Play', '', '', 'Self Groom', 'Nonsocial Play', '', '', '', 'Groom', '', '', 'Groom', '', 'Groom', '', '', 'Groom', '', '', 'Groom', '', '', 'Groom', '', '', '', '', '', '', 'Groom', 'Groom', '', 'Groom', '', '', 'Groom', '', '', '', 'Self Groom', '', '', '', '', '', '', 'Groom', '', 'Groom', '', 'Feed Forage', '']
def filter_iter(itr):
return [i for i in itr if i]
be = filter_iter(be)
print([be[e] for e in extra])
```
Prints:
```
['Nonsocial Play', 'Groom']
``` | Single line of code using `list comprehension` with `enumerate` and `filter`
```
[j for i, j in enumerate(list(filter(lambda x: x != '', be))) if i in extra]
['Nonsocial Play', 'Groom']
```
Testing for speed:
```
%timeit [j for i, j in enumerate(list(filter(lambda x: x != '', be))) if i in extra]
45.2 µs ± 5.48 µs per loop (mean ± std. dev. of 7 runs, 10000 loops each)
``` |
51,617,624 | I have two lists named `extra` and `be` in my code.
`extra` output is `[7,27]` and
`be` output is
```python
'Feed Forage', '', '', '', 'Social Play', '', 'Feed Forage', 'Nonsocial Play', '', 'Nonsocial Play', '', '', '', '', 'Nonsocial Play', '', '', '', '', '', '', '', '', 'Social Play', '', '', '', '', '', '', '', '', 'Nonsocial Play', 'Groom', 'Feed Forage', '', '', 'Nonsocial Play', '', '', 'Feed Forage', '', 'Feed Forage', '', 'Feed Forage', '', 'Social Play', '', 'Social Play', '', '', 'Social Play', '', '', '', '', '', 'Feed Forage', '', '', '', '', 'Feed Forage', '', '', '', '', 'Feed Forage', '', '', 'Feed Forage', '', '', '', '', '', 'Feed Forage', '', '', '', 'Groom', 'Groom', '', '', '', '', 'Groom', 'Groom', 'Groom', '', 'Groom', '', '', '', 'Feed Forage', '', '', 'Feed Forage', 'Nonsocial Play', '', '', '', 'Pace', '', '', '', 'Feed Forage', '', 'Nonsocial Play', '', 'Feed Forage', '', 'Social Play', '', 'Feed Forage', '', 'Social Play', '', 'Social Play', '', '', '', '', '', 'Nonsocial Play', '', 'Social Play', '', '', '', '', 'Feed Forage', '', '', '', '', '', '', '', 'Nonsocial Play', '', 'Nonsocial Play', '', 'Feed Forage', 'Social Play', '', '', '', 'Feed Forage', '', 'Nonsocial Play', '', '', 'Feed Forage', '', '', '', '', 'Self Groom', '', '', 'Groom', '', '', 'Self Groom', '', '', '', '', '', 'Groom', '', '', 'Self Groom', '', '', 'Feed Forage', '', '', '', '', '', 'Pace', '', 'Self Groom', '', '', '', 'Self Groom', '', 'Self Groom', '', 'Social Play', '', 'Social Play', '', 'Self Groom', 'Groom', '', '', 'Groom', '', 'Groom', '', 'Groom', 'Groom', 'Groom', '', '', 'Self Groom', '', 'Groom', '', 'Groom', '', 'Feed Forage', '', 'Feed Forage', '', 'Feed Forage', '', '', '', '', '', '', '', 'Feed Forage', '', '', '', '', 'Feed Forage', 'Nonsocial Play', '', '', 'Self Groom', 'Nonsocial Play', '', '', '', 'Groom', '', '', 'Groom', '', 'Groom', '', '', 'Groom', '', '', 'Groom', '', '', 'Groom', '', '', '', '', '', '', 'Groom', 'Groom', '', 'Groom', '', '', 'Groom', '', '', '', 'Self Groom', '', '', '', '', '', '', 'Groom', '', 'Groom', '', 'Feed Forage', '']
```
I need to find the 7th and 27th word elements of `extra` (i.e. elements don't count if they are an empty string). It should be `Nonsocial Play` and `Groom` but the for-loop I have only prints `Nonsocial Play`
These are the for-loops I am using:
```
for x in extra:
count = 0
for y in be:
if y != '':
if x == count:
print(be[x])
count += 1
elif x != count:
count += 1
```
If you have any idea why it isn't working, please let me know!
EDIT: I want to print these statements but I also need to delete them | 2018/07/31 | [
"https://Stackoverflow.com/questions/51617624",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10000684/"
] | **Python 2**
```
new_be=filter(lambda a: a != '', be) #we delete from the list all the '' and we save the new list in new_be
world=[]
for i in extra:
world.append(new_be[int(i)])
print (world)
```
**Python 3**
```
new_be=list(filter(("").__ne__, be)) #we delete from the list all the '' and we save the new list in new_be
world=[]
for i in extra:
world.append(new_be[int(i)])
print (world)
```
>
> ['Nonsocial Play', 'Groom']
>
>
> | This:
```
[[w for w in be if w != ''][k] for k in extra]
``` |
51,617,624 | I have two lists named `extra` and `be` in my code.
`extra` output is `[7,27]` and
`be` output is
```python
'Feed Forage', '', '', '', 'Social Play', '', 'Feed Forage', 'Nonsocial Play', '', 'Nonsocial Play', '', '', '', '', 'Nonsocial Play', '', '', '', '', '', '', '', '', 'Social Play', '', '', '', '', '', '', '', '', 'Nonsocial Play', 'Groom', 'Feed Forage', '', '', 'Nonsocial Play', '', '', 'Feed Forage', '', 'Feed Forage', '', 'Feed Forage', '', 'Social Play', '', 'Social Play', '', '', 'Social Play', '', '', '', '', '', 'Feed Forage', '', '', '', '', 'Feed Forage', '', '', '', '', 'Feed Forage', '', '', 'Feed Forage', '', '', '', '', '', 'Feed Forage', '', '', '', 'Groom', 'Groom', '', '', '', '', 'Groom', 'Groom', 'Groom', '', 'Groom', '', '', '', 'Feed Forage', '', '', 'Feed Forage', 'Nonsocial Play', '', '', '', 'Pace', '', '', '', 'Feed Forage', '', 'Nonsocial Play', '', 'Feed Forage', '', 'Social Play', '', 'Feed Forage', '', 'Social Play', '', 'Social Play', '', '', '', '', '', 'Nonsocial Play', '', 'Social Play', '', '', '', '', 'Feed Forage', '', '', '', '', '', '', '', 'Nonsocial Play', '', 'Nonsocial Play', '', 'Feed Forage', 'Social Play', '', '', '', 'Feed Forage', '', 'Nonsocial Play', '', '', 'Feed Forage', '', '', '', '', 'Self Groom', '', '', 'Groom', '', '', 'Self Groom', '', '', '', '', '', 'Groom', '', '', 'Self Groom', '', '', 'Feed Forage', '', '', '', '', '', 'Pace', '', 'Self Groom', '', '', '', 'Self Groom', '', 'Self Groom', '', 'Social Play', '', 'Social Play', '', 'Self Groom', 'Groom', '', '', 'Groom', '', 'Groom', '', 'Groom', 'Groom', 'Groom', '', '', 'Self Groom', '', 'Groom', '', 'Groom', '', 'Feed Forage', '', 'Feed Forage', '', 'Feed Forage', '', '', '', '', '', '', '', 'Feed Forage', '', '', '', '', 'Feed Forage', 'Nonsocial Play', '', '', 'Self Groom', 'Nonsocial Play', '', '', '', 'Groom', '', '', 'Groom', '', 'Groom', '', '', 'Groom', '', '', 'Groom', '', '', 'Groom', '', '', '', '', '', '', 'Groom', 'Groom', '', 'Groom', '', '', 'Groom', '', '', '', 'Self Groom', '', '', '', '', '', '', 'Groom', '', 'Groom', '', 'Feed Forage', '']
```
I need to find the 7th and 27th word elements of `extra` (i.e. elements don't count if they are an empty string). It should be `Nonsocial Play` and `Groom` but the for-loop I have only prints `Nonsocial Play`
These are the for-loops I am using:
```
for x in extra:
count = 0
for y in be:
if y != '':
if x == count:
print(be[x])
count += 1
elif x != count:
count += 1
```
If you have any idea why it isn't working, please let me know!
EDIT: I want to print these statements but I also need to delete them | 2018/07/31 | [
"https://Stackoverflow.com/questions/51617624",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10000684/"
] | Here is a solution using using `filter` the elements, `enumerate` to iterate over the resulting iterator along with its index, and `itertools.islice` to get only certain range of indexes from it
```
>>> from itertools import islice
>>> extra = [7,27]
>>> be = ['Feed Forage', '', '', '', 'Social Play', '', 'Feed Forage', 'Nonsocial Play', '', 'Nonsocial Play', '', '', '', '', 'Nonsocial Play', '', '', '', '', '', '', '', '', 'Social Play', '', '', '', '', '', '', '', '', 'Nonsocial Play', 'Groom', 'Feed Forage', '', '', 'Nonsocial Play', '', '', 'Feed Forage', '', 'Feed Forage', '', 'Feed Forage', '', 'Social Play', '', 'Social Play', '', '', 'Social Play', '', '', '', '', '', 'Feed Forage', '', '', '', '', 'Feed Forage', '', '', '', '', 'Feed Forage', '', '', 'Feed Forage', '', '', '', '', '', 'Feed Forage', '', '', '', 'Groom', 'Groom', '', '', '', '', 'Groom', 'Groom', 'Groom', '', 'Groom', '', '', '', 'Feed Forage', '', '', 'Feed Forage', 'Nonsocial Play', '', '', '', 'Pace', '', '', '', 'Feed Forage', '', 'Nonsocial Play', '', 'Feed Forage', '', 'Social Play', '', 'Feed Forage', '', 'Social Play', '', 'Social Play', '', '', '', '', '', 'Nonsocial Play', '', 'Social Play', '', '', '', '', 'Feed Forage', '', '', '', '', '', '', '', 'Nonsocial Play', '', 'Nonsocial Play', '', 'Feed Forage', 'Social Play', '', '', '', 'Feed Forage', '', 'Nonsocial Play', '', '', 'Feed Forage', '', '', '', '', 'Self Groom', '', '', 'Groom', '', '', 'Self Groom', '', '', '', '', '', 'Groom', '', '', 'Self Groom', '', '', 'Feed Forage', '', '', '', '', '', 'Pace', '', 'Self Groom', '', '', '', 'Self Groom', '', 'Self Groom', '', 'Social Play', '', 'Social Play', '', 'Self Groom', 'Groom', '', '', 'Groom', '', 'Groom', '', 'Groom', 'Groom', 'Groom', '', '', 'Self Groom', '', 'Groom', '', 'Groom', '', 'Feed Forage', '', 'Feed Forage', '', 'Feed Forage', '', '', '', '', '', '', '', 'Feed Forage', '', '', '', '', 'Feed Forage', 'Nonsocial Play', '', '', 'Self Groom', 'Nonsocial Play', '', '', '', 'Groom', '', '', 'Groom', '', 'Groom', '', '', 'Groom', '', '', 'Groom', '', '', 'Groom', '', '', '', '', '', '', 'Groom', 'Groom', '', 'Groom', '', '', 'Groom', '', '', '', 'Self Groom', '', '', '', '', '', '', 'Groom', '', 'Groom', '', 'Feed Forage', '']
>>> [x for i,x in enumerate(islice(filter(bool, be), min(extra), max(extra)+1), min(extra)) if i in extra]
['Nonsocial Play', 'Groom']
``` | This:
```
[[w for w in be if w != ''][k] for k in extra]
``` |
51,617,624 | I have two lists named `extra` and `be` in my code.
`extra` output is `[7,27]` and
`be` output is
```python
'Feed Forage', '', '', '', 'Social Play', '', 'Feed Forage', 'Nonsocial Play', '', 'Nonsocial Play', '', '', '', '', 'Nonsocial Play', '', '', '', '', '', '', '', '', 'Social Play', '', '', '', '', '', '', '', '', 'Nonsocial Play', 'Groom', 'Feed Forage', '', '', 'Nonsocial Play', '', '', 'Feed Forage', '', 'Feed Forage', '', 'Feed Forage', '', 'Social Play', '', 'Social Play', '', '', 'Social Play', '', '', '', '', '', 'Feed Forage', '', '', '', '', 'Feed Forage', '', '', '', '', 'Feed Forage', '', '', 'Feed Forage', '', '', '', '', '', 'Feed Forage', '', '', '', 'Groom', 'Groom', '', '', '', '', 'Groom', 'Groom', 'Groom', '', 'Groom', '', '', '', 'Feed Forage', '', '', 'Feed Forage', 'Nonsocial Play', '', '', '', 'Pace', '', '', '', 'Feed Forage', '', 'Nonsocial Play', '', 'Feed Forage', '', 'Social Play', '', 'Feed Forage', '', 'Social Play', '', 'Social Play', '', '', '', '', '', 'Nonsocial Play', '', 'Social Play', '', '', '', '', 'Feed Forage', '', '', '', '', '', '', '', 'Nonsocial Play', '', 'Nonsocial Play', '', 'Feed Forage', 'Social Play', '', '', '', 'Feed Forage', '', 'Nonsocial Play', '', '', 'Feed Forage', '', '', '', '', 'Self Groom', '', '', 'Groom', '', '', 'Self Groom', '', '', '', '', '', 'Groom', '', '', 'Self Groom', '', '', 'Feed Forage', '', '', '', '', '', 'Pace', '', 'Self Groom', '', '', '', 'Self Groom', '', 'Self Groom', '', 'Social Play', '', 'Social Play', '', 'Self Groom', 'Groom', '', '', 'Groom', '', 'Groom', '', 'Groom', 'Groom', 'Groom', '', '', 'Self Groom', '', 'Groom', '', 'Groom', '', 'Feed Forage', '', 'Feed Forage', '', 'Feed Forage', '', '', '', '', '', '', '', 'Feed Forage', '', '', '', '', 'Feed Forage', 'Nonsocial Play', '', '', 'Self Groom', 'Nonsocial Play', '', '', '', 'Groom', '', '', 'Groom', '', 'Groom', '', '', 'Groom', '', '', 'Groom', '', '', 'Groom', '', '', '', '', '', '', 'Groom', 'Groom', '', 'Groom', '', '', 'Groom', '', '', '', 'Self Groom', '', '', '', '', '', '', 'Groom', '', 'Groom', '', 'Feed Forage', '']
```
I need to find the 7th and 27th word elements of `extra` (i.e. elements don't count if they are an empty string). It should be `Nonsocial Play` and `Groom` but the for-loop I have only prints `Nonsocial Play`
These are the for-loops I am using:
```
for x in extra:
count = 0
for y in be:
if y != '':
if x == count:
print(be[x])
count += 1
elif x != count:
count += 1
```
If you have any idea why it isn't working, please let me know!
EDIT: I want to print these statements but I also need to delete them | 2018/07/31 | [
"https://Stackoverflow.com/questions/51617624",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10000684/"
] | **Python 2**
```
new_be=filter(lambda a: a != '', be) #we delete from the list all the '' and we save the new list in new_be
world=[]
for i in extra:
world.append(new_be[int(i)])
print (world)
```
**Python 3**
```
new_be=list(filter(("").__ne__, be)) #we delete from the list all the '' and we save the new list in new_be
world=[]
for i in extra:
world.append(new_be[int(i)])
print (world)
```
>
> ['Nonsocial Play', 'Groom']
>
>
> | It isn't working because the indentation isn't correct.It would also be a good idea to include a break once the element is found since you are starting a new count after finding the first element. You are also printing be[x] which wrong. It should be y instead as y is the string you want to print.
```
for x in extra:
count = 0
for y in be:
if y != '':
if x == count:
print(y)
count += 1
break
elif x != count:
count += 1
``` |
51,617,624 | I have two lists named `extra` and `be` in my code.
`extra` output is `[7,27]` and
`be` output is
```python
'Feed Forage', '', '', '', 'Social Play', '', 'Feed Forage', 'Nonsocial Play', '', 'Nonsocial Play', '', '', '', '', 'Nonsocial Play', '', '', '', '', '', '', '', '', 'Social Play', '', '', '', '', '', '', '', '', 'Nonsocial Play', 'Groom', 'Feed Forage', '', '', 'Nonsocial Play', '', '', 'Feed Forage', '', 'Feed Forage', '', 'Feed Forage', '', 'Social Play', '', 'Social Play', '', '', 'Social Play', '', '', '', '', '', 'Feed Forage', '', '', '', '', 'Feed Forage', '', '', '', '', 'Feed Forage', '', '', 'Feed Forage', '', '', '', '', '', 'Feed Forage', '', '', '', 'Groom', 'Groom', '', '', '', '', 'Groom', 'Groom', 'Groom', '', 'Groom', '', '', '', 'Feed Forage', '', '', 'Feed Forage', 'Nonsocial Play', '', '', '', 'Pace', '', '', '', 'Feed Forage', '', 'Nonsocial Play', '', 'Feed Forage', '', 'Social Play', '', 'Feed Forage', '', 'Social Play', '', 'Social Play', '', '', '', '', '', 'Nonsocial Play', '', 'Social Play', '', '', '', '', 'Feed Forage', '', '', '', '', '', '', '', 'Nonsocial Play', '', 'Nonsocial Play', '', 'Feed Forage', 'Social Play', '', '', '', 'Feed Forage', '', 'Nonsocial Play', '', '', 'Feed Forage', '', '', '', '', 'Self Groom', '', '', 'Groom', '', '', 'Self Groom', '', '', '', '', '', 'Groom', '', '', 'Self Groom', '', '', 'Feed Forage', '', '', '', '', '', 'Pace', '', 'Self Groom', '', '', '', 'Self Groom', '', 'Self Groom', '', 'Social Play', '', 'Social Play', '', 'Self Groom', 'Groom', '', '', 'Groom', '', 'Groom', '', 'Groom', 'Groom', 'Groom', '', '', 'Self Groom', '', 'Groom', '', 'Groom', '', 'Feed Forage', '', 'Feed Forage', '', 'Feed Forage', '', '', '', '', '', '', '', 'Feed Forage', '', '', '', '', 'Feed Forage', 'Nonsocial Play', '', '', 'Self Groom', 'Nonsocial Play', '', '', '', 'Groom', '', '', 'Groom', '', 'Groom', '', '', 'Groom', '', '', 'Groom', '', '', 'Groom', '', '', '', '', '', '', 'Groom', 'Groom', '', 'Groom', '', '', 'Groom', '', '', '', 'Self Groom', '', '', '', '', '', '', 'Groom', '', 'Groom', '', 'Feed Forage', '']
```
I need to find the 7th and 27th word elements of `extra` (i.e. elements don't count if they are an empty string). It should be `Nonsocial Play` and `Groom` but the for-loop I have only prints `Nonsocial Play`
These are the for-loops I am using:
```
for x in extra:
count = 0
for y in be:
if y != '':
if x == count:
print(be[x])
count += 1
elif x != count:
count += 1
```
If you have any idea why it isn't working, please let me know!
EDIT: I want to print these statements but I also need to delete them | 2018/07/31 | [
"https://Stackoverflow.com/questions/51617624",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10000684/"
] | You can also just do
```
extra = [7,27]
be = ['Feed Forage', '', '', '', 'Social Play', '', 'Feed Forage', 'Nonsocial Play', '', 'Nonsocial Play', '', '', '', '', 'Nonsocial Play', '', '', '', '', '', '', '', '', 'Social Play', '', '', '', '', '', '', '', '', 'Nonsocial Play', 'Groom', 'Feed Forage', '', '', 'Nonsocial Play', '', '', 'Feed Forage', '', 'Feed Forage', '', 'Feed Forage', '', 'Social Play', '', 'Social Play', '', '', 'Social Play', '', '', '', '', '', 'Feed Forage', '', '', '', '', 'Feed Forage', '', '', '', '', 'Feed Forage', '', '', 'Feed Forage', '', '', '', '', '', 'Feed Forage', '', '', '', 'Groom', 'Groom', '', '', '', '', 'Groom', 'Groom', 'Groom', '', 'Groom', '', '', '', 'Feed Forage', '', '', 'Feed Forage', 'Nonsocial Play', '', '', '', 'Pace', '', '', '', 'Feed Forage', '', 'Nonsocial Play', '', 'Feed Forage', '', 'Social Play', '', 'Feed Forage', '', 'Social Play', '', 'Social Play', '', '', '', '', '', 'Nonsocial Play', '', 'Social Play', '', '', '', '', 'Feed Forage', '', '', '', '', '', '', '', 'Nonsocial Play', '', 'Nonsocial Play', '', 'Feed Forage', 'Social Play', '', '', '', 'Feed Forage', '', 'Nonsocial Play', '', '', 'Feed Forage', '', '', '', '', 'Self Groom', '', '', 'Groom', '', '', 'Self Groom', '', '', '', '', '', 'Groom', '', '', 'Self Groom', '', '', 'Feed Forage', '', '', '', '', '', 'Pace', '', 'Self Groom', '', '', '', 'Self Groom', '', 'Self Groom', '', 'Social Play', '', 'Social Play', '', 'Self Groom', 'Groom', '', '', 'Groom', '', 'Groom', '', 'Groom', 'Groom', 'Groom', '', '', 'Self Groom', '', 'Groom', '', 'Groom', '', 'Feed Forage', '', 'Feed Forage', '', 'Feed Forage', '', '', '', '', '', '', '', 'Feed Forage', '', '', '', '', 'Feed Forage', 'Nonsocial Play', '', '', 'Self Groom', 'Nonsocial Play', '', '', '', 'Groom', '', '', 'Groom', '', 'Groom', '', '', 'Groom', '', '', 'Groom', '', '', 'Groom', '', '', '', '', '', '', 'Groom', 'Groom', '', 'Groom', '', '', 'Groom', '', '', '', 'Self Groom', '', '', '', '', '', '', 'Groom', '', 'Groom', '', 'Feed Forage', '']
>>> [x for i, x in enumerate(s for s in be if s) if i in extra]
['Nonsocial Play', 'Groom']
``` | This:
```
[[w for w in be if w != ''][k] for k in extra]
``` |
51,617,624 | I have two lists named `extra` and `be` in my code.
`extra` output is `[7,27]` and
`be` output is
```python
'Feed Forage', '', '', '', 'Social Play', '', 'Feed Forage', 'Nonsocial Play', '', 'Nonsocial Play', '', '', '', '', 'Nonsocial Play', '', '', '', '', '', '', '', '', 'Social Play', '', '', '', '', '', '', '', '', 'Nonsocial Play', 'Groom', 'Feed Forage', '', '', 'Nonsocial Play', '', '', 'Feed Forage', '', 'Feed Forage', '', 'Feed Forage', '', 'Social Play', '', 'Social Play', '', '', 'Social Play', '', '', '', '', '', 'Feed Forage', '', '', '', '', 'Feed Forage', '', '', '', '', 'Feed Forage', '', '', 'Feed Forage', '', '', '', '', '', 'Feed Forage', '', '', '', 'Groom', 'Groom', '', '', '', '', 'Groom', 'Groom', 'Groom', '', 'Groom', '', '', '', 'Feed Forage', '', '', 'Feed Forage', 'Nonsocial Play', '', '', '', 'Pace', '', '', '', 'Feed Forage', '', 'Nonsocial Play', '', 'Feed Forage', '', 'Social Play', '', 'Feed Forage', '', 'Social Play', '', 'Social Play', '', '', '', '', '', 'Nonsocial Play', '', 'Social Play', '', '', '', '', 'Feed Forage', '', '', '', '', '', '', '', 'Nonsocial Play', '', 'Nonsocial Play', '', 'Feed Forage', 'Social Play', '', '', '', 'Feed Forage', '', 'Nonsocial Play', '', '', 'Feed Forage', '', '', '', '', 'Self Groom', '', '', 'Groom', '', '', 'Self Groom', '', '', '', '', '', 'Groom', '', '', 'Self Groom', '', '', 'Feed Forage', '', '', '', '', '', 'Pace', '', 'Self Groom', '', '', '', 'Self Groom', '', 'Self Groom', '', 'Social Play', '', 'Social Play', '', 'Self Groom', 'Groom', '', '', 'Groom', '', 'Groom', '', 'Groom', 'Groom', 'Groom', '', '', 'Self Groom', '', 'Groom', '', 'Groom', '', 'Feed Forage', '', 'Feed Forage', '', 'Feed Forage', '', '', '', '', '', '', '', 'Feed Forage', '', '', '', '', 'Feed Forage', 'Nonsocial Play', '', '', 'Self Groom', 'Nonsocial Play', '', '', '', 'Groom', '', '', 'Groom', '', 'Groom', '', '', 'Groom', '', '', 'Groom', '', '', 'Groom', '', '', '', '', '', '', 'Groom', 'Groom', '', 'Groom', '', '', 'Groom', '', '', '', 'Self Groom', '', '', '', '', '', '', 'Groom', '', 'Groom', '', 'Feed Forage', '']
```
I need to find the 7th and 27th word elements of `extra` (i.e. elements don't count if they are an empty string). It should be `Nonsocial Play` and `Groom` but the for-loop I have only prints `Nonsocial Play`
These are the for-loops I am using:
```
for x in extra:
count = 0
for y in be:
if y != '':
if x == count:
print(be[x])
count += 1
elif x != count:
count += 1
```
If you have any idea why it isn't working, please let me know!
EDIT: I want to print these statements but I also need to delete them | 2018/07/31 | [
"https://Stackoverflow.com/questions/51617624",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10000684/"
] | You can also just do
```
extra = [7,27]
be = ['Feed Forage', '', '', '', 'Social Play', '', 'Feed Forage', 'Nonsocial Play', '', 'Nonsocial Play', '', '', '', '', 'Nonsocial Play', '', '', '', '', '', '', '', '', 'Social Play', '', '', '', '', '', '', '', '', 'Nonsocial Play', 'Groom', 'Feed Forage', '', '', 'Nonsocial Play', '', '', 'Feed Forage', '', 'Feed Forage', '', 'Feed Forage', '', 'Social Play', '', 'Social Play', '', '', 'Social Play', '', '', '', '', '', 'Feed Forage', '', '', '', '', 'Feed Forage', '', '', '', '', 'Feed Forage', '', '', 'Feed Forage', '', '', '', '', '', 'Feed Forage', '', '', '', 'Groom', 'Groom', '', '', '', '', 'Groom', 'Groom', 'Groom', '', 'Groom', '', '', '', 'Feed Forage', '', '', 'Feed Forage', 'Nonsocial Play', '', '', '', 'Pace', '', '', '', 'Feed Forage', '', 'Nonsocial Play', '', 'Feed Forage', '', 'Social Play', '', 'Feed Forage', '', 'Social Play', '', 'Social Play', '', '', '', '', '', 'Nonsocial Play', '', 'Social Play', '', '', '', '', 'Feed Forage', '', '', '', '', '', '', '', 'Nonsocial Play', '', 'Nonsocial Play', '', 'Feed Forage', 'Social Play', '', '', '', 'Feed Forage', '', 'Nonsocial Play', '', '', 'Feed Forage', '', '', '', '', 'Self Groom', '', '', 'Groom', '', '', 'Self Groom', '', '', '', '', '', 'Groom', '', '', 'Self Groom', '', '', 'Feed Forage', '', '', '', '', '', 'Pace', '', 'Self Groom', '', '', '', 'Self Groom', '', 'Self Groom', '', 'Social Play', '', 'Social Play', '', 'Self Groom', 'Groom', '', '', 'Groom', '', 'Groom', '', 'Groom', 'Groom', 'Groom', '', '', 'Self Groom', '', 'Groom', '', 'Groom', '', 'Feed Forage', '', 'Feed Forage', '', 'Feed Forage', '', '', '', '', '', '', '', 'Feed Forage', '', '', '', '', 'Feed Forage', 'Nonsocial Play', '', '', 'Self Groom', 'Nonsocial Play', '', '', '', 'Groom', '', '', 'Groom', '', 'Groom', '', '', 'Groom', '', '', 'Groom', '', '', 'Groom', '', '', '', '', '', '', 'Groom', 'Groom', '', 'Groom', '', '', 'Groom', '', '', '', 'Self Groom', '', '', '', '', '', '', 'Groom', '', 'Groom', '', 'Feed Forage', '']
>>> [x for i, x in enumerate(s for s in be if s) if i in extra]
['Nonsocial Play', 'Groom']
``` | When the `count` reaches `x`, print the *current* item from `be`
```
for x in extra:
count = 0
for y in be:
if y != '':
if x == count:
print(y)
#print(be[x])
count += 1
elif x != count:
count += 1
```
---
Deleting items from a sequence while iterating over it doesn't work.
Make [deques](https://docs.python.org/3/library/collections.html#collections.deque) of `extra` and `be` and use the rotate method to *visit* the items in `be`. Design the logic so that `be` items are popped off when they meet the criteria and `extra` items are popped off when a `be` item is found. Keep track of rotations so the order can be reconstructed.
```
extra.sort()
extraa = collections.deque(extra)
bee = collections.deque(be)
#print(len(bee))
rotation_count = 0
word_count = 0
while extraa:
while bee[0] == '':
bee.rotate(-1)
rotation_count += 1
if word_count == extraa[0]:
print(bee.popleft())
extraa.popleft()
else:
bee.rotate(-1)
rotation_count += 1
word_count += 1
#print(len(bee))
bee.rotate(rotation_count)
be = list(bee)
``` |
51,617,624 | I have two lists named `extra` and `be` in my code.
`extra` output is `[7,27]` and
`be` output is
```python
'Feed Forage', '', '', '', 'Social Play', '', 'Feed Forage', 'Nonsocial Play', '', 'Nonsocial Play', '', '', '', '', 'Nonsocial Play', '', '', '', '', '', '', '', '', 'Social Play', '', '', '', '', '', '', '', '', 'Nonsocial Play', 'Groom', 'Feed Forage', '', '', 'Nonsocial Play', '', '', 'Feed Forage', '', 'Feed Forage', '', 'Feed Forage', '', 'Social Play', '', 'Social Play', '', '', 'Social Play', '', '', '', '', '', 'Feed Forage', '', '', '', '', 'Feed Forage', '', '', '', '', 'Feed Forage', '', '', 'Feed Forage', '', '', '', '', '', 'Feed Forage', '', '', '', 'Groom', 'Groom', '', '', '', '', 'Groom', 'Groom', 'Groom', '', 'Groom', '', '', '', 'Feed Forage', '', '', 'Feed Forage', 'Nonsocial Play', '', '', '', 'Pace', '', '', '', 'Feed Forage', '', 'Nonsocial Play', '', 'Feed Forage', '', 'Social Play', '', 'Feed Forage', '', 'Social Play', '', 'Social Play', '', '', '', '', '', 'Nonsocial Play', '', 'Social Play', '', '', '', '', 'Feed Forage', '', '', '', '', '', '', '', 'Nonsocial Play', '', 'Nonsocial Play', '', 'Feed Forage', 'Social Play', '', '', '', 'Feed Forage', '', 'Nonsocial Play', '', '', 'Feed Forage', '', '', '', '', 'Self Groom', '', '', 'Groom', '', '', 'Self Groom', '', '', '', '', '', 'Groom', '', '', 'Self Groom', '', '', 'Feed Forage', '', '', '', '', '', 'Pace', '', 'Self Groom', '', '', '', 'Self Groom', '', 'Self Groom', '', 'Social Play', '', 'Social Play', '', 'Self Groom', 'Groom', '', '', 'Groom', '', 'Groom', '', 'Groom', 'Groom', 'Groom', '', '', 'Self Groom', '', 'Groom', '', 'Groom', '', 'Feed Forage', '', 'Feed Forage', '', 'Feed Forage', '', '', '', '', '', '', '', 'Feed Forage', '', '', '', '', 'Feed Forage', 'Nonsocial Play', '', '', 'Self Groom', 'Nonsocial Play', '', '', '', 'Groom', '', '', 'Groom', '', 'Groom', '', '', 'Groom', '', '', 'Groom', '', '', 'Groom', '', '', '', '', '', '', 'Groom', 'Groom', '', 'Groom', '', '', 'Groom', '', '', '', 'Self Groom', '', '', '', '', '', '', 'Groom', '', 'Groom', '', 'Feed Forage', '']
```
I need to find the 7th and 27th word elements of `extra` (i.e. elements don't count if they are an empty string). It should be `Nonsocial Play` and `Groom` but the for-loop I have only prints `Nonsocial Play`
These are the for-loops I am using:
```
for x in extra:
count = 0
for y in be:
if y != '':
if x == count:
print(be[x])
count += 1
elif x != count:
count += 1
```
If you have any idea why it isn't working, please let me know!
EDIT: I want to print these statements but I also need to delete them | 2018/07/31 | [
"https://Stackoverflow.com/questions/51617624",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10000684/"
] | When the `count` reaches `x`, print the *current* item from `be`
```
for x in extra:
count = 0
for y in be:
if y != '':
if x == count:
print(y)
#print(be[x])
count += 1
elif x != count:
count += 1
```
---
Deleting items from a sequence while iterating over it doesn't work.
Make [deques](https://docs.python.org/3/library/collections.html#collections.deque) of `extra` and `be` and use the rotate method to *visit* the items in `be`. Design the logic so that `be` items are popped off when they meet the criteria and `extra` items are popped off when a `be` item is found. Keep track of rotations so the order can be reconstructed.
```
extra.sort()
extraa = collections.deque(extra)
bee = collections.deque(be)
#print(len(bee))
rotation_count = 0
word_count = 0
while extraa:
while bee[0] == '':
bee.rotate(-1)
rotation_count += 1
if word_count == extraa[0]:
print(bee.popleft())
extraa.popleft()
else:
bee.rotate(-1)
rotation_count += 1
word_count += 1
#print(len(bee))
bee.rotate(rotation_count)
be = list(bee)
``` | This:
```
[[w for w in be if w != ''][k] for k in extra]
``` |
51,617,624 | I have two lists named `extra` and `be` in my code.
`extra` output is `[7,27]` and
`be` output is
```python
'Feed Forage', '', '', '', 'Social Play', '', 'Feed Forage', 'Nonsocial Play', '', 'Nonsocial Play', '', '', '', '', 'Nonsocial Play', '', '', '', '', '', '', '', '', 'Social Play', '', '', '', '', '', '', '', '', 'Nonsocial Play', 'Groom', 'Feed Forage', '', '', 'Nonsocial Play', '', '', 'Feed Forage', '', 'Feed Forage', '', 'Feed Forage', '', 'Social Play', '', 'Social Play', '', '', 'Social Play', '', '', '', '', '', 'Feed Forage', '', '', '', '', 'Feed Forage', '', '', '', '', 'Feed Forage', '', '', 'Feed Forage', '', '', '', '', '', 'Feed Forage', '', '', '', 'Groom', 'Groom', '', '', '', '', 'Groom', 'Groom', 'Groom', '', 'Groom', '', '', '', 'Feed Forage', '', '', 'Feed Forage', 'Nonsocial Play', '', '', '', 'Pace', '', '', '', 'Feed Forage', '', 'Nonsocial Play', '', 'Feed Forage', '', 'Social Play', '', 'Feed Forage', '', 'Social Play', '', 'Social Play', '', '', '', '', '', 'Nonsocial Play', '', 'Social Play', '', '', '', '', 'Feed Forage', '', '', '', '', '', '', '', 'Nonsocial Play', '', 'Nonsocial Play', '', 'Feed Forage', 'Social Play', '', '', '', 'Feed Forage', '', 'Nonsocial Play', '', '', 'Feed Forage', '', '', '', '', 'Self Groom', '', '', 'Groom', '', '', 'Self Groom', '', '', '', '', '', 'Groom', '', '', 'Self Groom', '', '', 'Feed Forage', '', '', '', '', '', 'Pace', '', 'Self Groom', '', '', '', 'Self Groom', '', 'Self Groom', '', 'Social Play', '', 'Social Play', '', 'Self Groom', 'Groom', '', '', 'Groom', '', 'Groom', '', 'Groom', 'Groom', 'Groom', '', '', 'Self Groom', '', 'Groom', '', 'Groom', '', 'Feed Forage', '', 'Feed Forage', '', 'Feed Forage', '', '', '', '', '', '', '', 'Feed Forage', '', '', '', '', 'Feed Forage', 'Nonsocial Play', '', '', 'Self Groom', 'Nonsocial Play', '', '', '', 'Groom', '', '', 'Groom', '', 'Groom', '', '', 'Groom', '', '', 'Groom', '', '', 'Groom', '', '', '', '', '', '', 'Groom', 'Groom', '', 'Groom', '', '', 'Groom', '', '', '', 'Self Groom', '', '', '', '', '', '', 'Groom', '', 'Groom', '', 'Feed Forage', '']
```
I need to find the 7th and 27th word elements of `extra` (i.e. elements don't count if they are an empty string). It should be `Nonsocial Play` and `Groom` but the for-loop I have only prints `Nonsocial Play`
These are the for-loops I am using:
```
for x in extra:
count = 0
for y in be:
if y != '':
if x == count:
print(be[x])
count += 1
elif x != count:
count += 1
```
If you have any idea why it isn't working, please let me know!
EDIT: I want to print these statements but I also need to delete them | 2018/07/31 | [
"https://Stackoverflow.com/questions/51617624",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10000684/"
] | I created simple function `filter_iter(itr)` that filters the iterable in argument `itr` from any empty values. Then you can access the resulting filtered list with values from list `extra`:
```
extra = [7,27]
be = ['Feed Forage', '', '', '', 'Social Play', '', 'Feed Forage', 'Nonsocial Play', '', 'Nonsocial Play', '', '', '', '', 'Nonsocial Play', '', '', '', '', '', '', '', '', 'Social Play', '', '', '', '', '', '', '', '', 'Nonsocial Play', 'Groom', 'Feed Forage', '', '', 'Nonsocial Play', '', '', 'Feed Forage', '', 'Feed Forage', '', 'Feed Forage', '', 'Social Play', '', 'Social Play', '', '', 'Social Play', '', '', '', '', '', 'Feed Forage', '', '', '', '', 'Feed Forage', '', '', '', '', 'Feed Forage', '', '', 'Feed Forage', '', '', '', '', '', 'Feed Forage', '', '', '', 'Groom', 'Groom', '', '', '', '', 'Groom', 'Groom', 'Groom', '', 'Groom', '', '', '', 'Feed Forage', '', '', 'Feed Forage', 'Nonsocial Play', '', '', '', 'Pace', '', '', '', 'Feed Forage', '', 'Nonsocial Play', '', 'Feed Forage', '', 'Social Play', '', 'Feed Forage', '', 'Social Play', '', 'Social Play', '', '', '', '', '', 'Nonsocial Play', '', 'Social Play', '', '', '', '', 'Feed Forage', '', '', '', '', '', '', '', 'Nonsocial Play', '', 'Nonsocial Play', '', 'Feed Forage', 'Social Play', '', '', '', 'Feed Forage', '', 'Nonsocial Play', '', '', 'Feed Forage', '', '', '', '', 'Self Groom', '', '', 'Groom', '', '', 'Self Groom', '', '', '', '', '', 'Groom', '', '', 'Self Groom', '', '', 'Feed Forage', '', '', '', '', '', 'Pace', '', 'Self Groom', '', '', '', 'Self Groom', '', 'Self Groom', '', 'Social Play', '', 'Social Play', '', 'Self Groom', 'Groom', '', '', 'Groom', '', 'Groom', '', 'Groom', 'Groom', 'Groom', '', '', 'Self Groom', '', 'Groom', '', 'Groom', '', 'Feed Forage', '', 'Feed Forage', '', 'Feed Forage', '', '', '', '', '', '', '', 'Feed Forage', '', '', '', '', 'Feed Forage', 'Nonsocial Play', '', '', 'Self Groom', 'Nonsocial Play', '', '', '', 'Groom', '', '', 'Groom', '', 'Groom', '', '', 'Groom', '', '', 'Groom', '', '', 'Groom', '', '', '', '', '', '', 'Groom', 'Groom', '', 'Groom', '', '', 'Groom', '', '', '', 'Self Groom', '', '', '', '', '', '', 'Groom', '', 'Groom', '', 'Feed Forage', '']
def filter_iter(itr):
return [i for i in itr if i]
be = filter_iter(be)
print([be[e] for e in extra])
```
Prints:
```
['Nonsocial Play', 'Groom']
``` | This:
```
[[w for w in be if w != ''][k] for k in extra]
``` |
51,617,624 | I have two lists named `extra` and `be` in my code.
`extra` output is `[7,27]` and
`be` output is
```python
'Feed Forage', '', '', '', 'Social Play', '', 'Feed Forage', 'Nonsocial Play', '', 'Nonsocial Play', '', '', '', '', 'Nonsocial Play', '', '', '', '', '', '', '', '', 'Social Play', '', '', '', '', '', '', '', '', 'Nonsocial Play', 'Groom', 'Feed Forage', '', '', 'Nonsocial Play', '', '', 'Feed Forage', '', 'Feed Forage', '', 'Feed Forage', '', 'Social Play', '', 'Social Play', '', '', 'Social Play', '', '', '', '', '', 'Feed Forage', '', '', '', '', 'Feed Forage', '', '', '', '', 'Feed Forage', '', '', 'Feed Forage', '', '', '', '', '', 'Feed Forage', '', '', '', 'Groom', 'Groom', '', '', '', '', 'Groom', 'Groom', 'Groom', '', 'Groom', '', '', '', 'Feed Forage', '', '', 'Feed Forage', 'Nonsocial Play', '', '', '', 'Pace', '', '', '', 'Feed Forage', '', 'Nonsocial Play', '', 'Feed Forage', '', 'Social Play', '', 'Feed Forage', '', 'Social Play', '', 'Social Play', '', '', '', '', '', 'Nonsocial Play', '', 'Social Play', '', '', '', '', 'Feed Forage', '', '', '', '', '', '', '', 'Nonsocial Play', '', 'Nonsocial Play', '', 'Feed Forage', 'Social Play', '', '', '', 'Feed Forage', '', 'Nonsocial Play', '', '', 'Feed Forage', '', '', '', '', 'Self Groom', '', '', 'Groom', '', '', 'Self Groom', '', '', '', '', '', 'Groom', '', '', 'Self Groom', '', '', 'Feed Forage', '', '', '', '', '', 'Pace', '', 'Self Groom', '', '', '', 'Self Groom', '', 'Self Groom', '', 'Social Play', '', 'Social Play', '', 'Self Groom', 'Groom', '', '', 'Groom', '', 'Groom', '', 'Groom', 'Groom', 'Groom', '', '', 'Self Groom', '', 'Groom', '', 'Groom', '', 'Feed Forage', '', 'Feed Forage', '', 'Feed Forage', '', '', '', '', '', '', '', 'Feed Forage', '', '', '', '', 'Feed Forage', 'Nonsocial Play', '', '', 'Self Groom', 'Nonsocial Play', '', '', '', 'Groom', '', '', 'Groom', '', 'Groom', '', '', 'Groom', '', '', 'Groom', '', '', 'Groom', '', '', '', '', '', '', 'Groom', 'Groom', '', 'Groom', '', '', 'Groom', '', '', '', 'Self Groom', '', '', '', '', '', '', 'Groom', '', 'Groom', '', 'Feed Forage', '']
```
I need to find the 7th and 27th word elements of `extra` (i.e. elements don't count if they are an empty string). It should be `Nonsocial Play` and `Groom` but the for-loop I have only prints `Nonsocial Play`
These are the for-loops I am using:
```
for x in extra:
count = 0
for y in be:
if y != '':
if x == count:
print(be[x])
count += 1
elif x != count:
count += 1
```
If you have any idea why it isn't working, please let me know!
EDIT: I want to print these statements but I also need to delete them | 2018/07/31 | [
"https://Stackoverflow.com/questions/51617624",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10000684/"
] | Here is a solution using using `filter` the elements, `enumerate` to iterate over the resulting iterator along with its index, and `itertools.islice` to get only certain range of indexes from it
```
>>> from itertools import islice
>>> extra = [7,27]
>>> be = ['Feed Forage', '', '', '', 'Social Play', '', 'Feed Forage', 'Nonsocial Play', '', 'Nonsocial Play', '', '', '', '', 'Nonsocial Play', '', '', '', '', '', '', '', '', 'Social Play', '', '', '', '', '', '', '', '', 'Nonsocial Play', 'Groom', 'Feed Forage', '', '', 'Nonsocial Play', '', '', 'Feed Forage', '', 'Feed Forage', '', 'Feed Forage', '', 'Social Play', '', 'Social Play', '', '', 'Social Play', '', '', '', '', '', 'Feed Forage', '', '', '', '', 'Feed Forage', '', '', '', '', 'Feed Forage', '', '', 'Feed Forage', '', '', '', '', '', 'Feed Forage', '', '', '', 'Groom', 'Groom', '', '', '', '', 'Groom', 'Groom', 'Groom', '', 'Groom', '', '', '', 'Feed Forage', '', '', 'Feed Forage', 'Nonsocial Play', '', '', '', 'Pace', '', '', '', 'Feed Forage', '', 'Nonsocial Play', '', 'Feed Forage', '', 'Social Play', '', 'Feed Forage', '', 'Social Play', '', 'Social Play', '', '', '', '', '', 'Nonsocial Play', '', 'Social Play', '', '', '', '', 'Feed Forage', '', '', '', '', '', '', '', 'Nonsocial Play', '', 'Nonsocial Play', '', 'Feed Forage', 'Social Play', '', '', '', 'Feed Forage', '', 'Nonsocial Play', '', '', 'Feed Forage', '', '', '', '', 'Self Groom', '', '', 'Groom', '', '', 'Self Groom', '', '', '', '', '', 'Groom', '', '', 'Self Groom', '', '', 'Feed Forage', '', '', '', '', '', 'Pace', '', 'Self Groom', '', '', '', 'Self Groom', '', 'Self Groom', '', 'Social Play', '', 'Social Play', '', 'Self Groom', 'Groom', '', '', 'Groom', '', 'Groom', '', 'Groom', 'Groom', 'Groom', '', '', 'Self Groom', '', 'Groom', '', 'Groom', '', 'Feed Forage', '', 'Feed Forage', '', 'Feed Forage', '', '', '', '', '', '', '', 'Feed Forage', '', '', '', '', 'Feed Forage', 'Nonsocial Play', '', '', 'Self Groom', 'Nonsocial Play', '', '', '', 'Groom', '', '', 'Groom', '', 'Groom', '', '', 'Groom', '', '', 'Groom', '', '', 'Groom', '', '', '', '', '', '', 'Groom', 'Groom', '', 'Groom', '', '', 'Groom', '', '', '', 'Self Groom', '', '', '', '', '', '', 'Groom', '', 'Groom', '', 'Feed Forage', '']
>>> [x for i,x in enumerate(islice(filter(bool, be), min(extra), max(extra)+1), min(extra)) if i in extra]
['Nonsocial Play', 'Groom']
``` | It isn't working because the indentation isn't correct.It would also be a good idea to include a break once the element is found since you are starting a new count after finding the first element. You are also printing be[x] which wrong. It should be y instead as y is the string you want to print.
```
for x in extra:
count = 0
for y in be:
if y != '':
if x == count:
print(y)
count += 1
break
elif x != count:
count += 1
``` |
51,617,624 | I have two lists named `extra` and `be` in my code.
`extra` output is `[7,27]` and
`be` output is
```python
'Feed Forage', '', '', '', 'Social Play', '', 'Feed Forage', 'Nonsocial Play', '', 'Nonsocial Play', '', '', '', '', 'Nonsocial Play', '', '', '', '', '', '', '', '', 'Social Play', '', '', '', '', '', '', '', '', 'Nonsocial Play', 'Groom', 'Feed Forage', '', '', 'Nonsocial Play', '', '', 'Feed Forage', '', 'Feed Forage', '', 'Feed Forage', '', 'Social Play', '', 'Social Play', '', '', 'Social Play', '', '', '', '', '', 'Feed Forage', '', '', '', '', 'Feed Forage', '', '', '', '', 'Feed Forage', '', '', 'Feed Forage', '', '', '', '', '', 'Feed Forage', '', '', '', 'Groom', 'Groom', '', '', '', '', 'Groom', 'Groom', 'Groom', '', 'Groom', '', '', '', 'Feed Forage', '', '', 'Feed Forage', 'Nonsocial Play', '', '', '', 'Pace', '', '', '', 'Feed Forage', '', 'Nonsocial Play', '', 'Feed Forage', '', 'Social Play', '', 'Feed Forage', '', 'Social Play', '', 'Social Play', '', '', '', '', '', 'Nonsocial Play', '', 'Social Play', '', '', '', '', 'Feed Forage', '', '', '', '', '', '', '', 'Nonsocial Play', '', 'Nonsocial Play', '', 'Feed Forage', 'Social Play', '', '', '', 'Feed Forage', '', 'Nonsocial Play', '', '', 'Feed Forage', '', '', '', '', 'Self Groom', '', '', 'Groom', '', '', 'Self Groom', '', '', '', '', '', 'Groom', '', '', 'Self Groom', '', '', 'Feed Forage', '', '', '', '', '', 'Pace', '', 'Self Groom', '', '', '', 'Self Groom', '', 'Self Groom', '', 'Social Play', '', 'Social Play', '', 'Self Groom', 'Groom', '', '', 'Groom', '', 'Groom', '', 'Groom', 'Groom', 'Groom', '', '', 'Self Groom', '', 'Groom', '', 'Groom', '', 'Feed Forage', '', 'Feed Forage', '', 'Feed Forage', '', '', '', '', '', '', '', 'Feed Forage', '', '', '', '', 'Feed Forage', 'Nonsocial Play', '', '', 'Self Groom', 'Nonsocial Play', '', '', '', 'Groom', '', '', 'Groom', '', 'Groom', '', '', 'Groom', '', '', 'Groom', '', '', 'Groom', '', '', '', '', '', '', 'Groom', 'Groom', '', 'Groom', '', '', 'Groom', '', '', '', 'Self Groom', '', '', '', '', '', '', 'Groom', '', 'Groom', '', 'Feed Forage', '']
```
I need to find the 7th and 27th word elements of `extra` (i.e. elements don't count if they are an empty string). It should be `Nonsocial Play` and `Groom` but the for-loop I have only prints `Nonsocial Play`
These are the for-loops I am using:
```
for x in extra:
count = 0
for y in be:
if y != '':
if x == count:
print(be[x])
count += 1
elif x != count:
count += 1
```
If you have any idea why it isn't working, please let me know!
EDIT: I want to print these statements but I also need to delete them | 2018/07/31 | [
"https://Stackoverflow.com/questions/51617624",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10000684/"
] | I created simple function `filter_iter(itr)` that filters the iterable in argument `itr` from any empty values. Then you can access the resulting filtered list with values from list `extra`:
```
extra = [7,27]
be = ['Feed Forage', '', '', '', 'Social Play', '', 'Feed Forage', 'Nonsocial Play', '', 'Nonsocial Play', '', '', '', '', 'Nonsocial Play', '', '', '', '', '', '', '', '', 'Social Play', '', '', '', '', '', '', '', '', 'Nonsocial Play', 'Groom', 'Feed Forage', '', '', 'Nonsocial Play', '', '', 'Feed Forage', '', 'Feed Forage', '', 'Feed Forage', '', 'Social Play', '', 'Social Play', '', '', 'Social Play', '', '', '', '', '', 'Feed Forage', '', '', '', '', 'Feed Forage', '', '', '', '', 'Feed Forage', '', '', 'Feed Forage', '', '', '', '', '', 'Feed Forage', '', '', '', 'Groom', 'Groom', '', '', '', '', 'Groom', 'Groom', 'Groom', '', 'Groom', '', '', '', 'Feed Forage', '', '', 'Feed Forage', 'Nonsocial Play', '', '', '', 'Pace', '', '', '', 'Feed Forage', '', 'Nonsocial Play', '', 'Feed Forage', '', 'Social Play', '', 'Feed Forage', '', 'Social Play', '', 'Social Play', '', '', '', '', '', 'Nonsocial Play', '', 'Social Play', '', '', '', '', 'Feed Forage', '', '', '', '', '', '', '', 'Nonsocial Play', '', 'Nonsocial Play', '', 'Feed Forage', 'Social Play', '', '', '', 'Feed Forage', '', 'Nonsocial Play', '', '', 'Feed Forage', '', '', '', '', 'Self Groom', '', '', 'Groom', '', '', 'Self Groom', '', '', '', '', '', 'Groom', '', '', 'Self Groom', '', '', 'Feed Forage', '', '', '', '', '', 'Pace', '', 'Self Groom', '', '', '', 'Self Groom', '', 'Self Groom', '', 'Social Play', '', 'Social Play', '', 'Self Groom', 'Groom', '', '', 'Groom', '', 'Groom', '', 'Groom', 'Groom', 'Groom', '', '', 'Self Groom', '', 'Groom', '', 'Groom', '', 'Feed Forage', '', 'Feed Forage', '', 'Feed Forage', '', '', '', '', '', '', '', 'Feed Forage', '', '', '', '', 'Feed Forage', 'Nonsocial Play', '', '', 'Self Groom', 'Nonsocial Play', '', '', '', 'Groom', '', '', 'Groom', '', 'Groom', '', '', 'Groom', '', '', 'Groom', '', '', 'Groom', '', '', '', '', '', '', 'Groom', 'Groom', '', 'Groom', '', '', 'Groom', '', '', '', 'Self Groom', '', '', '', '', '', '', 'Groom', '', 'Groom', '', 'Feed Forage', '']
def filter_iter(itr):
return [i for i in itr if i]
be = filter_iter(be)
print([be[e] for e in extra])
```
Prints:
```
['Nonsocial Play', 'Groom']
``` | Here is a solution using using `filter` the elements, `enumerate` to iterate over the resulting iterator along with its index, and `itertools.islice` to get only certain range of indexes from it
```
>>> from itertools import islice
>>> extra = [7,27]
>>> be = ['Feed Forage', '', '', '', 'Social Play', '', 'Feed Forage', 'Nonsocial Play', '', 'Nonsocial Play', '', '', '', '', 'Nonsocial Play', '', '', '', '', '', '', '', '', 'Social Play', '', '', '', '', '', '', '', '', 'Nonsocial Play', 'Groom', 'Feed Forage', '', '', 'Nonsocial Play', '', '', 'Feed Forage', '', 'Feed Forage', '', 'Feed Forage', '', 'Social Play', '', 'Social Play', '', '', 'Social Play', '', '', '', '', '', 'Feed Forage', '', '', '', '', 'Feed Forage', '', '', '', '', 'Feed Forage', '', '', 'Feed Forage', '', '', '', '', '', 'Feed Forage', '', '', '', 'Groom', 'Groom', '', '', '', '', 'Groom', 'Groom', 'Groom', '', 'Groom', '', '', '', 'Feed Forage', '', '', 'Feed Forage', 'Nonsocial Play', '', '', '', 'Pace', '', '', '', 'Feed Forage', '', 'Nonsocial Play', '', 'Feed Forage', '', 'Social Play', '', 'Feed Forage', '', 'Social Play', '', 'Social Play', '', '', '', '', '', 'Nonsocial Play', '', 'Social Play', '', '', '', '', 'Feed Forage', '', '', '', '', '', '', '', 'Nonsocial Play', '', 'Nonsocial Play', '', 'Feed Forage', 'Social Play', '', '', '', 'Feed Forage', '', 'Nonsocial Play', '', '', 'Feed Forage', '', '', '', '', 'Self Groom', '', '', 'Groom', '', '', 'Self Groom', '', '', '', '', '', 'Groom', '', '', 'Self Groom', '', '', 'Feed Forage', '', '', '', '', '', 'Pace', '', 'Self Groom', '', '', '', 'Self Groom', '', 'Self Groom', '', 'Social Play', '', 'Social Play', '', 'Self Groom', 'Groom', '', '', 'Groom', '', 'Groom', '', 'Groom', 'Groom', 'Groom', '', '', 'Self Groom', '', 'Groom', '', 'Groom', '', 'Feed Forage', '', 'Feed Forage', '', 'Feed Forage', '', '', '', '', '', '', '', 'Feed Forage', '', '', '', '', 'Feed Forage', 'Nonsocial Play', '', '', 'Self Groom', 'Nonsocial Play', '', '', '', 'Groom', '', '', 'Groom', '', 'Groom', '', '', 'Groom', '', '', 'Groom', '', '', 'Groom', '', '', '', '', '', '', 'Groom', 'Groom', '', 'Groom', '', '', 'Groom', '', '', '', 'Self Groom', '', '', '', '', '', '', 'Groom', '', 'Groom', '', 'Feed Forage', '']
>>> [x for i,x in enumerate(islice(filter(bool, be), min(extra), max(extra)+1), min(extra)) if i in extra]
['Nonsocial Play', 'Groom']
``` |
41,269,038 | I have found a code that will predict next values using python scikit-learn linear regression.
I am able to predict single data .. but actually I need to predict 6 values and print the prediction of six values.
Here is the code
```
def linear_model_main(x_parameters, y_parameters, predict_value):
# Create linear regression object
regr = linear_model.LinearRegression()<
regr.fit(x_parameters, y_parameters)
# noinspection PyArgumentList
predict_outcome = regr.predict(predict_value)
score = regr.score(X, Y)
predictions = {'intercept': regr.intercept_, 'coefficient': regr.coef_, 'predicted_value': predict_outcome, 'accuracy' : score}
return predictions
predicted_value = 9 #I NEED TO PREDICT 9,10,11,12,13,14,15
result = linear_model_main(X, Y, predicted_value)
print('Constant Value: {0}'.format(result['intercept']))
print('Coefficient: {0}'.format(result['coefficient']))
print('Predicted Value: {0}'.format(result['predicted_value']))
print('Accuracy: {0}'.format(result['accuracy']))
```
I tried doing like this:
```
predicted_value = {9,10,11,12,13,14,15}
result = linear_model_main(X, Y, predicted_value)
print('Constant Value: '.format(result['intercept']))
print('Coefficient: '.format(result['coefficient']))
print('Predicted Value: '.format(result['predicted_value']))
print('Accuracy: '.format(result['accuracy']))
```
error message is :
```
Traceback (most recent call last):
File "C:Python34\data\cp.py", line 28, in <module>
result = linear_model_main(X, Y, predicted_value)
File "C:Python34\data\cp.py", line 22, in linear_model_main
predict_outcome = regr.predict(predict_value)
File "C:\Python34\lib\site-packages\sklearn\linear_model\base.py", line 200, in predict return self._decision_function(X)
File "C:\Python34\lib\site-packages\sklearn\linear_model\base.py", line 183, in _decision_function
X = check_array(X, accept_sparse=['csr', 'csc', 'coo'])
File "C:\Python34\lib\site-packages\sklearn\utils\validation.py", line 393, in check_array array = array.astype(np.float64)
TypeError: float() argument must be a string or a number, not 'set'
C:\>
```
and
```
predicted_value = 9,10,11,12,13,14,15
result = linear_model_main(X, Y, predicted_value)
print('Constant Value: '.format(result['intercept']))
print('Coefficient: '.format(result['coefficient']))
print('Predicted Value: '.format(result['predicted_value']))
print('Accuracy: '.format(result['accuracy']))
```
got these errors
```
C:\Python34\lib\site-packages\sklearn\utils\validation.py:386: DeprecationWarnin
g: Passing 1d arrays as data is deprecated in 0.17 and willraise ValueError in 0
.19. Reshape your data either using X.reshape(-1, 1) if your data has a single feature or X.reshape(1, -1) if it contains a single sample.
DeprecationWarning)
Traceback (most recent call last):
File "C:Python34\data\cp.py", line 28, in <module>
result = linear_model_main(X, Y, predicted_value)
File "C:Python34\data\cp.py", line 22, in linear_model_main
predict_outcome = regr.predict(predict_value)
File "C:\Python34\lib\site-packages\sklearn\linear_model\base.py", line 200, in predict return self._decision_function(X)
File "C:\Python34\lib\site-packages\sklearn\linear_model\base.py", line 185, in _decision_function dense_output=True) + self.intercept_
File "C:\Python34\lib\site-packages\sklearn\utils\extmath.py", line 184, in safe_sparse_dot return fast_dot(a, b)
ValueError: shapes (1,3) and (1,1) not aligned: 3 (dim 1) != 1 (dim 0)
C:\>
```
and if I make changes like this:
```
predicted_value = 9
result = linear_model_main(X, Y, predicted_value)
print('Constant Value: {1}'.format(result['intercept']))
print('Coefficient: {1}'.format(result['coefficient']))
print('Predicted Value: {}'.format(result['predicted_value']))
print('Accuracy: {1}'.format(result['accuracy']))
```
it will again give me error saying it crosses limit. What has to be done? | 2016/12/21 | [
"https://Stackoverflow.com/questions/41269038",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7302915/"
] | Here is a working example. I have not constructed your functions, just shown you the proper syntax. It looks like you aren't passing the data into `fit` properly.
```
import numpy as np
from sklearn import linear_model
x = np.random.uniform(-2,2,101)
y = 2*x+1 + np.random.normal(0,1, len(x))
#Note that x and y must be in specific shape.
x = x.reshape(-1,1)
y = y.reshape(-1,1)
LM = linear_model.LinearRegression().fit(x,y) #Note I am passing in x and y in column shape
predict_me = np.array([ 9,10,11,12,13,14,15])
predict_me = predict_me.reshape(-1,1)
score = LM.score(x,y)
predicted_values = LM.predict(predict_me)
predictions = {'intercept': LM.intercept_, 'coefficient': LM.coef_, 'predicted_value': predicted_values, 'accuracy' : score}
```
| Regr.predict() is expecting a set with the same shape as X. ([read the docs](http://scikit-learn.org/stable/modules/generated/sklearn.linear_model.LinearRegression.html#sklearn.linear_model.LinearRegression.predict))
Instead of this you are proving a scalar value (9). This is why you are getting the error about the shape of the objects not matching.
You need to predict with an object that has the same number of "columns" as X (although not necessarily the same number of rows) and you'll get back a prediction for each row.
Your predict\_value variable doesn't seem to do anything useful, since Y should contain the labels you are trying to predict for each of the rows of X. |
8,261,654 | I've been evaluating messaging technologies for my company but I've become very confused by the conceptual differences between a few terms:
**Pub/Sub** vs **Multicast** vs **Fan Out**
I am working with the following definitions:
* **Pub/Sub** has publishers delivering a separate copy of each message to
each subscriber which means that the opportunity to guarantee delivery exists
* **Fan Out** has a single queue pushing to all listening
clients.
* **Multicast** just spams out data and if someone is listening
then fine, if not, it doesn't matter. No possibility to guarantee a client definitely gets a message.
Are these definitions right? Or is Pub/Sub the pattern and multicast, direct, fanout etc. ways to acheive the pattern?
I'm trying to work the out-of-the-box RabbitMQ definitions into our architecture but I'm just going around in circles at the moment trying to write the specs for our app.
Please could someone advise me whether I am right? | 2011/11/24 | [
"https://Stackoverflow.com/questions/8261654",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/536546/"
] | I'm confused by your choice of three terms to compare. Within RabbitMQ, Fanout and Direct are exchange types. Pub-Sub is a generic messaging pattern but not an exchange type. And you didn't even mention the 3rd and most important Exchange type, namely Topic. In fact, you can implement Fanout behavior on a Topic exchange just by declaring multiple queues with the same binding key. And you can define Direct behavior on a Topic exchange by declaring a Queue with `*` as the wildcard binding key.
Pub-Sub is generally understood as a pattern in which an application publishes messages which are consumed by several subscribers.
With RabbitMQ/AMQP it is important to remember that messages are always published to exchanges. Then exchanges route to queues. And queues deliver messages to subscribers. The behavior of the exchange is important. In Topic exchanges, the routing key from the publisher is matched up to the binding key from the subscriber in order to make the routing decision. Binding keys can have wildcard patterns which further influences the routing decision. More complicated routing can be [done based on the content of message headers](https://stackoverflow.com/questions/3280676/content-based-routing-with-rabbitmq-and-python) using a headers exchange type
RabbitMQ doesn't guarantee delivery of messages but you can get guaranteed delivery by choosing the right options(delivery mode = 2 for persistent msgs), and declaring exchanges and queues in advance of running your application so that messages are not discarded. | Your definitions are pretty much correct. Note that guaranteed delivery is not limited to pub/sub only, and it can be done with fanout too. And yes, pub/sub is a very basic description which can be realized with specific methods like fanout, direct and so on.
There are more messaging patterns which you might find useful. Have a look at [Enterprise Integration Patterns](http://www.eaipatterns.com/toc.html) for more details. |
8,261,654 | I've been evaluating messaging technologies for my company but I've become very confused by the conceptual differences between a few terms:
**Pub/Sub** vs **Multicast** vs **Fan Out**
I am working with the following definitions:
* **Pub/Sub** has publishers delivering a separate copy of each message to
each subscriber which means that the opportunity to guarantee delivery exists
* **Fan Out** has a single queue pushing to all listening
clients.
* **Multicast** just spams out data and if someone is listening
then fine, if not, it doesn't matter. No possibility to guarantee a client definitely gets a message.
Are these definitions right? Or is Pub/Sub the pattern and multicast, direct, fanout etc. ways to acheive the pattern?
I'm trying to work the out-of-the-box RabbitMQ definitions into our architecture but I'm just going around in circles at the moment trying to write the specs for our app.
Please could someone advise me whether I am right? | 2011/11/24 | [
"https://Stackoverflow.com/questions/8261654",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/536546/"
] | Your definitions are pretty much correct. Note that guaranteed delivery is not limited to pub/sub only, and it can be done with fanout too. And yes, pub/sub is a very basic description which can be realized with specific methods like fanout, direct and so on.
There are more messaging patterns which you might find useful. Have a look at [Enterprise Integration Patterns](http://www.eaipatterns.com/toc.html) for more details. | From an electronic exchange point of view the term “Multicast” means “the message is placed on the wire once” and all client applications that are listening can read the message off the “wire”. Any solution that makes N copies of the message for the N clients is not multicast. In addition to examining the source code one can also use a “sniffer” to determine how many copies of the message is sent over the wire from the messaging system. And yes, multicast messages are a form the UDP protocol message. See: <http://en.wikipedia.org/wiki/Multicast> for a general description. About ten years ago, we used the messaging system from TIBCO that supported multicast. See: <https://docs.tibco.com/pub/ems_openvms_c_client/8.0.0-june-2013/docs/html/tib_ems_users_guide/wwhelp/wwhimpl/common/html/wwhelp.htm#context=tib_ems_users_guide&file=EMS.5.091.htm> |
8,261,654 | I've been evaluating messaging technologies for my company but I've become very confused by the conceptual differences between a few terms:
**Pub/Sub** vs **Multicast** vs **Fan Out**
I am working with the following definitions:
* **Pub/Sub** has publishers delivering a separate copy of each message to
each subscriber which means that the opportunity to guarantee delivery exists
* **Fan Out** has a single queue pushing to all listening
clients.
* **Multicast** just spams out data and if someone is listening
then fine, if not, it doesn't matter. No possibility to guarantee a client definitely gets a message.
Are these definitions right? Or is Pub/Sub the pattern and multicast, direct, fanout etc. ways to acheive the pattern?
I'm trying to work the out-of-the-box RabbitMQ definitions into our architecture but I'm just going around in circles at the moment trying to write the specs for our app.
Please could someone advise me whether I am right? | 2011/11/24 | [
"https://Stackoverflow.com/questions/8261654",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/536546/"
] | I'm confused by your choice of three terms to compare. Within RabbitMQ, Fanout and Direct are exchange types. Pub-Sub is a generic messaging pattern but not an exchange type. And you didn't even mention the 3rd and most important Exchange type, namely Topic. In fact, you can implement Fanout behavior on a Topic exchange just by declaring multiple queues with the same binding key. And you can define Direct behavior on a Topic exchange by declaring a Queue with `*` as the wildcard binding key.
Pub-Sub is generally understood as a pattern in which an application publishes messages which are consumed by several subscribers.
With RabbitMQ/AMQP it is important to remember that messages are always published to exchanges. Then exchanges route to queues. And queues deliver messages to subscribers. The behavior of the exchange is important. In Topic exchanges, the routing key from the publisher is matched up to the binding key from the subscriber in order to make the routing decision. Binding keys can have wildcard patterns which further influences the routing decision. More complicated routing can be [done based on the content of message headers](https://stackoverflow.com/questions/3280676/content-based-routing-with-rabbitmq-and-python) using a headers exchange type
RabbitMQ doesn't guarantee delivery of messages but you can get guaranteed delivery by choosing the right options(delivery mode = 2 for persistent msgs), and declaring exchanges and queues in advance of running your application so that messages are not discarded. | From an electronic exchange point of view the term “Multicast” means “the message is placed on the wire once” and all client applications that are listening can read the message off the “wire”. Any solution that makes N copies of the message for the N clients is not multicast. In addition to examining the source code one can also use a “sniffer” to determine how many copies of the message is sent over the wire from the messaging system. And yes, multicast messages are a form the UDP protocol message. See: <http://en.wikipedia.org/wiki/Multicast> for a general description. About ten years ago, we used the messaging system from TIBCO that supported multicast. See: <https://docs.tibco.com/pub/ems_openvms_c_client/8.0.0-june-2013/docs/html/tib_ems_users_guide/wwhelp/wwhimpl/common/html/wwhelp.htm#context=tib_ems_users_guide&file=EMS.5.091.htm> |
5,207,187 | I have html code `<input onclick="function_name(1)">` and I want to use it in Jquery something like `function function_name(i) { alert(i); }`. It doesn't work, any tips? Thank you. | 2011/03/05 | [
"https://Stackoverflow.com/questions/5207187",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/237681/"
] | ```
<input id="myId"/>
```
and
```
$("#myId").click(function() {
alert('something');
});
```
If I have understood you right. | try this:
html:
```
<input data="1" id="myinput" />
```
js;
```
$('#myinput').bind('click', function(event) {
alert($(this).attr('data'));
});
``` |
5,207,187 | I have html code `<input onclick="function_name(1)">` and I want to use it in Jquery something like `function function_name(i) { alert(i); }`. It doesn't work, any tips? Thank you. | 2011/03/05 | [
"https://Stackoverflow.com/questions/5207187",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/237681/"
] | The way your code is written, it should work.
If the `function_name` isn't firing, then it could be because you haven't defined it in the global scope.
For example, if you're using jQuery, this won't work because the function isn't global:
```
$(document).ready(function() {
function function_name(i) {
alert(i);
}
});
```
But this will, because you've made the function global:
```
$(document).ready(function() {
// some other code
});
function function_name(i) {
alert(i);
}
```
Or this will, because you've explicitly made it global from inside `.ready()`.
```
$(document).ready(function() {
window.function_name = function(i) {
alert(i);
}
});
```
Aside from the global issue, I'm not sure why your code would fail from the `onclick=` attribute. | try this:
html:
```
<input data="1" id="myinput" />
```
js;
```
$('#myinput').bind('click', function(event) {
alert($(this).attr('data'));
});
``` |
36,802,428 | When I put my cursor right on top of the link text, the link is not clickable, but if I put my cursor a little bit below the text, it becomes clickable. I'm learning right now so please explain to me why it's doing that and how to fix it.
HTML
```
<!DOCTYPE html>
<html Lang="en">
<head>
<meta charset="utf-8">
<title>Welcome!</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
```
```css
*{
margin: 0;
padding: 0;
}
header{
width: 1024px;
margin: 0 auto;
background-color: #81D4FA;
height: 50px;
}
header h1{
color: white;
position: relative;
left: 100px;
top: 5px;
}
nav{
margin-top: -20px;
margin-right: 100px;
}
nav ul{
float: right;
margin: 0;
padding: 0;
}
nav ul li{
list-style-type: none;
display: inline-block;
}
nav ul li a{
text-decoration: none;
color: white;
padding: 16px 20px;
}
a:hover{
background-color: #84FFFF;
}
.main{
width: 1024px;
margin-left: auto;
margin-right: auto;
}
.laptop{
width: 1024px;
}
.title{
background-color: #0D23FD;
height: 50px;
width: 300px;
position: relative;
top: -650px;
left: -10px;
border-bottom-right-radius: 10px;
border-top-right-radius: 10px;
}
.title h3{
color: white;
text-align: center;
position: relative;
top: 13px;
}
```
```html
<header>
<h1>Jack Smith</h1>
<nav>
<ul>
<li><a href="#">About</a></li>
<li><a href="#">My Work</a></li>
<li><a href="#">Contact Me</a></li>
</ul>
</nav>
</header>
<div class="main">
<img class="laptop" src="images/laptop.jpg">
<div class="title">
<h3>Front-End Web developer</h3>
</div>
</div>
``` | 2016/04/22 | [
"https://Stackoverflow.com/questions/36802428",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | It's because your `<h1>` is a block-level element, which will lay over the menu elements. If you give it `display: inline-block`, it will work as supposed.
>
> A **block-level element** always starts on a new line and takes up the
> full width available (stretches out to the left and right as far as it
> can).
>
>
>
See my example below.
```css
* {
margin: 0;
padding: 0;
}
header {
width: 1024px;
margin: 0 auto;
background-color: #81D4FA;
height: 50px;
}
header h1 {
color: white;
position: relative;
left: 100px;
top: 5px;
display: inline-block;
/* Added */
}
nav {
margin-top: -20px;
margin-right: 100px;
}
nav ul {
float: right;
margin: 0;
padding: 0;
}
nav ul li {
list-style-type: none;
display: inline-block;
}
nav ul li a {
text-decoration: none;
color: white;
padding: 16px 20px;
}
a:hover {
background-color: #84FFFF;
}
.main {
width: 1024px;
margin-left: auto;
margin-right: auto;
}
.laptop {
width: 1024px;
}
.title {
background-color: #0D23FD;
height: 50px;
width: 300px;
position: relative;
top: -650px;
left: -10px;
border-bottom-right-radius: 10px;
border-top-right-radius: 10px;
}
.title h3 {
color: white;
text-align: center;
position: relative;
top: 13px;
}
```
```html
<header>
<h1>Jack Smith</h1>
<nav>
<ul>
<li><a href="#">About</a>
</li>
<li><a href="#">My Work</a>
</li>
<li><a href="#">Contact Me</a>
</li>
</ul>
</nav>
</header>
<div class="main">
<img class="laptop" src="images/laptop.jpg">
<div class="title">
<h3>Front-End Web developer</h3>
</div>
</div>
``` | The problem is occurring because of the interaction between some of your styles. You're floating the `nav ul` element to the right, but you're also setting the `nav ul li` display to `inline-block` which is also doing an implicit float (try replacing it with `float: left` and you'll see the same behavior).
If you set the `position:relative` on your `nav ul`, it willforce the elements to float correctly within the `ul` container.
```
nav ul{
float: right;
margin: 0;
padding: 0;
position:relative; /*ADD THIS*/
}
``` |
27,426,786 | I'm trying to make database for my program and I'm having a lot of dumb problems...
It's fragment of main activity:
```
Database db = new Database(this,editText.getText().toString());
String text = db.printRow();
textView.setText(text);
```
Now database class:
```
String nickname="EmptyNick";
public Database(Context context, String name) {
super(context, "database.db", null, 1);
nickname = name;
}
public void onCreate(SQLiteDatabase db) {
if(!nickname.equals("EmptyNick")) {
db.execSQL("create table player(id integer primary key autoincrement,nick text);");
Users user = new Users();
user.setNick("Mariusz");
addPlayer(user);
}
else {
//not important
}
}
private void addPlayer(Users user) {
SQLiteDatabase db = getWritableDatabase();
ContentValues values = new ContentValues();
values.put("nick",user.getNick());
db.insertOrThrow("player",null,values);
}
public String printRow() {
String string=null;
if(!nickname.equals("EmptyNick")) {
String[] collumns = {"id","nick"};
SQLiteDatabase db = getReadableDatabase();
Cursor cursor = db.query("player",collumns,null,null,null,null,null);
cursor.moveToFirst();
while (cursor.moveToNext()) {
string += cursor.getString(1);
}
}
else {
//not important
}
return string;
}
```
Errors:
no such table: player
Caused by: java.lang.reflect.InvocationTargetException
Caused by: android.database.sqlite.SQLiteException: no such table: player (code 1): , while compiling: SELECT id, nick FROM player
I really can't see what's wrong. Error says there is no table 'player', but it is. On the beggining of onCreate methon in line:
```
db.execSQL("create table player(id integer primary key autoincrement,nick text);");
```
Can somebody help me? If I make Toast instead of text.setText(...) it shows me empty field, so yes, it can't create specific row. I understand the error, but do not from where and why it comes. | 2014/12/11 | [
"https://Stackoverflow.com/questions/27426786",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4334269/"
] | No need to delete from your list. Just shuffle it and iterate over it once. It will be faster and you can reuse your original list. So do `random.shuffle(bingo)` then iterate over `bingo`.
Here is how to incorporate this into your original code:
```
import random
bingo=["H", "He", "C", "O"]
random.shuffle(bingo)
for item in bingo:
if input("Bingo?") == "no":
print item
else:
break
``` | ```
foo = ['a', 'b', 'c', 'd', 'e']
from random import randrange
random_index = randrange(0,len(foo))
```
**For displaying:**
```
print foo[random_index]
```
**For deletion:**
```
foo = foo[:random_index] + foo[random_index+1 :]
``` |
27,426,786 | I'm trying to make database for my program and I'm having a lot of dumb problems...
It's fragment of main activity:
```
Database db = new Database(this,editText.getText().toString());
String text = db.printRow();
textView.setText(text);
```
Now database class:
```
String nickname="EmptyNick";
public Database(Context context, String name) {
super(context, "database.db", null, 1);
nickname = name;
}
public void onCreate(SQLiteDatabase db) {
if(!nickname.equals("EmptyNick")) {
db.execSQL("create table player(id integer primary key autoincrement,nick text);");
Users user = new Users();
user.setNick("Mariusz");
addPlayer(user);
}
else {
//not important
}
}
private void addPlayer(Users user) {
SQLiteDatabase db = getWritableDatabase();
ContentValues values = new ContentValues();
values.put("nick",user.getNick());
db.insertOrThrow("player",null,values);
}
public String printRow() {
String string=null;
if(!nickname.equals("EmptyNick")) {
String[] collumns = {"id","nick"};
SQLiteDatabase db = getReadableDatabase();
Cursor cursor = db.query("player",collumns,null,null,null,null,null);
cursor.moveToFirst();
while (cursor.moveToNext()) {
string += cursor.getString(1);
}
}
else {
//not important
}
return string;
}
```
Errors:
no such table: player
Caused by: java.lang.reflect.InvocationTargetException
Caused by: android.database.sqlite.SQLiteException: no such table: player (code 1): , while compiling: SELECT id, nick FROM player
I really can't see what's wrong. Error says there is no table 'player', but it is. On the beggining of onCreate methon in line:
```
db.execSQL("create table player(id integer primary key autoincrement,nick text);");
```
Can somebody help me? If I make Toast instead of text.setText(...) it shows me empty field, so yes, it can't create specific row. I understand the error, but do not from where and why it comes. | 2014/12/11 | [
"https://Stackoverflow.com/questions/27426786",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4334269/"
] | After reading, use `del`:
```
del bingo[int(a)]
``` | ```
foo = ['a', 'b', 'c', 'd', 'e']
from random import randrange
random_index = randrange(0,len(foo))
```
**For displaying:**
```
print foo[random_index]
```
**For deletion:**
```
foo = foo[:random_index] + foo[random_index+1 :]
``` |
27,426,786 | I'm trying to make database for my program and I'm having a lot of dumb problems...
It's fragment of main activity:
```
Database db = new Database(this,editText.getText().toString());
String text = db.printRow();
textView.setText(text);
```
Now database class:
```
String nickname="EmptyNick";
public Database(Context context, String name) {
super(context, "database.db", null, 1);
nickname = name;
}
public void onCreate(SQLiteDatabase db) {
if(!nickname.equals("EmptyNick")) {
db.execSQL("create table player(id integer primary key autoincrement,nick text);");
Users user = new Users();
user.setNick("Mariusz");
addPlayer(user);
}
else {
//not important
}
}
private void addPlayer(Users user) {
SQLiteDatabase db = getWritableDatabase();
ContentValues values = new ContentValues();
values.put("nick",user.getNick());
db.insertOrThrow("player",null,values);
}
public String printRow() {
String string=null;
if(!nickname.equals("EmptyNick")) {
String[] collumns = {"id","nick"};
SQLiteDatabase db = getReadableDatabase();
Cursor cursor = db.query("player",collumns,null,null,null,null,null);
cursor.moveToFirst();
while (cursor.moveToNext()) {
string += cursor.getString(1);
}
}
else {
//not important
}
return string;
}
```
Errors:
no such table: player
Caused by: java.lang.reflect.InvocationTargetException
Caused by: android.database.sqlite.SQLiteException: no such table: player (code 1): , while compiling: SELECT id, nick FROM player
I really can't see what's wrong. Error says there is no table 'player', but it is. On the beggining of onCreate methon in line:
```
db.execSQL("create table player(id integer primary key autoincrement,nick text);");
```
Can somebody help me? If I make Toast instead of text.setText(...) it shows me empty field, so yes, it can't create specific row. I understand the error, but do not from where and why it comes. | 2014/12/11 | [
"https://Stackoverflow.com/questions/27426786",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4334269/"
] | If you want to do this once you have a couple of options
1) Use a random index and pop
```
import random
i = random.randrange(0, len(bingo))
elem = bingo.pop(i) # removes and returns element
```
2) use random choice them remove
```
import random
elem = random.choice(bingo)
bingo.remove(elem)
```
If you want all of the elements in a random order, then you're better off just shuffling the list and then either iterating over it, or repeatedly calling `pop`
```
import random
random.shuffle(bingo)
for elem in bingo: # list is not shuffled
...
```
or
```
import random
random.shuffle(bingo)
while bingo:
elem = bingo.pop()
...
``` | ```
foo = ['a', 'b', 'c', 'd', 'e']
from random import randrange
random_index = randrange(0,len(foo))
```
**For displaying:**
```
print foo[random_index]
```
**For deletion:**
```
foo = foo[:random_index] + foo[random_index+1 :]
``` |
27,426,786 | I'm trying to make database for my program and I'm having a lot of dumb problems...
It's fragment of main activity:
```
Database db = new Database(this,editText.getText().toString());
String text = db.printRow();
textView.setText(text);
```
Now database class:
```
String nickname="EmptyNick";
public Database(Context context, String name) {
super(context, "database.db", null, 1);
nickname = name;
}
public void onCreate(SQLiteDatabase db) {
if(!nickname.equals("EmptyNick")) {
db.execSQL("create table player(id integer primary key autoincrement,nick text);");
Users user = new Users();
user.setNick("Mariusz");
addPlayer(user);
}
else {
//not important
}
}
private void addPlayer(Users user) {
SQLiteDatabase db = getWritableDatabase();
ContentValues values = new ContentValues();
values.put("nick",user.getNick());
db.insertOrThrow("player",null,values);
}
public String printRow() {
String string=null;
if(!nickname.equals("EmptyNick")) {
String[] collumns = {"id","nick"};
SQLiteDatabase db = getReadableDatabase();
Cursor cursor = db.query("player",collumns,null,null,null,null,null);
cursor.moveToFirst();
while (cursor.moveToNext()) {
string += cursor.getString(1);
}
}
else {
//not important
}
return string;
}
```
Errors:
no such table: player
Caused by: java.lang.reflect.InvocationTargetException
Caused by: android.database.sqlite.SQLiteException: no such table: player (code 1): , while compiling: SELECT id, nick FROM player
I really can't see what's wrong. Error says there is no table 'player', but it is. On the beggining of onCreate methon in line:
```
db.execSQL("create table player(id integer primary key autoincrement,nick text);");
```
Can somebody help me? If I make Toast instead of text.setText(...) it shows me empty field, so yes, it can't create specific row. I understand the error, but do not from where and why it comes. | 2014/12/11 | [
"https://Stackoverflow.com/questions/27426786",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4334269/"
] | No need to delete from your list. Just shuffle it and iterate over it once. It will be faster and you can reuse your original list. So do `random.shuffle(bingo)` then iterate over `bingo`.
Here is how to incorporate this into your original code:
```
import random
bingo=["H", "He", "C", "O"]
random.shuffle(bingo)
for item in bingo:
if input("Bingo?") == "no":
print item
else:
break
``` | After reading, use `del`:
```
del bingo[int(a)]
``` |
27,426,786 | I'm trying to make database for my program and I'm having a lot of dumb problems...
It's fragment of main activity:
```
Database db = new Database(this,editText.getText().toString());
String text = db.printRow();
textView.setText(text);
```
Now database class:
```
String nickname="EmptyNick";
public Database(Context context, String name) {
super(context, "database.db", null, 1);
nickname = name;
}
public void onCreate(SQLiteDatabase db) {
if(!nickname.equals("EmptyNick")) {
db.execSQL("create table player(id integer primary key autoincrement,nick text);");
Users user = new Users();
user.setNick("Mariusz");
addPlayer(user);
}
else {
//not important
}
}
private void addPlayer(Users user) {
SQLiteDatabase db = getWritableDatabase();
ContentValues values = new ContentValues();
values.put("nick",user.getNick());
db.insertOrThrow("player",null,values);
}
public String printRow() {
String string=null;
if(!nickname.equals("EmptyNick")) {
String[] collumns = {"id","nick"};
SQLiteDatabase db = getReadableDatabase();
Cursor cursor = db.query("player",collumns,null,null,null,null,null);
cursor.moveToFirst();
while (cursor.moveToNext()) {
string += cursor.getString(1);
}
}
else {
//not important
}
return string;
}
```
Errors:
no such table: player
Caused by: java.lang.reflect.InvocationTargetException
Caused by: android.database.sqlite.SQLiteException: no such table: player (code 1): , while compiling: SELECT id, nick FROM player
I really can't see what's wrong. Error says there is no table 'player', but it is. On the beggining of onCreate methon in line:
```
db.execSQL("create table player(id integer primary key autoincrement,nick text);");
```
Can somebody help me? If I make Toast instead of text.setText(...) it shows me empty field, so yes, it can't create specific row. I understand the error, but do not from where and why it comes. | 2014/12/11 | [
"https://Stackoverflow.com/questions/27426786",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4334269/"
] | No need to delete from your list. Just shuffle it and iterate over it once. It will be faster and you can reuse your original list. So do `random.shuffle(bingo)` then iterate over `bingo`.
Here is how to incorporate this into your original code:
```
import random
bingo=["H", "He", "C", "O"]
random.shuffle(bingo)
for item in bingo:
if input("Bingo?") == "no":
print item
else:
break
``` | If you want to do this once you have a couple of options
1) Use a random index and pop
```
import random
i = random.randrange(0, len(bingo))
elem = bingo.pop(i) # removes and returns element
```
2) use random choice them remove
```
import random
elem = random.choice(bingo)
bingo.remove(elem)
```
If you want all of the elements in a random order, then you're better off just shuffling the list and then either iterating over it, or repeatedly calling `pop`
```
import random
random.shuffle(bingo)
for elem in bingo: # list is not shuffled
...
```
or
```
import random
random.shuffle(bingo)
while bingo:
elem = bingo.pop()
...
``` |
3,508,701 | Where are they stored? And is there a way to determine when they get deleted? Is there a way to make it so that they are never deleted, so as to improve performance for example?
Another issue - in a busy hosting environment how big could all the dll's get? Let's say if you have 1000 medium websites? | 2010/08/18 | [
"https://Stackoverflow.com/questions/3508701",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/239362/"
] | >
> Where are they stored?
>
>
>
It depends on if you compile them before deployment or after deployment. If you compile them before deployment you will deploy them directly to the /bin folder of your app. This is what I normally do.
If you let asp.net compile after deployment there are a couple places they can end up, and it's not something I usually concern myself with. They are only re-compiled if something in the site changes, and so they are not deleted ever, merely over-written.
The size of a compiled dll file is generally comparable to that of the source files that are used to build it.
Note that these .Net dlls consist mainly of IL and do not yet have fully-compiled native code. They will be taken the rest of the way to native code when your app is started (in asp.net: when the first http request comes in) by the just-in-time compiler. You can use a tool like ngen to pre-compile them, but this is not normally the best option. Again, the location of this final code is not something I normally concern myself with. | You're probably looking for the `Temporary ASP.NET Files` folder, which is inside the .NET Framework directory. See <http://msdn.microsoft.com/en-us/library/ms366723.aspx> for more information. |
355,517 | This seems like pretty basic experiment, but I'm having a lot of trouble with it. Basically, I have two timer gates that measure time between two signals, and I drop metal ball between them. This way I'm getting distance traveled, and time. Ball is dropped from right above the first gate to make sure initial velocity is as small as possible (no way to make it 0 with this setup/timer). I'm assuming $v$ initial is $0 \frac{m}{s}$. Gates are $1$ meter apart.
Times are pretty consistent, and average result from dropping ball from $1.0$ meters is $0.4003$ seconds.
So now I have $3$ [constant acceleration] equations that I can use to get $g$.
1. $$d\_{traveled} = v\_{initial} . t + \frac{1}{2} a t^2$$
$$a = \frac{2d}{t^2}$$
$$a = \frac{2.1}{(.4003)^2}$$
$$a = 12.48 \frac{m}{s^2}$$
2. $$v\_f^2 = v\_i^2 + 2ad$$
$$a = \frac{v\_f^2-v\_i^2}{2d}$$
$$v\_f = \frac{distance}{time}=\frac{1.0}{0.4003}=2.5 \frac{m}{s}$$
$$a = \frac{(2.5 \frac{m}{s})^2}{2.1 m}$$
$$a = 3.125 \frac{m}{s^2}$$
3. $$v\_f = v\_i + at$$
$$a= \frac{v\_f-v\_i}{t}$$
$$a = \frac{2.5 m/s - 0}{ 0.4003 s}$$
$$a = 6.25 \frac{m}{s^2}$$
I'm getting three different results. And all of them are far from $9.8\frac{m}{s^2}$ .
No idea what I'm doing wrong.
Also, if I would drop that ball from different heights, and plot distance-time graph, how can I get acceleration from that? | 2017/09/05 | [
"https://physics.stackexchange.com/questions/355517",
"https://physics.stackexchange.com",
"https://physics.stackexchange.com/users/168267/"
] | The time you should be getting is $0.4516$ seconds. The measurement is off by $0.05$ seconds. This is reason why you are getting $12.48$ instead of $9.8$. This is one of the cases where even small errors in calculations can give you very wrong answers. Since the time is squared, it will bring more error to the answer.
Moving on, in your second and third calculations, you used a very wrong formula to get final velocity.
The relation,$Velocity=\frac{Distance}{Time}$, can only be used when motion in uniform (unaccelerated). But since the body is falling under gravity, the motion is accelerated.
Therefore, the last two calculations will always give wrong results because the usage of equations is wrong. However, the equations used in first equation are correct. | In #2 and in #3, You are calculating Vf as average velocity, not final velocity. With constant acceleration, your final velocity is twice the average so, it is 5 m/s, not 2.5 m/s. Now you will get all three results = ~ 12.5.
What this indicates is that your initial velocity is far from 0, and/or there is some other error in your experiment that you need to find yourself. It may be your time/distance measurements etc. |
355,517 | This seems like pretty basic experiment, but I'm having a lot of trouble with it. Basically, I have two timer gates that measure time between two signals, and I drop metal ball between them. This way I'm getting distance traveled, and time. Ball is dropped from right above the first gate to make sure initial velocity is as small as possible (no way to make it 0 with this setup/timer). I'm assuming $v$ initial is $0 \frac{m}{s}$. Gates are $1$ meter apart.
Times are pretty consistent, and average result from dropping ball from $1.0$ meters is $0.4003$ seconds.
So now I have $3$ [constant acceleration] equations that I can use to get $g$.
1. $$d\_{traveled} = v\_{initial} . t + \frac{1}{2} a t^2$$
$$a = \frac{2d}{t^2}$$
$$a = \frac{2.1}{(.4003)^2}$$
$$a = 12.48 \frac{m}{s^2}$$
2. $$v\_f^2 = v\_i^2 + 2ad$$
$$a = \frac{v\_f^2-v\_i^2}{2d}$$
$$v\_f = \frac{distance}{time}=\frac{1.0}{0.4003}=2.5 \frac{m}{s}$$
$$a = \frac{(2.5 \frac{m}{s})^2}{2.1 m}$$
$$a = 3.125 \frac{m}{s^2}$$
3. $$v\_f = v\_i + at$$
$$a= \frac{v\_f-v\_i}{t}$$
$$a = \frac{2.5 m/s - 0}{ 0.4003 s}$$
$$a = 6.25 \frac{m}{s^2}$$
I'm getting three different results. And all of them are far from $9.8\frac{m}{s^2}$ .
No idea what I'm doing wrong.
Also, if I would drop that ball from different heights, and plot distance-time graph, how can I get acceleration from that? | 2017/09/05 | [
"https://physics.stackexchange.com/questions/355517",
"https://physics.stackexchange.com",
"https://physics.stackexchange.com/users/168267/"
] | The time you should be getting is $0.4516$ seconds. The measurement is off by $0.05$ seconds. This is reason why you are getting $12.48$ instead of $9.8$. This is one of the cases where even small errors in calculations can give you very wrong answers. Since the time is squared, it will bring more error to the answer.
Moving on, in your second and third calculations, you used a very wrong formula to get final velocity.
The relation,$Velocity=\frac{Distance}{Time}$, can only be used when motion in uniform (unaccelerated). But since the body is falling under gravity, the motion is accelerated.
Therefore, the last two calculations will always give wrong results because the usage of equations is wrong. However, the equations used in first equation are correct. | First of all the Physics.
The velocities in the constant acceleration kinematic equations are **instantaneous** velocities at the initial time equal to zero, $v\_{\rm i}$, and and final time $t$ when the velocity if $v\_{\rm f}$.
In the first equation that you used you made no use of the velocities other than stating that the initial velocity is zero and so that is the correct value of $g$ from your experimental data.
In the other two equations you assumed that the final velocity was $\frac d t$ which is in fact the average velocity assuming the ball started from rest.
For constant acceleration starting from rest the final velocity is twice the average velocity.
As the average velocity is $\frac {1.0}{0.4003} = 2.498\,\rm m/s$ then the final velocity is $2 \times 2.498 = 4.996 \,\rm m/s$.
This gives the acceleration of free fall $g = \frac {4.996}{0.4003}= 12.48\, \rm m/s^2$ as you found using your first equation.
Now on to the experiment which is difficult to comment on as the actual experimental set up has not be described in any detail.
Perhaps the first thing which need to be done is to get an estimate of what the "expected" time for a free fall of one metre using ?
This works out to be $\sqrt{\frac {2}{9.8}} \approx 0.45 \,\rm s$.
As the timing device itself seems to be of a high precision and probably of a reasonable accuracy the discrepancy of $10\%$ in the timing points to a flawed experimental arrangement/technique.
There are numerous ways of doing this experiment in the school/college laboratory but if you are able to drop the ball from rest from a fixed position I suggest that using your apparatus you try the following.
Have the first light gate a distance $D$ from the position where the ball is dropped and the second light gate at a position which is $D+d$ from the initial position of the ball.
Again measure the time interval between the ball passing through the first light gate and then through the second gate.
That time interval $t$ is the time it takes for the ball to travel, from an unknown but constant velocity $v\_{\rm i}$ when at the first light gate, a distance $d$, to the second light gate.
$d = v\_{\rm i} t + \frac 12 g t^2 \Rightarrow \frac d t = \frac 12 g \, t + v\_{\rm i}$
Keeping the first light gate at the same position (ie keep $D$ constant) move the second light gate to a new position and hence a new value of $d$ and again measure the time interval.
You now have two equations and two unknowns $v\_{\rm i}$ and $g$ and hence you can now solve for $g$.
Perhaps a better method of analysis might be to plot $\frac d t$, which is the average velocity between the two light gates, against $t$ and from the gradient of the graph ($=\frac g 2$) find $g$?
---
If you want any further help then perhaps you need to say more about the experimental set up that you used?
---
It may be of interest to you to you that your method is the basis of the method used by [D R Tate to measure $g$](http://nvlpubs.nist.gov/nistpubs/jres/72C/jresv72Cn1p1_A1b.pdf) at the National Institute of Standards and Technology (NIST), then called the National Bureau of Standards.
The paper is worth reading just to show what needed to be done to get a value to $\pm 0.00005\%$. |
355,517 | This seems like pretty basic experiment, but I'm having a lot of trouble with it. Basically, I have two timer gates that measure time between two signals, and I drop metal ball between them. This way I'm getting distance traveled, and time. Ball is dropped from right above the first gate to make sure initial velocity is as small as possible (no way to make it 0 with this setup/timer). I'm assuming $v$ initial is $0 \frac{m}{s}$. Gates are $1$ meter apart.
Times are pretty consistent, and average result from dropping ball from $1.0$ meters is $0.4003$ seconds.
So now I have $3$ [constant acceleration] equations that I can use to get $g$.
1. $$d\_{traveled} = v\_{initial} . t + \frac{1}{2} a t^2$$
$$a = \frac{2d}{t^2}$$
$$a = \frac{2.1}{(.4003)^2}$$
$$a = 12.48 \frac{m}{s^2}$$
2. $$v\_f^2 = v\_i^2 + 2ad$$
$$a = \frac{v\_f^2-v\_i^2}{2d}$$
$$v\_f = \frac{distance}{time}=\frac{1.0}{0.4003}=2.5 \frac{m}{s}$$
$$a = \frac{(2.5 \frac{m}{s})^2}{2.1 m}$$
$$a = 3.125 \frac{m}{s^2}$$
3. $$v\_f = v\_i + at$$
$$a= \frac{v\_f-v\_i}{t}$$
$$a = \frac{2.5 m/s - 0}{ 0.4003 s}$$
$$a = 6.25 \frac{m}{s^2}$$
I'm getting three different results. And all of them are far from $9.8\frac{m}{s^2}$ .
No idea what I'm doing wrong.
Also, if I would drop that ball from different heights, and plot distance-time graph, how can I get acceleration from that? | 2017/09/05 | [
"https://physics.stackexchange.com/questions/355517",
"https://physics.stackexchange.com",
"https://physics.stackexchange.com/users/168267/"
] | In #2 and in #3, You are calculating Vf as average velocity, not final velocity. With constant acceleration, your final velocity is twice the average so, it is 5 m/s, not 2.5 m/s. Now you will get all three results = ~ 12.5.
What this indicates is that your initial velocity is far from 0, and/or there is some other error in your experiment that you need to find yourself. It may be your time/distance measurements etc. | First of all the Physics.
The velocities in the constant acceleration kinematic equations are **instantaneous** velocities at the initial time equal to zero, $v\_{\rm i}$, and and final time $t$ when the velocity if $v\_{\rm f}$.
In the first equation that you used you made no use of the velocities other than stating that the initial velocity is zero and so that is the correct value of $g$ from your experimental data.
In the other two equations you assumed that the final velocity was $\frac d t$ which is in fact the average velocity assuming the ball started from rest.
For constant acceleration starting from rest the final velocity is twice the average velocity.
As the average velocity is $\frac {1.0}{0.4003} = 2.498\,\rm m/s$ then the final velocity is $2 \times 2.498 = 4.996 \,\rm m/s$.
This gives the acceleration of free fall $g = \frac {4.996}{0.4003}= 12.48\, \rm m/s^2$ as you found using your first equation.
Now on to the experiment which is difficult to comment on as the actual experimental set up has not be described in any detail.
Perhaps the first thing which need to be done is to get an estimate of what the "expected" time for a free fall of one metre using ?
This works out to be $\sqrt{\frac {2}{9.8}} \approx 0.45 \,\rm s$.
As the timing device itself seems to be of a high precision and probably of a reasonable accuracy the discrepancy of $10\%$ in the timing points to a flawed experimental arrangement/technique.
There are numerous ways of doing this experiment in the school/college laboratory but if you are able to drop the ball from rest from a fixed position I suggest that using your apparatus you try the following.
Have the first light gate a distance $D$ from the position where the ball is dropped and the second light gate at a position which is $D+d$ from the initial position of the ball.
Again measure the time interval between the ball passing through the first light gate and then through the second gate.
That time interval $t$ is the time it takes for the ball to travel, from an unknown but constant velocity $v\_{\rm i}$ when at the first light gate, a distance $d$, to the second light gate.
$d = v\_{\rm i} t + \frac 12 g t^2 \Rightarrow \frac d t = \frac 12 g \, t + v\_{\rm i}$
Keeping the first light gate at the same position (ie keep $D$ constant) move the second light gate to a new position and hence a new value of $d$ and again measure the time interval.
You now have two equations and two unknowns $v\_{\rm i}$ and $g$ and hence you can now solve for $g$.
Perhaps a better method of analysis might be to plot $\frac d t$, which is the average velocity between the two light gates, against $t$ and from the gradient of the graph ($=\frac g 2$) find $g$?
---
If you want any further help then perhaps you need to say more about the experimental set up that you used?
---
It may be of interest to you to you that your method is the basis of the method used by [D R Tate to measure $g$](http://nvlpubs.nist.gov/nistpubs/jres/72C/jresv72Cn1p1_A1b.pdf) at the National Institute of Standards and Technology (NIST), then called the National Bureau of Standards.
The paper is worth reading just to show what needed to be done to get a value to $\pm 0.00005\%$. |
6,594,814 | Our team is assigned a project on database. We are all set to start. But we will be working at our homes.
Each member is given tables to create, insert MBs of data, and write one table-orientes triggers and stored pros.
But ultimately we will have to merge then in a single database file and each member will be having his .mdf file of his tables.
How to we merge these tables???
We need to combine all the data into a single database file only....
Please bear with me if this question is a cake! I'm just a newbie :-) | 2011/07/06 | [
"https://Stackoverflow.com/questions/6594814",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/825901/"
] | Moving objects from one database to another is easily achieved by scripting the objects.
<http://msdn.microsoft.com/en-us/library/ms178078.aspx>
Once the individual work is done, script out the tables, stored procedures, triggers, views, etc, and create them in your target database (this can be on a different server).
Then you can use the Import and Export Wizard to move your data.
<http://msdn.microsoft.com/en-us/library/ms140052.aspx> | As far as I am aware you can't merge the .mdf files in the way you are thinking.
The closest approach I can think of is as follows...
Each person:
1. works on their own database with UNIQUE database names
2. also has a 'clone' of what will be the final databases
3. creates a script that copies their database structure and data to the 'clone'
You can then attach each .mdf file to the master SQL Server (as seperate and distinct databases). You then run each person's script, copying from the attached .mdf's into the master copy of the final database.
In general I would strongly advise use of script based alterations to a database, allowing version control, etc, through versioning of the scripts. |
143,774 | So, I installed the Android SDK, Eclipse, and the ADT. Upon firing up Eclipse the first time after setting up the ADT, this error popped up:
```
[2012-05-29 12:11:06 - adb] /home/drsmith/Downloads/android-sdk-linux/platform-tools/adb: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory
[2012-05-29 12:11:06 - adb] 'adb version' failed!
/home/drsmith/Downloads/android-sdk-linux/platform-tools/adb: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory
[2012-05-29 12:11:06 - adb] Failed to parse the output of 'adb version':
Standard Output was:
Error Output was:
/home/drsmith/Downloads/android-sdk-linux/platform-tools/adb: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory
[2012-05-29 12:11:06 - adb] /home/drsmith/Downloads/android-sdk-linux/platform-tools/adb: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory
[2012-05-29 12:11:06 - adb] 'adb version' failed!
/home/drsmith/Downloads/android-sdk-linux/platform-tools/adb: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory
[2012-05-29 12:11:06 - adb] Failed to parse the output of 'adb version':
Standard Output was:
Error Output was:
/home/drsmith/Downloads/android-sdk-linux/platform-tools/adb: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory
```
I'm not quite sure how this is. Feels weird that there's a missing library there. I'm using Ubuntu 12.04. No adb is a pretty big blow as an Android developer. How do I fix? | 2012/05/29 | [
"https://askubuntu.com/questions/143774",
"https://askubuntu.com",
"https://askubuntu.com/users/27601/"
] | You need library ncurses 32 bit version installed in your system
```
sudo apt-get install libncurses5:i386
```
In addition to libncurses5, you may require libstdc++6.
```
sudo apt-get install libstdc++6:i386
```
With the command
```
sudo apt-get install ia32-libs
```
You install a lot of libraries that is not useful to solve your problem. | For me `adb` was missing regardless of all activities.
Then I noticed useful hint shown in the terminal, which I've tried:
>
> `sudo apt-get install android-tools-adb`
>
>
>
After that, `adb` command was installed and now I can install on emulated devices whatever I want. |
143,774 | So, I installed the Android SDK, Eclipse, and the ADT. Upon firing up Eclipse the first time after setting up the ADT, this error popped up:
```
[2012-05-29 12:11:06 - adb] /home/drsmith/Downloads/android-sdk-linux/platform-tools/adb: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory
[2012-05-29 12:11:06 - adb] 'adb version' failed!
/home/drsmith/Downloads/android-sdk-linux/platform-tools/adb: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory
[2012-05-29 12:11:06 - adb] Failed to parse the output of 'adb version':
Standard Output was:
Error Output was:
/home/drsmith/Downloads/android-sdk-linux/platform-tools/adb: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory
[2012-05-29 12:11:06 - adb] /home/drsmith/Downloads/android-sdk-linux/platform-tools/adb: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory
[2012-05-29 12:11:06 - adb] 'adb version' failed!
/home/drsmith/Downloads/android-sdk-linux/platform-tools/adb: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory
[2012-05-29 12:11:06 - adb] Failed to parse the output of 'adb version':
Standard Output was:
Error Output was:
/home/drsmith/Downloads/android-sdk-linux/platform-tools/adb: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory
```
I'm not quite sure how this is. Feels weird that there's a missing library there. I'm using Ubuntu 12.04. No adb is a pretty big blow as an Android developer. How do I fix? | 2012/05/29 | [
"https://askubuntu.com/questions/143774",
"https://askubuntu.com",
"https://askubuntu.com/users/27601/"
] | You need library ncurses 32 bit version installed in your system
```
sudo apt-get install libncurses5:i386
```
In addition to libncurses5, you may require libstdc++6.
```
sudo apt-get install libstdc++6:i386
```
With the command
```
sudo apt-get install ia32-libs
```
You install a lot of libraries that is not useful to solve your problem. | I am running Ubuntu 13.10 and I was having the same problem. I tried adding `ia32libs` and it didn't recognize the repo, and recommended a couple others like `lib32z1`. Neither worked. Then I saw this comment,
You need library ncurses 32 bit version installed in your system
```
sudo apt-get install libncurses5:i386
```
In addition to libncurses5, you may require libstdc++6.
```
sudo apt-get install libstdc++6:i386
```
This worked great for me. :) |
143,774 | So, I installed the Android SDK, Eclipse, and the ADT. Upon firing up Eclipse the first time after setting up the ADT, this error popped up:
```
[2012-05-29 12:11:06 - adb] /home/drsmith/Downloads/android-sdk-linux/platform-tools/adb: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory
[2012-05-29 12:11:06 - adb] 'adb version' failed!
/home/drsmith/Downloads/android-sdk-linux/platform-tools/adb: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory
[2012-05-29 12:11:06 - adb] Failed to parse the output of 'adb version':
Standard Output was:
Error Output was:
/home/drsmith/Downloads/android-sdk-linux/platform-tools/adb: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory
[2012-05-29 12:11:06 - adb] /home/drsmith/Downloads/android-sdk-linux/platform-tools/adb: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory
[2012-05-29 12:11:06 - adb] 'adb version' failed!
/home/drsmith/Downloads/android-sdk-linux/platform-tools/adb: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory
[2012-05-29 12:11:06 - adb] Failed to parse the output of 'adb version':
Standard Output was:
Error Output was:
/home/drsmith/Downloads/android-sdk-linux/platform-tools/adb: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory
```
I'm not quite sure how this is. Feels weird that there's a missing library there. I'm using Ubuntu 12.04. No adb is a pretty big blow as an Android developer. How do I fix? | 2012/05/29 | [
"https://askubuntu.com/questions/143774",
"https://askubuntu.com",
"https://askubuntu.com/users/27601/"
] | Android SDK platform tools requires `ia32-libs`, which itself is a big package of libraries:
```
sudo apt-get install ia32-libs
```
---
**UPDATE:**
Below are the [latest instructions from Google](https://developer.android.com/sdk/installing/index.html?pkg=tools) on how to install Android SDK library dependencies:
>
> If you are running a 64-bit distribution on your development machine, you need to install additional packages first. For Ubuntu 13.10 (Saucy Salamander) and above, install the `libncurses5:i386`, `libstdc++6:i386`, and `zlib1g:i386` packages using `apt-get`:
>
>
>
> ```
> sudo dpkg --add-architecture i386
> sudo apt-get update
> sudo apt-get install libncurses5:i386 libstdc++6:i386 zlib1g:i386
>
> ```
>
> For earlier versions of Ubuntu, install the `ia32-libs` package using `apt-get`:
>
>
>
> ```
> apt-get install ia32-libs
>
> ```
>
> | ```
sudo apt-get install ia32-libs
```
Solved my problem. This libraries collection can be useful for a lot of developer's programs also. |
143,774 | So, I installed the Android SDK, Eclipse, and the ADT. Upon firing up Eclipse the first time after setting up the ADT, this error popped up:
```
[2012-05-29 12:11:06 - adb] /home/drsmith/Downloads/android-sdk-linux/platform-tools/adb: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory
[2012-05-29 12:11:06 - adb] 'adb version' failed!
/home/drsmith/Downloads/android-sdk-linux/platform-tools/adb: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory
[2012-05-29 12:11:06 - adb] Failed to parse the output of 'adb version':
Standard Output was:
Error Output was:
/home/drsmith/Downloads/android-sdk-linux/platform-tools/adb: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory
[2012-05-29 12:11:06 - adb] /home/drsmith/Downloads/android-sdk-linux/platform-tools/adb: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory
[2012-05-29 12:11:06 - adb] 'adb version' failed!
/home/drsmith/Downloads/android-sdk-linux/platform-tools/adb: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory
[2012-05-29 12:11:06 - adb] Failed to parse the output of 'adb version':
Standard Output was:
Error Output was:
/home/drsmith/Downloads/android-sdk-linux/platform-tools/adb: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory
```
I'm not quite sure how this is. Feels weird that there's a missing library there. I'm using Ubuntu 12.04. No adb is a pretty big blow as an Android developer. How do I fix? | 2012/05/29 | [
"https://askubuntu.com/questions/143774",
"https://askubuntu.com",
"https://askubuntu.com/users/27601/"
] | If `libncurses` is not installed then install it and try again.
```
sudo apt-get install libncurses5
``` | For me `adb` was missing regardless of all activities.
Then I noticed useful hint shown in the terminal, which I've tried:
>
> `sudo apt-get install android-tools-adb`
>
>
>
After that, `adb` command was installed and now I can install on emulated devices whatever I want. |
143,774 | So, I installed the Android SDK, Eclipse, and the ADT. Upon firing up Eclipse the first time after setting up the ADT, this error popped up:
```
[2012-05-29 12:11:06 - adb] /home/drsmith/Downloads/android-sdk-linux/platform-tools/adb: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory
[2012-05-29 12:11:06 - adb] 'adb version' failed!
/home/drsmith/Downloads/android-sdk-linux/platform-tools/adb: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory
[2012-05-29 12:11:06 - adb] Failed to parse the output of 'adb version':
Standard Output was:
Error Output was:
/home/drsmith/Downloads/android-sdk-linux/platform-tools/adb: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory
[2012-05-29 12:11:06 - adb] /home/drsmith/Downloads/android-sdk-linux/platform-tools/adb: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory
[2012-05-29 12:11:06 - adb] 'adb version' failed!
/home/drsmith/Downloads/android-sdk-linux/platform-tools/adb: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory
[2012-05-29 12:11:06 - adb] Failed to parse the output of 'adb version':
Standard Output was:
Error Output was:
/home/drsmith/Downloads/android-sdk-linux/platform-tools/adb: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory
```
I'm not quite sure how this is. Feels weird that there's a missing library there. I'm using Ubuntu 12.04. No adb is a pretty big blow as an Android developer. How do I fix? | 2012/05/29 | [
"https://askubuntu.com/questions/143774",
"https://askubuntu.com",
"https://askubuntu.com/users/27601/"
] | If `libncurses` is not installed then install it and try again.
```
sudo apt-get install libncurses5
``` | ```
sudo apt-get install ia32-libs
```
Solved my problem. This libraries collection can be useful for a lot of developer's programs also. |