qid
int64 1
74.7M
| question
stringlengths 0
58.3k
| date
stringlengths 10
10
| metadata
list | response_j
stringlengths 2
48.3k
| response_k
stringlengths 2
40.5k
|
---|---|---|---|---|---|
33,079,298 |
I have a string value for amount that is coming from the DB. The local culture on my system is Portuguese(pt-br). As a result, the amount with decimal values is read as, for ex: 3,4 for 3.4. I need to parse this in such a way that it displays 3.4 but instead no matter what i try I'm getting 34. I have searched every where for a solution and have tried implementing the below, but in vain.
//here row[item.columnName] is the row of the DataTable which I'm looping
Solution 1:
```
Double amt = Double.Parse(Convert.ToString(row[item.columnName]), CultureInfo.InvariantCulture);
```
Solution 2:
```
CultureInfo usCulture = new CultureInfo("en-US");
NumberFormatInfo dbNumberFormat = usCulture.NumberFormat;
Double amt = Double.Parse(Convert.ToString(row[item.columnName]), dbNumberFormat);
```
Neither of them seem to work.Can some one please suggest if there is any other way I can achieve this?
**EDIT:**
Turns out that the value I am getting from the DB is of type decimal so I changed my LOC to below.
```
decimal d = decimal.Parse(Convert.ToString(row[item.columnName]),new System.Globalization.CultureInfo("pt-BR", false));
```
It still doesn't seem to work and I just don't see where I'm going wrong. I tried the same thing on [DotNetFiddle](https://dotnetfiddle.net/)
and it works absolutely fine. Below is the code that I tried.
```
using System;
public class Program
{
public static void Main()
{
decimal d = decimal.Parse("1,35",new System.Globalization.CultureInfo("pt-BR", false));
Console.WriteLine(d.ToString());
}
}
```
The result I obtained was 1.35 as expected. What am I doing wrong?
|
2015/10/12
|
[
"https://Stackoverflow.com/questions/33079298",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4243283/"
] |
OK the issue with the click event binding.
You need to bind the click event on nav a because of the page1.php have nav menu so the content is loaded using the ajax but click event is not bind on new menu item.
So create new function called BindClickEvent
```
function BindClickEvent(){
$("ul#nav a").unbind( "click" );
$("ul#nav a").bind("click", function(){
page = "content/"+$(this).attr('href')
$("#loading").ajaxStart(function(){
$(this).show()
})
$("#loading").ajaxStop(function(){
$(this).hide();
})
$(".content").load(page);
return false;
})
}
```
call `BindClickEvent` function in page load and page1.php file content also
So whenever you will add / remove menu call `BindClickEvent` function in ajax call response.
|
It is the issue of delegated function,
just replace
`$("ul#nav a").click(function(){`
with
`$(document).on('click', 'ul#nav a', function(){`
your problem will be solved :)
|
4,214,992 |
>
> What is the smallest number that can be written as the sum of three, four and five consecutive numbers?
>
>
>
I encountered this question while doing my Math summer homework. I have tried to make progress on this question.
Sum of three consecutive numbers = $x + x+1 + x+2 = 3x+3$
Sum of four consecutive integers = $x + x+1 + x+2 + x+3 = 4x+6$
Sum of five consecutive integers = $x + x+1 + x+2 + x+3 + x+4 = 5x+10$
The number must be the lowest common multiple of $3x+3$ , $4x+6$ and $5x+10$, which is $60x + 30$.
Substituting $x = 0$ gives us the lowest positive, non-zero and whole number, which is $30$.
$$30 = 9 + 10 + 11\\
30 = 6 + 7 + 8 + 9\\
30 = 4 + 5 + 6 + 7 + 8$$
Is my answer correct? If not, where in my method have I produced an error? Is there an ever quicker method to solve this question?
|
2021/08/02
|
[
"https://math.stackexchange.com/questions/4214992",
"https://math.stackexchange.com",
"https://math.stackexchange.com/users/955185/"
] |
If we are talking about a non-negative integer, I have another method to propose.
---
>
> Sum of three consecutive numbers = $++1++2=3+3$
>
>
>
>
> Sum of four consecutive integers = $++1++2++3=4+6$
>
>
>
>
> Sum of five consecutive integers = $++1++2++3++4=5+10$
>
>
>
Another way of formulating a solution from this step can be as follows:
$y = 3x\_1 + 3 = 4x\_2+6 = 5x\_3+10$
$y= 3x\_1+3\equiv 0 \pmod{3}$
$y= 4x\_2+6\equiv 2 \pmod{4}$
$y= 5x\_3+10\equiv 0 \pmod{5}$
$y$ is divisible by $5$ and $3$ which gives us $y=15k$
The remainder left from dividing $y$ by $4$ is $2$. $y=15$ doesn't satisfy this condition, but $y=30$ does.
|
Your final answer is fine, but your method looks highly suspect at one particular line which needs clarification. You write:
>
> The number must be the lowest common multiple of $3x+3$ , $4x+6$ and
> $5x+10$, which is $60x + 30$.
>
>
>
But it’s not clear what you mean by this, as the lowest common multiple of those three numbers is not $60x+30$ (try it for $x=2$). Maybe what you’re actually doing to arrive at $60x+30$ is correct, or maybe it isn’t — but at a minimum you need to explain what you’re doing because “lowest common multiple” doesn’t describe it adequately, and the reuse of the same $x$ for three different values is a big red flag.
My *hunch* is that you’re taking the separate LCMs of the coefficients $(3,4,5)$ and of $(3,6,10)$ and then gluing them back together. If so then this that’s definitely wrong. Consider the slight variation where 3,4,5 are replaced by 2,3,5. Then you’d have $2x+1, 3x+3, 5x+10$ combining to $30x+30$, which never works (it’s even, so it can never be the sum of two consecutive integers). Being a multiple of $2x+1$ is very different from being. *equal* to $2x+1$.
This broken method lucks out sometimes because of the fact that it basically works for odd coefficients (when $k$ is odd, being the sum of $k$ consecutive integers is the same as being divisible by $k$). But if that’s really what you’re doing then it is broken and should not be part of your solution.
|
4,214,992 |
>
> What is the smallest number that can be written as the sum of three, four and five consecutive numbers?
>
>
>
I encountered this question while doing my Math summer homework. I have tried to make progress on this question.
Sum of three consecutive numbers = $x + x+1 + x+2 = 3x+3$
Sum of four consecutive integers = $x + x+1 + x+2 + x+3 = 4x+6$
Sum of five consecutive integers = $x + x+1 + x+2 + x+3 + x+4 = 5x+10$
The number must be the lowest common multiple of $3x+3$ , $4x+6$ and $5x+10$, which is $60x + 30$.
Substituting $x = 0$ gives us the lowest positive, non-zero and whole number, which is $30$.
$$30 = 9 + 10 + 11\\
30 = 6 + 7 + 8 + 9\\
30 = 4 + 5 + 6 + 7 + 8$$
Is my answer correct? If not, where in my method have I produced an error? Is there an ever quicker method to solve this question?
|
2021/08/02
|
[
"https://math.stackexchange.com/questions/4214992",
"https://math.stackexchange.com",
"https://math.stackexchange.com/users/955185/"
] |
If we are talking about a non-negative integer, I have another method to propose.
---
>
> Sum of three consecutive numbers = $++1++2=3+3$
>
>
>
>
> Sum of four consecutive integers = $++1++2++3=4+6$
>
>
>
>
> Sum of five consecutive integers = $++1++2++3++4=5+10$
>
>
>
Another way of formulating a solution from this step can be as follows:
$y = 3x\_1 + 3 = 4x\_2+6 = 5x\_3+10$
$y= 3x\_1+3\equiv 0 \pmod{3}$
$y= 4x\_2+6\equiv 2 \pmod{4}$
$y= 5x\_3+10\equiv 0 \pmod{5}$
$y$ is divisible by $5$ and $3$ which gives us $y=15k$
The remainder left from dividing $y$ by $4$ is $2$. $y=15$ doesn't satisfy this condition, but $y=30$ does.
|
Your reasoning contains a subtle (essentially notational) error, which does not greatly affect the result you obtain. You say:
>
> The number must be the lowest common multiple of $3x+3$, $4x+6$ and $5x+10$, which is $60x + 30$.
>
>
>
But the value of $x$ in each of $3x+3$, $4x+6$ and $5x+10$ is not the same; by your own results it is either $4$ or $6$ or $9$. So saying $60x+30$ and $x=0$ is not logically consistent: you did not mean to imply that the sum $3x+3=3$ was equal to $4x+6=6$ or $5x+10=10$.
The better reasoning goes as follows: One of the sums has $3$ as a factor, another has $2$ (but not $4$) as a factor, and the third has $5$ as a factor. Since they each equal the same sum, that sum must have $2,3,5$ as factors, and so must be an odd multiple of $30$. In your terms, $S=60k+30$ where $k$ is not identically the same as the $x$ in any of your sums.
$30$ itself is in fact a solution, and so are $90,150,\dots$, viz:
$$90=29+30+31=21+22+23+24=16+17+18+19+20 \\
150=49+50+51=36+37+38+39=28+29+30+31+32$$
The smallest such number is $30$, as you found.
As I get set to post this, I see that Erick Wong has made essentially the same objection.
|
147,436 |
I'm running OpenXcom and wondered if there is any way to having the game automatically rename my soldiers in order to classify them by ability, i.e. high accuracy, strong, and so on.
I think this was available as a patch to the original release of the game, and wondered if there was anything similar available.
|
2013/12/22
|
[
"https://gaming.stackexchange.com/questions/147436",
"https://gaming.stackexchange.com",
"https://gaming.stackexchange.com/users/16344/"
] |
You can just click on a soldiers name in the stats menu to change his/her name.

|
You can use [Statstrings](https://www.ufopaedia.org/index.php/Statstrings). Check the built-in **XcomUtil StatStrings** mod as an example you can modify to your will.
|
46,085,660 |
In the following snippet, `MyClass` has a static method which returns its shared pointer. To make to code concise, we use the alias `MyClassPtr` for `std::shared_ptr<MyClass>`.
However, to accomplish this, we declare the class before declaring the shared pointer alias, which then follows the actual class declaration. It looks verbose.
Is there some way to reorganize the code so that
* keep the `MyClassPtr` alias (it is shared across the project)
* without "declaring" `MyClass` twice
code below:
```
class MyClass;
using MyClassPtr = std::shared_ptr<MyClass>;
class MyClass {
public:
static MyClassPtr createMyClassInstance();
private:
/*Other members & methods*/
}
```
I'm OK with the current implementation. But I would like to seek experienced guy's advice if the code can be improved.
|
2017/09/06
|
[
"https://Stackoverflow.com/questions/46085660",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3697757/"
] |
Make `Ptr` a member type:
```
class MyClass {
public:
using Ptr = std::shared_ptr<MyClass>;
static Ptr createMyClassInstance();
private:
/*Other members & method*/
};
// ...
MyClass::Ptr p = MyClass::createMyClassInstance();
```
|
Replace the return type with auto:
```
class MyClass {
public:
static auto createMyClassInstance();
private:
/*Other members & method*/
}
```
[Demo](http://coliru.stacked-crooked.com/a/088a1b2702f777c8):
|
46,085,660 |
In the following snippet, `MyClass` has a static method which returns its shared pointer. To make to code concise, we use the alias `MyClassPtr` for `std::shared_ptr<MyClass>`.
However, to accomplish this, we declare the class before declaring the shared pointer alias, which then follows the actual class declaration. It looks verbose.
Is there some way to reorganize the code so that
* keep the `MyClassPtr` alias (it is shared across the project)
* without "declaring" `MyClass` twice
code below:
```
class MyClass;
using MyClassPtr = std::shared_ptr<MyClass>;
class MyClass {
public:
static MyClassPtr createMyClassInstance();
private:
/*Other members & methods*/
}
```
I'm OK with the current implementation. But I would like to seek experienced guy's advice if the code can be improved.
|
2017/09/06
|
[
"https://Stackoverflow.com/questions/46085660",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3697757/"
] |
Your question is somewhat vague, as you ask how the code can be *simplified*, yet you fail to provide any real code, only the outline of a class definition. Instead, I try to answer the more sensible question of how to *improve* your code. I suggest
1. Avoid the alias `MyClassPtr`, it's not really necessary (it should not be used much if you use `auto`) but more importantly reduces verbosity and hence readability of the code, since it's not obvious from its name that `MyClassPtr` refers to a `shared_ptr`.
If you insist on having a shorthand for the smart pointer, you can define this *after* the class definition, thus avoiding the forward declaration
2. Rename `MyClass::createMyClassInstance` to something more verbose, I suggest `MyClass::createSharedPtr` (no need to have `MyClass` in the function name again).
3. Don't forget the `;` after a class definition.
Thus,
```
class MyClass
{
public:
static std::shared_ptr<MyClass> createSharedPtr();
private:
/* Other members & methods */
};
using MyClassSharedPtr = std::shared_ptr<MyClass>; // optional
```
IMHO, good code should be self-explanatory and hence not necessarily most concise/brief, though redundancies must be avoided.
|
Replace the return type with auto:
```
class MyClass {
public:
static auto createMyClassInstance();
private:
/*Other members & method*/
}
```
[Demo](http://coliru.stacked-crooked.com/a/088a1b2702f777c8):
|
46,085,660 |
In the following snippet, `MyClass` has a static method which returns its shared pointer. To make to code concise, we use the alias `MyClassPtr` for `std::shared_ptr<MyClass>`.
However, to accomplish this, we declare the class before declaring the shared pointer alias, which then follows the actual class declaration. It looks verbose.
Is there some way to reorganize the code so that
* keep the `MyClassPtr` alias (it is shared across the project)
* without "declaring" `MyClass` twice
code below:
```
class MyClass;
using MyClassPtr = std::shared_ptr<MyClass>;
class MyClass {
public:
static MyClassPtr createMyClassInstance();
private:
/*Other members & methods*/
}
```
I'm OK with the current implementation. But I would like to seek experienced guy's advice if the code can be improved.
|
2017/09/06
|
[
"https://Stackoverflow.com/questions/46085660",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3697757/"
] |
>
> is there some way to reorganize the code so that
>
>
> (1)keep the MyClassPtr alias (it is shared across the project)
>
>
> (2) without "declaring" MyClass twice
>
>
>
You you accept to declare `MyClassPtr` twice, you can declare it inside the class and "export" it outside
```
#include <memory>
class MyClass
{
public:
using MyClassPtr = std::shared_ptr<MyClass>;
static MyClassPtr createMyClassInstance();
private:
/*Other members & methods*/
};
using MyClassPtr = MyClass::MyClassPtr;
int main()
{
MyClassPtr np { nullptr };
}
```
|
Replace the return type with auto:
```
class MyClass {
public:
static auto createMyClassInstance();
private:
/*Other members & method*/
}
```
[Demo](http://coliru.stacked-crooked.com/a/088a1b2702f777c8):
|
46,085,660 |
In the following snippet, `MyClass` has a static method which returns its shared pointer. To make to code concise, we use the alias `MyClassPtr` for `std::shared_ptr<MyClass>`.
However, to accomplish this, we declare the class before declaring the shared pointer alias, which then follows the actual class declaration. It looks verbose.
Is there some way to reorganize the code so that
* keep the `MyClassPtr` alias (it is shared across the project)
* without "declaring" `MyClass` twice
code below:
```
class MyClass;
using MyClassPtr = std::shared_ptr<MyClass>;
class MyClass {
public:
static MyClassPtr createMyClassInstance();
private:
/*Other members & methods*/
}
```
I'm OK with the current implementation. But I would like to seek experienced guy's advice if the code can be improved.
|
2017/09/06
|
[
"https://Stackoverflow.com/questions/46085660",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3697757/"
] |
Make `Ptr` a member type:
```
class MyClass {
public:
using Ptr = std::shared_ptr<MyClass>;
static Ptr createMyClassInstance();
private:
/*Other members & method*/
};
// ...
MyClass::Ptr p = MyClass::createMyClassInstance();
```
|
>
> is there some way to reorganize the code so that
>
>
> (1)keep the MyClassPtr alias (it is shared across the project)
>
>
> (2) without "declaring" MyClass twice
>
>
>
You you accept to declare `MyClassPtr` twice, you can declare it inside the class and "export" it outside
```
#include <memory>
class MyClass
{
public:
using MyClassPtr = std::shared_ptr<MyClass>;
static MyClassPtr createMyClassInstance();
private:
/*Other members & methods*/
};
using MyClassPtr = MyClass::MyClassPtr;
int main()
{
MyClassPtr np { nullptr };
}
```
|
46,085,660 |
In the following snippet, `MyClass` has a static method which returns its shared pointer. To make to code concise, we use the alias `MyClassPtr` for `std::shared_ptr<MyClass>`.
However, to accomplish this, we declare the class before declaring the shared pointer alias, which then follows the actual class declaration. It looks verbose.
Is there some way to reorganize the code so that
* keep the `MyClassPtr` alias (it is shared across the project)
* without "declaring" `MyClass` twice
code below:
```
class MyClass;
using MyClassPtr = std::shared_ptr<MyClass>;
class MyClass {
public:
static MyClassPtr createMyClassInstance();
private:
/*Other members & methods*/
}
```
I'm OK with the current implementation. But I would like to seek experienced guy's advice if the code can be improved.
|
2017/09/06
|
[
"https://Stackoverflow.com/questions/46085660",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3697757/"
] |
Your question is somewhat vague, as you ask how the code can be *simplified*, yet you fail to provide any real code, only the outline of a class definition. Instead, I try to answer the more sensible question of how to *improve* your code. I suggest
1. Avoid the alias `MyClassPtr`, it's not really necessary (it should not be used much if you use `auto`) but more importantly reduces verbosity and hence readability of the code, since it's not obvious from its name that `MyClassPtr` refers to a `shared_ptr`.
If you insist on having a shorthand for the smart pointer, you can define this *after* the class definition, thus avoiding the forward declaration
2. Rename `MyClass::createMyClassInstance` to something more verbose, I suggest `MyClass::createSharedPtr` (no need to have `MyClass` in the function name again).
3. Don't forget the `;` after a class definition.
Thus,
```
class MyClass
{
public:
static std::shared_ptr<MyClass> createSharedPtr();
private:
/* Other members & methods */
};
using MyClassSharedPtr = std::shared_ptr<MyClass>; // optional
```
IMHO, good code should be self-explanatory and hence not necessarily most concise/brief, though redundancies must be avoided.
|
>
> is there some way to reorganize the code so that
>
>
> (1)keep the MyClassPtr alias (it is shared across the project)
>
>
> (2) without "declaring" MyClass twice
>
>
>
You you accept to declare `MyClassPtr` twice, you can declare it inside the class and "export" it outside
```
#include <memory>
class MyClass
{
public:
using MyClassPtr = std::shared_ptr<MyClass>;
static MyClassPtr createMyClassInstance();
private:
/*Other members & methods*/
};
using MyClassPtr = MyClass::MyClassPtr;
int main()
{
MyClassPtr np { nullptr };
}
```
|
43,044,881 |
I am trying to change the Titles of 'doctors' in a database and was just wondering was there a SQL query which I could run to change them.
[The column im trying to change](https://i.stack.imgur.com/Ca4iM.png)
What I am asking is that there is any way I can update the column to add a 'Dr' infront of the names to replace the 'Miss','Mr' etc.
I'm thinking about using a SQL Statement containing the wildcard function to update it but not sure it would change the specifics.
Thanks,
Karl
|
2017/03/27
|
[
"https://Stackoverflow.com/questions/43044881",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7251447/"
] |
This example can be quite useful for you.
```
public partial class MainWindow: Window
{
DispatcherTimer dispatcherTimer = new DispatcherTimer();
Stopwatch stopWatch= new Stopwatch();
string currentTime = string.Empty;
public MainWindow()
{
InitializeComponent();
dispatcherTimer .Tick += new EventHandler(dt_Tick);
dispatcherTimer .Interval = new TimeSpan(0, 0, 0, 0, 1);
}
void dt_Tick(object sender, EventArgs e)
{
if (stopWatch.IsRunning)
{
TimeSpan ts = stopWatch.Elapsed;
currentTime = String.Format("{0:00}:{1:00}:{2:00}",
ts.Minutes, ts.Seconds, ts.Milliseconds / 10);
clocktxt.Text = currentTime;
}
}
private void startbtn_Click(object sender, RoutedEventArgs e)
{
stopWatch.Start();
dispatcherTimer .Start();
}
private void stopbtn_Click(object sender, RoutedEventArgs e)
{
if (stopWatch.IsRunning)
{
stopWatch.Stop();
}
elapsedtimeitem.Items.Add(currentTime);
}
private void resetbtn_Click(object sender, RoutedEventArgs e)
{
stopWatch.Reset();
clocktxt.Text = "00:00:00";
}
}
```
|
Full code.
The Frontend XAML is as follows:
```
<Window x:Class="StopWatch.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Simple Stop Watch" Height="350" Width="525">
<Grid Background="BlanchedAlmond">
<TextBlock FontSize="50" Margin="200,-12,175,258" RenderTransformOrigin="1.443,0.195">Timer</TextBlock>
<TextBlock x:Name="clocktxtblock" FontSize="70" Margin="118,38,37,183"></TextBlock>
<Button x:Name="startbtn" Margin="38,137,350,126" Background="SkyBlue" Content="Start" FontSize="30" Click="startbtn_Click" ></Button>
<Button x:Name="stopbtn" Margin="200,137,190,126" Background="SkyBlue" Content="Stop" FontSize="30" Click="stopbtn_Click" ></Button>
<Button x:Name="resetbtn" Margin="360,137,28,126" Background="SkyBlue" Content="Reset" FontSize="30" Click="resetbtn_Click" ></Button>
<ListBox x:Name="elapsedtimeitem" HorizontalAlignment="Left" Height="100" VerticalAlignment="Top" Width="433" Margin="56,199,0,0"/>
</Grid>
```
Coding The CodeBehind File( MainWindows.xaml.cs):
```
public partial class MainWindow: Window
{
DispatcherTimer dt = new DispatcherTimer();
Stopwatch sw = new Stopwatch();
string currentTime = string.Empty;
public MainWindow()
{
InitializeComponent();
dt.Tick += new EventHandler(dt_Tick);
dt.Interval = new TimeSpan(0, 0, 0, 0, 1);
}
void dt_Tick(object sender, EventArgs e)
{
if (sw.IsRunning)
{
TimeSpan ts = sw.Elapsed;
currentTime = String.Format("{0:00}:{1:00}:{2:00}",
ts.Minutes, ts.Seconds, ts.Milliseconds / 10);
clocktxtblock.Text = currentTime;
}
}
private void startbtn_Click(object sender, RoutedEventArgs e)
{
sw.Start();
dt.Start();
}
private void stopbtn_Click(object sender, RoutedEventArgs e)
{
if (sw.IsRunning)
{
sw.Stop();
}
elapsedtimeitem.Items.Add(currentTime);
}
private void resetbtn_Click(object sender, RoutedEventArgs e)
{
sw.Reset();
clocktxtblock.Text = "00:00:00";
}
}
```
|
298,208 |
I am making a table where I need to adjust the row height. After adjusting the row height, the vertical lines on my second column do not extend to the correct height (they leave a gap).
```
\documentclass[11pt]{article}
\usepackage{xcolor,colortbl}
\definecolor{Gray}{gray}{0.85}
\begin{document}
\Large\centering \textbf{APPROVALS} \\
\normalsize
\begin{center}
\begin{tabular}{|p{2in}|p{3.5in}|}
\hline\rowcolor{Gray}
& \centering SIGNATURE \tabularnewline
\hline
Document Owner \\ NAME 1 & \multicolumn{1}{c||}{ } \tabularnewline[15pt]
\hline
Reviewer \\ Someone 1 & \multicolumn{1}{c|}{ } \tabularnewline[15pt]
\hline
Reviewer \\ Someone 2 & \multicolumn{1}{c|}{ } \tabularnewline[15pt]
\hline
Approved: \\ NAME 4 & \multicolumn{1}{c|}{ } \tabularnewline[15pt]
\hline
\end{tabular}
\end{center}
\end{document}
```
[](https://i.stack.imgur.com/L98Vn.jpg)
|
2016/03/09
|
[
"https://tex.stackexchange.com/questions/298208",
"https://tex.stackexchange.com",
"https://tex.stackexchange.com/users/100324/"
] |
the gaps are because you finished the rows early
```
Document Owner \\
```
has no second cell, so does not get the vertical rules in that cell use
```
Document Owner & \\
```
|
David pushed me in the right direction. The following code makes the table I want.
```
\documentclass[11pt]{article}
\usepackage{multirow}
\usepackage{xcolor,colortbl}
\definecolor{Gray}{gray}{0.85}
\begin{document}
\Large\centering \textbf{APPROVALS} \\
\normalsize
\begin{center}
\begin{tabular}{|p{2in}|p{3.5in}|}
\hline\rowcolor{Gray}
\multicolumn{1}{|c}{ }& \centering SIGNATURE \tabularnewline
\hline
Document Owner1 & \tabularnewline
NAME 1 & \tabularnewline[15pt]
\hline
Reviewer & \tabularnewline
Someone 1 & \tabularnewline[15pt]
\hline
Reviewer & \tabularnewline
Someone 2 & \tabularnewline[15pt]
\hline
Approved: & \tabularnewline
NAME 4 & \tabularnewline[15pt]
\hline
\end{tabular}
\end{center}
\end{document}
```
[](https://i.stack.imgur.com/e6Ixa.jpg)
|
46,345,027 |
I am having a `UICollectionView` with a horizontal scroll. Here is my `collectionView`:
```
fileprivate(set) lazy var collectionView: UICollectionView = {
let width = UIScreen.main.bounds.width.multiplied(by: 0.9)
let layout: UICollectionViewFlowLayout = UICollectionViewFlowLayout()
layout.itemSize = CGSize(width: width, height: 50)
layout.sectionInset = UIEdgeInsets(top: 20, left: 20, bottom: 10, right: 20)
layout.scrollDirection = .horizontal
layout.minimumLineSpacing = 20
let collectionView = UICollectionView(frame: CGRect(x: 0, y: 0, width: self.frame.width, height: 50), collectionViewLayout: layout)
collectionView.translatesAutoresizingMaskIntoConstraints = false
collectionView.backgroundColor = .red
collectionView.isPagingEnabled = true
return collectionView
}()
```
and it looks like that:
[](https://i.stack.imgur.com/bvwU3.png)
As you see I have `collectionView.isPagingEnabled = true` in the code since I want the paging effect. So what I am trying to achieve is to make the items look like in the picture above (20 spacing on left and right) in every other page, but so far I am getting :
[](https://i.stack.imgur.com/JWl43.png)
Any ideas/tips how to get to the desired behaviour ?
|
2017/09/21
|
[
"https://Stackoverflow.com/questions/46345027",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3594729/"
] |
Here's the `UICollectionViewDelegateFlowLayout` I used in my test project to achieve what you want.
```
func collectionView(_ collectionView: UICollectionView,
layout collectionViewLayout: UICollectionViewLayout,
sizeForItemAt indexPath: IndexPath) -> CGSize {
return CGSize(width: UIScreen.main.bounds.width.multiplied(by: 0.9), height: 50.0)
}
// item spacing = vertical spacing in horizontal flow
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat {
return (UIScreen.main.bounds.width.multiplied(by: 0.1))
}
// line spacing = horizontal spacing in horizontal flow
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {
return (UIScreen.main.bounds.width.multiplied(by: 0.1))
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
return UIEdgeInsets(top: 0, left: (UIScreen.main.bounds.width.multiplied(by: 0.1) / 2.0), bottom: 0, right: (UIScreen.main.bounds.width.multiplied(by: 0.1) / 2.0))
}
```
With your code it'd be like that:
```
fileprivate(set) lazy var collectionView: UICollectionView = {
let width = UIScreen.main.bounds.width.multiplied(by: 0.9)
let layout: UICollectionViewFlowLayout = UICollectionViewFlowLayout()
layout.itemSize = CGSize(width: width, height: 50)
layout.sectionInset = UIEdgeInsets(top: 20, left: UIScreen.main.bounds.width.multiplied(by: 0.1) / 2.0, bottom: 10, right: UIScreen.main.bounds.width.multiplied(by: 0.1) / 2.0)
layout.scrollDirection = .horizontal
layout.minimumLineSpacing = UIScreen.main.bounds.width.multiplied(by: 0.1)
layout.minimumInteritemSpacing = UIScreen.main.bounds.width.multiplied(by: 0.1) // or any value you want
let collectionView = UICollectionView(frame: CGRect(x: 0, y: 0, width: self.frame.width, height: 50), collectionViewLayout: layout)
collectionView.translatesAutoresizingMaskIntoConstraints = false
collectionView.backgroundColor = .red
collectionView.isPagingEnabled = true
return collectionView
}()
```
|
@Jeremy provided a comprehensive solution. I just want to share how I achieve this with little effort
```
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
let frame = cvImages.frame
return CGSize(width: frame.width , height: frame.height * 0.9)
}
```
and enabling the paging and I have done
Actually I just have to show a single cell at a time on collection view just like image slider
|
54,793,479 |
I don't understand why this code compiles:
```
#include <iostream>
class T {
};
void fun(T) {
std::cout << __PRETTY_FUNCTION__ << std::endl;
}
void fun(const T&) { // Why does this compile?
std::cout << __PRETTY_FUNCTION__ << std::endl;
}
void fun(const T&&) { // Why does this compile?
}
int main() {
return 0;
}
```
The overloads `T` and `const T&` are always conflicting, so I don't understand why GCC compiles it.
I have readen that like "a parameter of category value can't be overloaded by a parameter of rvalue or lvalue".
If the overload with `T` and `const T&&` works, does it mean that it will be impossible to pass a rvalue to this function in any way, because any call would be ambiguous ? Or is it a way to disambiguiate the call ?
**GCC Version:** gcc version 7.3.0 (Ubuntu 7.3.0-27ubuntu1~18.04)
`__cplusplus = 201103`
|
2019/02/20
|
[
"https://Stackoverflow.com/questions/54793479",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5110937/"
] |
The overloads are indeed conflicting (ambiguous) under ordinary overload resolution, but they are still resolvable by explicit means
```
T a;
static_cast<void(*)(T)>(fun)(a); // calls `T` version
static_cast<void(*)(const T &)>(fun)(a); // calls `const T &` version
```
although I don't immediately see any use case for it.
As for `const T &&` overload - it has some narrow applicability if you for some reason want to prohibit calling your `const T &` function with non-lvalue arguments
```
void fun(const T &) {}
void fun(const T &&) = delete;
int main()
{
T t;
fun(t); // OK
fun(T()); // Error
}
```
See, for example, how it is done for [std::ref, std::cref](https://en.cppreference.com/w/cpp/utility/functional/ref).
|
I'll assume that you have defined the type `T` somewhere preceding this code snippet. Otherwise, of course, the code would not compile.
It's not *quite* true that if one overload takes `T` and one takes `const T&`, then overload resolution can never select one of them over the other. For example, if the argument has type `volatile T`, then the overload taking `T` must be selected over the one taking `const T&`. This corner case aside, though, these functions are always *individually* callable by bypassing overload resolution entirely:
```
static_cast<void(*)(T)>(fun)(x); // calls void fun(T) on x
```
It's not the compiler's job to *prevent* you from declaring functions that pose issues for overload resolution. A good compiler might, perhaps, *warn* you; but then again, I don't think such a warning is necessary, since almost no programmer would write code like this, other than as an experiment.
|
3,145,414 |
I need to write the series
$$\sum\_{n=0}^N nx^n$$
in a form that does not involve the summation notation, for example $\sum\_{i=0}^n i^2 = \frac{(n^2+n)(2n+1)}{6}$. Does anyone have any idea how to do this? I've attempted multiple ways including using generating functions however no luck
|
2019/03/12
|
[
"https://math.stackexchange.com/questions/3145414",
"https://math.stackexchange.com",
"https://math.stackexchange.com/users/540784/"
] |
I will give a sketch that every isometry $F:S^2\times \mathbb{R}\to S^2\times \mathbb{R}$ is of the form $F(p,y)=(A(p),B(y)).$
Fix arbitrary $p\in S^2$ and $y\in \mathbb{R}$. Let $q\in S^2$ and $r\in \mathbb{R}$ be given by $(q,r)=F(p,y)$. Observe that the tangent space at $(p,y)$ splits as an orthogonal sum
\begin{equation\*}
T\_{(p,y)}(S^2\times\mathbb{R})=T\_pS^2\oplus T\_y\mathbb{R}
\end{equation\*}
and similarly
\begin{equation\*}
T\_{(q,r)}(S^2\times\mathbb{R})=T\_qS^2\oplus T\_r\mathbb{R}.
\end{equation\*}
Recall that $(dF)\_{(p,y)}:T\_pS^2\oplus T\_y\mathbb{R}\to T\_qS^2\oplus T\_r\mathbb{R}$ is an isometry between vector spaces. Observe that
\begin{equation\*}
(dF)\_{(p,y)}\big(T\_pS^2\big)\subset T\_qS^2,
\end{equation\*}
since otherwise $F$ would map some periodic geodesics to non-periodic geodesics. Since $T\_pS^2$ and $T\_qS^2$ have the same dimension, we even get
\begin{equation\*}
(dF)\_{(p,y)}\big(T\_pS^2\big)=T\_qS^2
\end{equation\*}
by the injectivity of $(dF)\_{(p,y)}$. As $(dF)\_{(p,y)}$ is an isometry,
\begin{equation\*}
(dF)\_{(p,y)}\big(T\_y\mathbb{R}\big)=T\_r\mathbb{R}
\end{equation\*}
follows from the orthogonal decompositions of the tangent spaces. Hence we get a decomposition
\begin{equation\*}
(dF)\_{(p,y)}=a\oplus b
\end{equation\*}
for some isometries $a:T\_pS^2\to T\_qS^2$ and $b: T\_y\mathbb{R}\to T\_r\mathbb{R}$. Therefore, for any $v\in T\_pM$ and $c,t\in \mathbb{R}$ we have
\begin{equation\*}
F\big(\exp\_p(tv),y+ct\big)=\Big(\exp\_q\big(ta(v)\big),r+tb(c)\Big).
\end{equation\*}
Can you conclude from here?
|
Not every map $F: \mathbb{S}^2 \times \mathbb{R} \to \mathbb{S}^2 \times \mathbb{R}$ can be written in the form $F(\hat{x}, y) = (A(\hat{x}), B(y))$. As an analogy, consider a map from $\mathbb{R}^2$ to itself; is it true that every such map can be written in the form $F(x,y) = (f(x), g(y))$?
|
37,043,579 |
When i run my app, it takes about 10 min to display on my phone. And every change in code also takes 10 min. What should I do? I am using `Android Studio 2.0`.
|
2016/05/05
|
[
"https://Stackoverflow.com/questions/37043579",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6183852/"
] |
In android studio goto
* **File > Settings > Build,Execution,Deployment > Build Tools > Gradle** and check the **Offline Work** option.
* **File > Settings > Build,Execution,Deployment > Compiler** and check all four checkboxes.
If you are using android 2.0 or higher and if you have enabled Instant Run.
* **File > Settings > Build,Execution,Deployment > Instant
Run** and uncheck all four checkboxes.
\*\*
Sometimes enabling Instant run causes app to launch activity too slowly with white screen after running. Disabling instant run will remove the problem.
* Restart Android studio
|
Upgrade to the Android Studio 2.1. I also faced the same problem in 2.0
hope it will work.
|
74,389,848 |
In python tutorial(<https://docs.python.org/3/tutorial/introduction.html#strings>),
slicing is explained as to think of the indices as pointing between characters, with the left edge of the first character numbered 0. Then the right edge of the last character of a string of n characters has index n, for example:
[](https://i.stack.imgur.com/kBfgk.png)
Moving on it says - 'The slice from i to j consists of all characters between the edges labeled i and j, respectively.'
However, when i try to print the following two cases it seems to miss the P.
Case1: print(word[6:0:-1])--> Outputs 'nohty'
Case2: print(word[6:-6:-1])--> Outputs 'nohty'
Can anyone provide a possible explanation why it doesn't print 'nohtyP'?
(P.S. - I know i can keep the end vacant to get the 'P'.)
|
2022/11/10
|
[
"https://Stackoverflow.com/questions/74389848",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10288870/"
] |
uisng non local params
```
def main():
def egg():
nonlocal a
print(a)
#egg() # NameError: name 'a' is not defined **As excepted**
a = 50
egg()
main()
```
output
```
50
```
|
Callable class can be used to replicate this sort of behaviour without breaking the encapsulation of a function.
```
class Egg:
def __init__(self, a):
self.a = a
def __call__(self):
print(self.a)
egg = Egg(50)
egg() # 50
egg.a = 20
egg() # 20
```
|
340,228 |
As the title says I'm having a very strange problem with SSH connections at my house, it seems that after about 3-5 minutes of inactivity any SSH sessions I have open will just shutdown and leave the SSH connection in an appeared active state as I do not receive a timeout or reset message and I cannot provide any input or receive any output, it's as if it has become frozen in time and I must close the terminal window itself.
I know that the server's I am connecting too are not the problem as I regularly use them at the office with no issues, sometimes keeping a session open for hours on end.
I have attempted to set the SSH KeepAlive with no success, running `top` has been the only solution I can find so far to keep the connection open and it does not always guarantee.
I have been attempting to debug this issue for quite some time and have come up with absolutely nothing and beginning to wonder if this could possibly be my ISP ( Brighthouse ) or my modem/router ( RCA Thompson DWG855T ) causing the problem, I am leaning towards the later but I cannot remove and test the connection alone as the RCA is a router/modem combo .....
As anyone experienced this problem before and found a viable solution?
Here is the -vvv ssh with certain info #### out
```
OpenSSH_5.1p1, OpenSSL 0.9.7l 28 Sep 2006
debug1: Reading configuration data ###
debug1: Reading configuration data /etc/ssh_config
debug2: ssh_connect: needpriv 0
debug1: Connecting to ##### port 22.
debug1: Connection established.
debug1: identity file ### type -1
debug3: Not a RSA1 key file ###.
debug2: key_type_from_name: unknown key type '-----BEGIN'
debug3: key_read: missing keytype
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug2: key_type_from_name: unknown key type '-----END'
debug3: key_read: missing keytype
debug1: identity file #### type 1
debug1: identity file #### type -1
debug1: Remote protocol version 2.0, remote software version OpenSSH_4.3
debug1: match: OpenSSH_4.3 pat OpenSSH*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_5.1
debug2: fd 3 setting O_NONBLOCK
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug2: kex_parse_kexinit: diffie-hellman-group-exchange-sha256,diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1
debug2: kex_parse_kexinit: ssh-rsa,ssh-dss
debug2: kex_parse_kexinit: aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,arcfour128,arcfour256,arcfour,aes192-cbc,aes256-cbc,[email protected],aes128-ctr,aes192-ctr,aes256-ctr
debug2: kex_parse_kexinit: aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,arcfour128,arcfour256,arcfour,aes192-cbc,aes256-cbc,[email protected],aes128-ctr,aes192-ctr,aes256-ctr
debug2: kex_parse_kexinit: hmac-md5,hmac-sha1,[email protected],hmac-ripemd160,[email protected],hmac-sha1-96,hmac-md5-96
debug2: kex_parse_kexinit: hmac-md5,hmac-sha1,[email protected],hmac-ripemd160,[email protected],hmac-sha1-96,hmac-md5-96
debug2: kex_parse_kexinit: none,[email protected],zlib
debug2: kex_parse_kexinit: none,[email protected],zlib
debug2: kex_parse_kexinit:
debug2: kex_parse_kexinit:
debug2: kex_parse_kexinit: first_kex_follows 0
debug2: kex_parse_kexinit: reserved 0
debug2: kex_parse_kexinit: diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1
debug2: kex_parse_kexinit: ssh-rsa,ssh-dss
debug2: kex_parse_kexinit: aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,[email protected]
debug2: kex_parse_kexinit: aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,[email protected]
debug2: kex_parse_kexinit: hmac-md5,hmac-sha1,hmac-ripemd160,[email protected],hmac-sha1-96,hmac-md5-96
debug2: kex_parse_kexinit: hmac-md5,hmac-sha1,hmac-ripemd160,[email protected],hmac-sha1-96,hmac-md5-96
debug2: kex_parse_kexinit: none,[email protected]
debug2: kex_parse_kexinit: none,[email protected]
debug2: kex_parse_kexinit:
debug2: kex_parse_kexinit:
debug2: kex_parse_kexinit: first_kex_follows 0
debug2: kex_parse_kexinit: reserved 0
debug2: mac_setup: found hmac-md5
debug1: kex: server->client aes128-cbc hmac-md5 none
debug2: mac_setup: found hmac-md5
debug1: kex: client->server aes128-cbc hmac-md5 none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
debug2: dh_gen_key: priv key bits set: 116/256
debug2: bits set: 488/1024
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
debug3: check_host_in_hostfile: filename ####
debug3: check_host_in_hostfile: match line 17
debug3: check_host_in_hostfile: filename ####
debug3: check_host_in_hostfile: match line 16
debug1: Host '####' is known and matches the RSA host key.
debug1: Found key in ####:17
debug2: bits set: 486/1024
debug1: ssh_rsa_verify: signature correct
debug2: kex_derive_keys
debug2: set_newkeys: mode 1
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug2: set_newkeys: mode 0
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug2: service_accept: ssh-userauth
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug2: key: #### (0x0)
debug2: key: #### (0x407f00)
debug2: key: #### (0x0)
debug1: Authentications that can continue: publickey,gssapi-with-mic,password
debug3: start over, passed a different list publickey,gssapi-with-mic,password
debug3: preferred publickey,keyboard-interactive,password
debug3: authmethod_lookup publickey
debug3: remaining preferred: keyboard-interactive,password
debug3: authmethod_is_enabled publickey
debug1: Next authentication method: publickey
debug1: Trying private key: ####.ssh/identity
debug3: no such identity: ####.ssh/identity
debug1: Offering public key: ####.ssh/id_rsa
debug3: send_pubkey_test
debug2: we sent a publickey packet, wait for reply
debug1: Server accepts key: pkalg ssh-rsa blen 277
debug2: input_userauth_pk_ok: fp 32:97:a1:c0:1a:26:24:e2:a2:c2:be:47:46:31:a9:94
debug3: sign_and_send_pubkey
debug1: read PEM private key done: type RSA
debug1: Authentication succeeded (publickey).
debug1: channel 0: new [client-session]
debug3: ssh_session2_open: channel_new: 0
debug2: channel 0: send open
debug1: Requesting [email protected]
debug1: Entering interactive session.
debug2: callback start
debug2: client_session2_setup: id 0
debug2: channel 0: request pty-req confirm 1
debug3: tty_make_modes: ospeed 38400
debug3: tty_make_modes: ispeed 38400
debug2: channel 0: request shell confirm 1
debug2: fd 3 setting TCP_NODELAY
debug2: callback done
debug2: channel 0: open confirm rwindow 0 rmax 32768
debug2: channel_input_confirm: type 99 id 0
debug2: PTY allocation request accepted on channel 0
debug2: channel 0: rcvd adjust 2097152
debug2: channel_input_confirm: type 99 id 0
debug2: shell request accepted on channel 0
```
|
2011/12/12
|
[
"https://serverfault.com/questions/340228",
"https://serverfault.com",
"https://serverfault.com/users/76801/"
] |
Check the timeout settings on the router at the server side (the system you're connecting to). I usually run into the 5-minute delay as a result of the default settings on Sonicwall firewalls. In these cases, I'll make the following changes on the ssh server *IF* I don't have access to correct this on the firewall side.
In `/etc/ssh/sshd_config`, I add or make sure the following directives are set:
```
TCPKeepAlive yes
KeepAlive yes
ClientAliveInterval 60
```
Restart the ssh daemon, and the issue should go away.
You can also make the change on your client system. This entails adding `ServerAliveInterval 60` to `/etc/ssh/ssh_config` and reconnecting or adding `-o ServerAliveInterval 60` to your ssh connection string.
|
I have had similar problems with while connecting over bad connections. The following configuration did the trick for me. In the server's sshd\_config add the following
```
ClientAliveInterval 60
```
For details you can lookup manual page of sshd\_config. Good luck : )
|
31,809,602 |
I have a viewController in which I have a scrollView in which I have 3 views. This is a scheme :
* ScrollView (UIScrollView)
+ Header (UIView)
+ TabBar (UIView)
+ Container (UIView in which I load a ViewController)
The main problem is that, in my container (in which there is a view controller), I have a collectionView (which can scroll) but I want my entire scrollView to scroll (not only my container).
So this is what I have :
[](https://i.stack.imgur.com/rNt7T.png)
And this is what I want :
[](https://i.stack.imgur.com/dOstz.png)
Anyone can help me with this ?
|
2015/08/04
|
[
"https://Stackoverflow.com/questions/31809602",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3369214/"
] |
I just solved this problem for my own project. Assuming you are using storyboards, I made the UIView a child of UITableView and made the UITableView extend the full viewport of the device.
Since UITableView implements UIScrollView you get full screen scrolling of your content.
**General Rule** your parent view has to implement UIScrollView and extend the full screen to get viewport vertical scrolling.
[](https://i.stack.imgur.com/zyaV0.png)
|
To do this, if you are not using auto layout or if you are adding views to container programmatically, you must manually set collection view frame to match its content size after you load some data on it. If you are using auto layout, you should create height constraint outlet and set its constant value based on collection view content size, again after loading data on it
|
31,809,602 |
I have a viewController in which I have a scrollView in which I have 3 views. This is a scheme :
* ScrollView (UIScrollView)
+ Header (UIView)
+ TabBar (UIView)
+ Container (UIView in which I load a ViewController)
The main problem is that, in my container (in which there is a view controller), I have a collectionView (which can scroll) but I want my entire scrollView to scroll (not only my container).
So this is what I have :
[](https://i.stack.imgur.com/rNt7T.png)
And this is what I want :
[](https://i.stack.imgur.com/dOstz.png)
Anyone can help me with this ?
|
2015/08/04
|
[
"https://Stackoverflow.com/questions/31809602",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3369214/"
] |
I just solved this problem for my own project. Assuming you are using storyboards, I made the UIView a child of UITableView and made the UITableView extend the full viewport of the device.
Since UITableView implements UIScrollView you get full screen scrolling of your content.
**General Rule** your parent view has to implement UIScrollView and extend the full screen to get viewport vertical scrolling.
[](https://i.stack.imgur.com/zyaV0.png)
|
You should set the frame of the container view to match the height of the view controller that it is loaded in it and set the contentsize of the scroolview based on the container height.
|
31,809,602 |
I have a viewController in which I have a scrollView in which I have 3 views. This is a scheme :
* ScrollView (UIScrollView)
+ Header (UIView)
+ TabBar (UIView)
+ Container (UIView in which I load a ViewController)
The main problem is that, in my container (in which there is a view controller), I have a collectionView (which can scroll) but I want my entire scrollView to scroll (not only my container).
So this is what I have :
[](https://i.stack.imgur.com/rNt7T.png)
And this is what I want :
[](https://i.stack.imgur.com/dOstz.png)
Anyone can help me with this ?
|
2015/08/04
|
[
"https://Stackoverflow.com/questions/31809602",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3369214/"
] |
I just solved this problem for my own project. Assuming you are using storyboards, I made the UIView a child of UITableView and made the UITableView extend the full viewport of the device.
Since UITableView implements UIScrollView you get full screen scrolling of your content.
**General Rule** your parent view has to implement UIScrollView and extend the full screen to get viewport vertical scrolling.
[](https://i.stack.imgur.com/zyaV0.png)
|
**A scrollview will scroll only if its contents are bigger than its frame.** This applies to the parent scrollview as well as the child scrollview.
Here in your case, for the parent scrollview to scroll its contents (Header, Tabbar & container) together must have greater height than its parent. The child scrollview (container) is already scrolling because its contents (a view controller) has greater height than its parent.
I have made both scroll views to scroll:
(1) The parent scrollview - by increasing the height of the child scrollview so that it extends below the main view controller's frame. The child scrollview is one of the contents of the main scrollview.
(2) The child scrollview - Setting a large content inside it so that it is bigger than its parent. I have used a long UIImage as its content.
Also, **I have used autolayout and pinned the contents to the scrollviews' sides by adding constraints.**
Hope this helps.
This is how it scrolls: [Scrolling of UIScrollView inside another](https://youtu.be/J5Qu9gEOJdc)
|
1,114,284 |
Is there a way I can prove that $O(3^{2n})$ does NOT equal $10^n$? How would that be done? Also, is it okay to simplify $O(3^{2n})$ to $O(9^n)$ to do so?
|
2015/01/21
|
[
"https://math.stackexchange.com/questions/1114284",
"https://math.stackexchange.com",
"https://math.stackexchange.com/users/209622/"
] |
To answer your second question first: yes, it is allowable to simplify $3^{2n}$ to $9^n$.
Recall that $f\in \mathcal O(g)$ iff:
$$\limsup\_{x\to\infty}\frac{f(x)}{g(x)} = c,\quad 0\leq c < \infty$$
Letting $f(x) = 10^x$ and $g(x) = 9^x$, and taking the limit:
\begin{align}
\limsup\_{x\to\infty}\frac{f(x)}{g(x)} &= \limsup\_{x\to\infty}\frac{10^x}{9^x}\\
&= \limsup\_{x\to\infty}\left(\frac{10}{9}\right)^x \\
&\to \infty
\end{align}
(The last simplification is because $10/9 > 1$.)
Therefore, $f\not\in\mathcal O(g)$.
|
It seems that you want to show that $10^n\notin O(3^{2n})$.
To prove that $10^n$ is not $O(3^{2n})$ it is enough to show that for any $M$ there is $n$ such that $10^n > M\cdot3^{2n}$, in particular
\begin{align}
10^n &> M\cdot 9^n\\
\frac{10^n}{9^n} &> M \\
n &> \log\_{\frac{10}{9}} M
\end{align}
so $n = \left\lfloor\frac{\log M}{\log\frac{10}{9}}\right\rfloor + 1$ suffices.
I hope this helps $\ddot\smile$
|
1,114,284 |
Is there a way I can prove that $O(3^{2n})$ does NOT equal $10^n$? How would that be done? Also, is it okay to simplify $O(3^{2n})$ to $O(9^n)$ to do so?
|
2015/01/21
|
[
"https://math.stackexchange.com/questions/1114284",
"https://math.stackexchange.com",
"https://math.stackexchange.com/users/209622/"
] |
In this answer, whenever I say "function," I mean a positive real-valued function on the natural numbers $\{1, 2, 3, \ldots\}$.
Big-O notation is a way to compare the growth rates of functions as their arguments go to infinity. Let's define a relation $\preccurlyeq$ between functions by saying that $f \preccurlyeq g$ if the ratio $\frac{f(n)}{g(n)}$ remains bounded below some constant as $n$ goes to infinity.
The symbol $O(g)$ refers to the set of functions $f$ with the property that $f \preccurlyeq g$. When talking quickly, people often say things like "$f$ is $O(g)$." They really mean "$f$ is in the set $O(g)$," which is the same thing as saying "$f \preccurlyeq g$."
Here are some examples of how the $\preccurlyeq$ relation works.
* The statement $5n^2 + 10 \preccurlyeq n^3$ is true, because $\frac{5 n^2 + 10}{n^3}$ is always less or equal to than 15, no matter how big $n$ gets. You can see this by rewriting the ratio as $5 \frac{1}{n} + 10 \frac{1}{n^3}$.
* The statement $n^3 \preccurlyeq n^2$ is false, because you can make $\frac{n^3}{n^2}$ as big as you want by setting $n$ high enough. You can see this by rewriting the ratio as $n$.
* The statement $n^3 \preccurlyeq n^3 + 1$ is true, because $\frac{n^3}{n^3 + 1}$ is always less than 1, no matter how big $n$ gets.
* The statement $n^3 + 1 \preccurlyeq n^3$ is also true, because $\frac{n^3 + 1}{n^3}$ is always less than or equal to 2, no matter how big $n$ gets.
* The statement $9^n \preccurlyeq 10^n$ is true, because $\frac{9^n}{10^n}$ is always less than 1, no matter how large $n$ gets. You can see this by rewriting the ratio as $\left(\frac{9}{10}\right)^n$.
* The statement $10^n \preccurlyeq 9^n$ is false, because you can make $\frac{10^n}{9^n}$ as large as you want by setting $n$ high enough. You can see this by rewriting the ratio as $\left(\frac{10}{9}\right)^n$.
---
The $\preccurlyeq$ relation between functions acts like the familiar $\le$ relation between numbers in two important ways:
* It's *transitive*: if $f \preccurlyeq g$ and $g \preccurlyeq h$, then $f \preccurlyeq h$.
* It's *reflexive*: $f \preccurlyeq f$ for any function $f$.
A relation with these properties is called a *preorder*. Keeping this properties in mind is very helpful when you're trying to prove things about the $\preccurlyeq$ relation. Here's an example.
>
> Let's say we want to prove that $5n^2 + 10 \preccurlyeq n^3 + 1$. We know from before that $5n^2 + 10 \preccurlyeq n^3$, and that $n^3 \preccurlyeq n^3 + 1$. Because $\preccurlyeq$ is trasitive, these two facts together imply the one we want to prove.
>
>
>
|
To answer your second question first: yes, it is allowable to simplify $3^{2n}$ to $9^n$.
Recall that $f\in \mathcal O(g)$ iff:
$$\limsup\_{x\to\infty}\frac{f(x)}{g(x)} = c,\quad 0\leq c < \infty$$
Letting $f(x) = 10^x$ and $g(x) = 9^x$, and taking the limit:
\begin{align}
\limsup\_{x\to\infty}\frac{f(x)}{g(x)} &= \limsup\_{x\to\infty}\frac{10^x}{9^x}\\
&= \limsup\_{x\to\infty}\left(\frac{10}{9}\right)^x \\
&\to \infty
\end{align}
(The last simplification is because $10/9 > 1$.)
Therefore, $f\not\in\mathcal O(g)$.
|
1,114,284 |
Is there a way I can prove that $O(3^{2n})$ does NOT equal $10^n$? How would that be done? Also, is it okay to simplify $O(3^{2n})$ to $O(9^n)$ to do so?
|
2015/01/21
|
[
"https://math.stackexchange.com/questions/1114284",
"https://math.stackexchange.com",
"https://math.stackexchange.com/users/209622/"
] |
In this answer, whenever I say "function," I mean a positive real-valued function on the natural numbers $\{1, 2, 3, \ldots\}$.
Big-O notation is a way to compare the growth rates of functions as their arguments go to infinity. Let's define a relation $\preccurlyeq$ between functions by saying that $f \preccurlyeq g$ if the ratio $\frac{f(n)}{g(n)}$ remains bounded below some constant as $n$ goes to infinity.
The symbol $O(g)$ refers to the set of functions $f$ with the property that $f \preccurlyeq g$. When talking quickly, people often say things like "$f$ is $O(g)$." They really mean "$f$ is in the set $O(g)$," which is the same thing as saying "$f \preccurlyeq g$."
Here are some examples of how the $\preccurlyeq$ relation works.
* The statement $5n^2 + 10 \preccurlyeq n^3$ is true, because $\frac{5 n^2 + 10}{n^3}$ is always less or equal to than 15, no matter how big $n$ gets. You can see this by rewriting the ratio as $5 \frac{1}{n} + 10 \frac{1}{n^3}$.
* The statement $n^3 \preccurlyeq n^2$ is false, because you can make $\frac{n^3}{n^2}$ as big as you want by setting $n$ high enough. You can see this by rewriting the ratio as $n$.
* The statement $n^3 \preccurlyeq n^3 + 1$ is true, because $\frac{n^3}{n^3 + 1}$ is always less than 1, no matter how big $n$ gets.
* The statement $n^3 + 1 \preccurlyeq n^3$ is also true, because $\frac{n^3 + 1}{n^3}$ is always less than or equal to 2, no matter how big $n$ gets.
* The statement $9^n \preccurlyeq 10^n$ is true, because $\frac{9^n}{10^n}$ is always less than 1, no matter how large $n$ gets. You can see this by rewriting the ratio as $\left(\frac{9}{10}\right)^n$.
* The statement $10^n \preccurlyeq 9^n$ is false, because you can make $\frac{10^n}{9^n}$ as large as you want by setting $n$ high enough. You can see this by rewriting the ratio as $\left(\frac{10}{9}\right)^n$.
---
The $\preccurlyeq$ relation between functions acts like the familiar $\le$ relation between numbers in two important ways:
* It's *transitive*: if $f \preccurlyeq g$ and $g \preccurlyeq h$, then $f \preccurlyeq h$.
* It's *reflexive*: $f \preccurlyeq f$ for any function $f$.
A relation with these properties is called a *preorder*. Keeping this properties in mind is very helpful when you're trying to prove things about the $\preccurlyeq$ relation. Here's an example.
>
> Let's say we want to prove that $5n^2 + 10 \preccurlyeq n^3 + 1$. We know from before that $5n^2 + 10 \preccurlyeq n^3$, and that $n^3 \preccurlyeq n^3 + 1$. Because $\preccurlyeq$ is trasitive, these two facts together imply the one we want to prove.
>
>
>
|
It seems that you want to show that $10^n\notin O(3^{2n})$.
To prove that $10^n$ is not $O(3^{2n})$ it is enough to show that for any $M$ there is $n$ such that $10^n > M\cdot3^{2n}$, in particular
\begin{align}
10^n &> M\cdot 9^n\\
\frac{10^n}{9^n} &> M \\
n &> \log\_{\frac{10}{9}} M
\end{align}
so $n = \left\lfloor\frac{\log M}{\log\frac{10}{9}}\right\rfloor + 1$ suffices.
I hope this helps $\ddot\smile$
|
4,474,228 |
My model is correctly validated. If I take a peak in the validation results during debug, I will see that everything is correct. However, *all* my validation results will show, even if only one is invalid. Again, during debug, only one field is correctly showing up in the validation results, but when my view is rendered all our displayed:
```
[HttpPost]
public ActionResult Create(Widget widget)
{
if (widge.Valid)
{
// Save to db
}
retun View(widget);
}
```
My view:
```
<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" AutoEventWireup="true" Inherits="System.Web.Mvc.ViewPage<Widget>" %>
// took out a lot of html here
<form action="Create" method="post">
<input name="Widget.City" value="<%= Model.City == null ? "" : Model.City%>" />
<%= Html.ValidationMessage("Widget.City")%>
<input name="Widget.Department" value="<%= Model.Department == null ? "" : Model.Department %>" />
<%= Html.ValidationMessage("Widget.Department")%>
<button type="submit">Save</button>
</form>
```
Let us say City and Department are set to `NotNull` in my model and I correctly put in a City, but leave Department blank. Again, it will show it is invalid on the controller, with the property Department having a problem, yet in my view I'll get "may not be null" messages for *both* properties. If I have 4 properties and 4 ValidationMessage tags in my view, even if one property is not valid ... all 4 will show. What's the deal?
|
2010/12/17
|
[
"https://Stackoverflow.com/questions/4474228",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/500038/"
] |
Try:
```
preg_match_all("/\d{10}/", $article, $tags);
```
|
```
preg_match('/[0-9]{10}/', $article, $tags);
```
Try that. Or if you have multiple IDs, you can use `preg_match_all`.
```
preg_match_all('/[0-9]{10}/', $article, $tags);
```
|
49,392 |
I have a custom Site page that contains some javascript code (using jquery and `SPServices`), that calls `Lists.asmx` Web service to perform CRUD operations on the list. At the init, my js code needs all list items. Recently I notided, that the latest added list items are not returned. Using Fiddler, I investigated that they are not simply included in the result set.
As older items seem to be useless for my code, there's a simply solution just to clear them.
But the question still remains, if the `Lists.asmx` has any limit of the items to return, and if it has how to configure it.
Thx in advance.
|
2012/10/18
|
[
"https://sharepoint.stackexchange.com/questions/49392",
"https://sharepoint.stackexchange.com",
"https://sharepoint.stackexchange.com/users/5118/"
] |
Like @Ben said, Chrome and SharePoint 2007 do not play nicely together. There is an extension for Chrome called IE Tab
[Chrome Extension for using IE](https://chrome.google.com/webstore/detail/ie-tab/hehijbfgiekmjfkfjpbkbammjbdenadd)
It will render the page using the IE engine while still in Chrome. You can configure it to use the IE Tab automatically by URL.
|
SharePoint and Chrome really don't play nice. FF is better but still has oddities. Leave your soul at the door and use the latest version of IE.
I feel dirty saying that.
|
14,904,398 |
I have two select statement like
```
Select author_id, count(text) from posts group by author_id
select author_id, count(text) from posts where postcounter =1 group by author_id
```
Is there a way to combine in a single query the two statements? Results differ in length, so it is needed to insert some 0s in the second resultset.
Many thanks for any help
Best regards,
Simone
|
2013/02/15
|
[
"https://Stackoverflow.com/questions/14904398",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/299791/"
] |
You should be able to get this in a single query using:
```
Select author_id,
count(text) TextCount,
count(case when postcounter=1 then text end) PostCount
from posts
group by author_id
```
|
Is this what you're looking for?
```
select author_id,
sum(case when postcounter = 1 then 1 else 0 end) count1,
sum(case when postcounter <> 1 then 1 else 0 end) count2,
count(text) allcount
from posts
group by author_id
```
|
14,904,398 |
I have two select statement like
```
Select author_id, count(text) from posts group by author_id
select author_id, count(text) from posts where postcounter =1 group by author_id
```
Is there a way to combine in a single query the two statements? Results differ in length, so it is needed to insert some 0s in the second resultset.
Many thanks for any help
Best regards,
Simone
|
2013/02/15
|
[
"https://Stackoverflow.com/questions/14904398",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/299791/"
] |
Is this what you're looking for?
```
select author_id,
sum(case when postcounter = 1 then 1 else 0 end) count1,
sum(case when postcounter <> 1 then 1 else 0 end) count2,
count(text) allcount
from posts
group by author_id
```
|
You can try a union all statement?
```
SELECT `id`,sum(`count`) FROM (
Select author_id as `id`, count(text) as `count` from posts group by author_id
UNION ALL
select author_id as `id`, count(text) as `count` from posts where postcounter =1 group by author_id
)
```
|
14,904,398 |
I have two select statement like
```
Select author_id, count(text) from posts group by author_id
select author_id, count(text) from posts where postcounter =1 group by author_id
```
Is there a way to combine in a single query the two statements? Results differ in length, so it is needed to insert some 0s in the second resultset.
Many thanks for any help
Best regards,
Simone
|
2013/02/15
|
[
"https://Stackoverflow.com/questions/14904398",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/299791/"
] |
You should be able to get this in a single query using:
```
Select author_id,
count(text) TextCount,
count(case when postcounter=1 then text end) PostCount
from posts
group by author_id
```
|
You can try a union all statement?
```
SELECT `id`,sum(`count`) FROM (
Select author_id as `id`, count(text) as `count` from posts group by author_id
UNION ALL
select author_id as `id`, count(text) as `count` from posts where postcounter =1 group by author_id
)
```
|
18,329,564 |
I'm building a site in Bootstrap 3.
Is there anyway to make a element use the class pull-left on smaller devices and use pull-right on larger ones?
Something like: *pull-left-sm pull-right-lg.*
I've managed to do it with jquery, catching the resize of the window. Is there any other way? Pref without duplicating the code in a hidden-x pull-left. Or is it considered more ok to duplicate code/content now when going responsive?
|
2013/08/20
|
[
"https://Stackoverflow.com/questions/18329564",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1676860/"
] |
There is no need to create your own class with media queries. Bootstrap 3 already has float ordering for media breakpoints under [Column Ordering](http://getbootstrap.com/css/#grid-column-ordering).
The syntax for the class is `col-<#grid-size>-(push|pull)-<#cols>` where `<#grid-size>` is `xs`, `sm`, `md` or `lg` and `<#cols>` is how far you want the column to move for that grid size. Push or pull is left or right of course.
I use it all the time so I know it works well.
|
LESS version of @Alex's answer
```
@media (max-width: @screen-xs-max) {
.pull-xs-left {
.pull-left();
}
.pull-xs-right {
.pull-right();
}
}
@media (min-width: @screen-sm-min) and (max-width: @screen-sm-max) {
.pull-sm-left {
.pull-left();
}
.pull-sm-right {
.pull-right();
}
}
@media (min-width: @screen-md-min) and (max-width: @screen-md-max) {
.pull-md-left {
.pull-left();
}
.pull-md-right {
.pull-right();
}
}
@media (min-width: @screen-lg-min) {
.pull-lg-left {
.pull-left();
}
.pull-lg-right {
.pull-right();
}
}
```
|
18,329,564 |
I'm building a site in Bootstrap 3.
Is there anyway to make a element use the class pull-left on smaller devices and use pull-right on larger ones?
Something like: *pull-left-sm pull-right-lg.*
I've managed to do it with jquery, catching the resize of the window. Is there any other way? Pref without duplicating the code in a hidden-x pull-left. Or is it considered more ok to duplicate code/content now when going responsive?
|
2013/08/20
|
[
"https://Stackoverflow.com/questions/18329564",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1676860/"
] |
You can use [CSS Media Queries](https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Media_queries)
basic usage will be like this; if you want to float left below devices of width 500px, then
```
@media (max-width: 500px) {
.your_class {
float: left;
}
}
@media (min-width: 501px) {
.your_class {
float: right;
}
}
```
|
Yes. Create your own style. I don’t know what element you’re trying to float left/right, but create an **application.css** file and create a CSS class for it:
```
/* default, mobile-first styles */
.logo {
float: left;
}
/* tablets and upwards */
@media (min-width: 768px) {
.logo {
float: right;
}
}
```
Don’t be afraid to write custom CSS. Bootstrap is meant to be exactly that: a bootstrap, a starter point.
|
18,329,564 |
I'm building a site in Bootstrap 3.
Is there anyway to make a element use the class pull-left on smaller devices and use pull-right on larger ones?
Something like: *pull-left-sm pull-right-lg.*
I've managed to do it with jquery, catching the resize of the window. Is there any other way? Pref without duplicating the code in a hidden-x pull-left. Or is it considered more ok to duplicate code/content now when going responsive?
|
2013/08/20
|
[
"https://Stackoverflow.com/questions/18329564",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1676860/"
] |
There is no need to create your own class with media queries. Bootstrap 3 already has float ordering for media breakpoints under [Column Ordering](http://getbootstrap.com/css/#grid-column-ordering).
The syntax for the class is `col-<#grid-size>-(push|pull)-<#cols>` where `<#grid-size>` is `xs`, `sm`, `md` or `lg` and `<#cols>` is how far you want the column to move for that grid size. Push or pull is left or right of course.
I use it all the time so I know it works well.
|
This is what i am using . change @screen-xs-max for other sizes
```
/* Pull left in mobile resolutions */
@media (max-width: @screen-xs-max) {
.pull-xs-right {
float: right !important;
}
.pull-xs-left {
float: left !important;
}
.radio-inline.pull-xs-left + .radio-inline.pull-xs-left ,
.checkbox-inline.pull-xs-left + .checkbox-inline.pull-xs-left {
margin-left: 0;
}
.radio-inline.pull-xs-left, .checkbox-inline.pull-xs-left{
margin-right: 10px;
}
}
```
|
18,329,564 |
I'm building a site in Bootstrap 3.
Is there anyway to make a element use the class pull-left on smaller devices and use pull-right on larger ones?
Something like: *pull-left-sm pull-right-lg.*
I've managed to do it with jquery, catching the resize of the window. Is there any other way? Pref without duplicating the code in a hidden-x pull-left. Or is it considered more ok to duplicate code/content now when going responsive?
|
2013/08/20
|
[
"https://Stackoverflow.com/questions/18329564",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1676860/"
] |
You can use [CSS Media Queries](https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Media_queries)
basic usage will be like this; if you want to float left below devices of width 500px, then
```
@media (max-width: 500px) {
.your_class {
float: left;
}
}
@media (min-width: 501px) {
.your_class {
float: right;
}
}
```
|
This is what i am using . change @screen-xs-max for other sizes
```
/* Pull left in mobile resolutions */
@media (max-width: @screen-xs-max) {
.pull-xs-right {
float: right !important;
}
.pull-xs-left {
float: left !important;
}
.radio-inline.pull-xs-left + .radio-inline.pull-xs-left ,
.checkbox-inline.pull-xs-left + .checkbox-inline.pull-xs-left {
margin-left: 0;
}
.radio-inline.pull-xs-left, .checkbox-inline.pull-xs-left{
margin-right: 10px;
}
}
```
|
18,329,564 |
I'm building a site in Bootstrap 3.
Is there anyway to make a element use the class pull-left on smaller devices and use pull-right on larger ones?
Something like: *pull-left-sm pull-right-lg.*
I've managed to do it with jquery, catching the resize of the window. Is there any other way? Pref without duplicating the code in a hidden-x pull-left. Or is it considered more ok to duplicate code/content now when going responsive?
|
2013/08/20
|
[
"https://Stackoverflow.com/questions/18329564",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1676860/"
] |
Just add this to your SASS file:
```
@media (max-width: $screen-xs-max) {
.pull-xs-left {
float: left;
}
.pull-xs-right {
float: right;
}
}
@media (min-width: $screen-sm-min) and (max-width: $screen-sm-max) {
.pull-sm-left {
float: left;
}
.pull-sm-right {
float: right;
}
}
@media (min-width: $screen-md-min) and (max-width: $screen-md-max) {
.pull-md-left {
float: left;
}
.pull-md-right {
float: right;
}
}
@media (min-width: $screen-lg-min) {
.pull-lg-left {
float: left;
}
.pull-lg-right {
float: right;
}
}
```
Insert actual px values for `$screen-*` if you use plain CSS of course.
HTML:
```
<div class="pull-md-left pull-lg-left">
this div is only floated on screen-md and screen-lg
</div>
```
|
Yes. Create your own style. I don’t know what element you’re trying to float left/right, but create an **application.css** file and create a CSS class for it:
```
/* default, mobile-first styles */
.logo {
float: left;
}
/* tablets and upwards */
@media (min-width: 768px) {
.logo {
float: right;
}
}
```
Don’t be afraid to write custom CSS. Bootstrap is meant to be exactly that: a bootstrap, a starter point.
|
18,329,564 |
I'm building a site in Bootstrap 3.
Is there anyway to make a element use the class pull-left on smaller devices and use pull-right on larger ones?
Something like: *pull-left-sm pull-right-lg.*
I've managed to do it with jquery, catching the resize of the window. Is there any other way? Pref without duplicating the code in a hidden-x pull-left. Or is it considered more ok to duplicate code/content now when going responsive?
|
2013/08/20
|
[
"https://Stackoverflow.com/questions/18329564",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1676860/"
] |
You can use [CSS Media Queries](https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Media_queries)
basic usage will be like this; if you want to float left below devices of width 500px, then
```
@media (max-width: 500px) {
.your_class {
float: left;
}
}
@media (min-width: 501px) {
.your_class {
float: right;
}
}
```
|
There is no need to create your own class with media queries. Bootstrap 3 already has float ordering for media breakpoints under [Column Ordering](http://getbootstrap.com/css/#grid-column-ordering).
The syntax for the class is `col-<#grid-size>-(push|pull)-<#cols>` where `<#grid-size>` is `xs`, `sm`, `md` or `lg` and `<#cols>` is how far you want the column to move for that grid size. Push or pull is left or right of course.
I use it all the time so I know it works well.
|
18,329,564 |
I'm building a site in Bootstrap 3.
Is there anyway to make a element use the class pull-left on smaller devices and use pull-right on larger ones?
Something like: *pull-left-sm pull-right-lg.*
I've managed to do it with jquery, catching the resize of the window. Is there any other way? Pref without duplicating the code in a hidden-x pull-left. Or is it considered more ok to duplicate code/content now when going responsive?
|
2013/08/20
|
[
"https://Stackoverflow.com/questions/18329564",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1676860/"
] |
Possibly you can use [column ordering](https://getbootstrap.com/docs/3.3/css/#grid-column-ordering).
```
<div class="row">
<div class="col-md-9 col-md-push-3">.col-md-9 .col-md-push-3</div>
<div class="col-md-3 col-md-pull-9">.col-md-3 .col-md-pull-9</div>
</div>
```
Looks like floating columns will be getting added to version 4 by like @Alex has done - <https://github.com/twbs/bootstrap/issues/13690>
|
LESS version of @Alex's answer
```
@media (max-width: @screen-xs-max) {
.pull-xs-left {
.pull-left();
}
.pull-xs-right {
.pull-right();
}
}
@media (min-width: @screen-sm-min) and (max-width: @screen-sm-max) {
.pull-sm-left {
.pull-left();
}
.pull-sm-right {
.pull-right();
}
}
@media (min-width: @screen-md-min) and (max-width: @screen-md-max) {
.pull-md-left {
.pull-left();
}
.pull-md-right {
.pull-right();
}
}
@media (min-width: @screen-lg-min) {
.pull-lg-left {
.pull-left();
}
.pull-lg-right {
.pull-right();
}
}
```
|
18,329,564 |
I'm building a site in Bootstrap 3.
Is there anyway to make a element use the class pull-left on smaller devices and use pull-right on larger ones?
Something like: *pull-left-sm pull-right-lg.*
I've managed to do it with jquery, catching the resize of the window. Is there any other way? Pref without duplicating the code in a hidden-x pull-left. Or is it considered more ok to duplicate code/content now when going responsive?
|
2013/08/20
|
[
"https://Stackoverflow.com/questions/18329564",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1676860/"
] |
Just add this to your SASS file:
```
@media (max-width: $screen-xs-max) {
.pull-xs-left {
float: left;
}
.pull-xs-right {
float: right;
}
}
@media (min-width: $screen-sm-min) and (max-width: $screen-sm-max) {
.pull-sm-left {
float: left;
}
.pull-sm-right {
float: right;
}
}
@media (min-width: $screen-md-min) and (max-width: $screen-md-max) {
.pull-md-left {
float: left;
}
.pull-md-right {
float: right;
}
}
@media (min-width: $screen-lg-min) {
.pull-lg-left {
float: left;
}
.pull-lg-right {
float: right;
}
}
```
Insert actual px values for `$screen-*` if you use plain CSS of course.
HTML:
```
<div class="pull-md-left pull-lg-left">
this div is only floated on screen-md and screen-lg
</div>
```
|
There is no need to create your own class with media queries. Bootstrap 3 already has float ordering for media breakpoints under [Column Ordering](http://getbootstrap.com/css/#grid-column-ordering).
The syntax for the class is `col-<#grid-size>-(push|pull)-<#cols>` where `<#grid-size>` is `xs`, `sm`, `md` or `lg` and `<#cols>` is how far you want the column to move for that grid size. Push or pull is left or right of course.
I use it all the time so I know it works well.
|
18,329,564 |
I'm building a site in Bootstrap 3.
Is there anyway to make a element use the class pull-left on smaller devices and use pull-right on larger ones?
Something like: *pull-left-sm pull-right-lg.*
I've managed to do it with jquery, catching the resize of the window. Is there any other way? Pref without duplicating the code in a hidden-x pull-left. Or is it considered more ok to duplicate code/content now when going responsive?
|
2013/08/20
|
[
"https://Stackoverflow.com/questions/18329564",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1676860/"
] |
You can use [CSS Media Queries](https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Media_queries)
basic usage will be like this; if you want to float left below devices of width 500px, then
```
@media (max-width: 500px) {
.your_class {
float: left;
}
}
@media (min-width: 501px) {
.your_class {
float: right;
}
}
```
|
LESS version of @Alex's answer
```
@media (max-width: @screen-xs-max) {
.pull-xs-left {
.pull-left();
}
.pull-xs-right {
.pull-right();
}
}
@media (min-width: @screen-sm-min) and (max-width: @screen-sm-max) {
.pull-sm-left {
.pull-left();
}
.pull-sm-right {
.pull-right();
}
}
@media (min-width: @screen-md-min) and (max-width: @screen-md-max) {
.pull-md-left {
.pull-left();
}
.pull-md-right {
.pull-right();
}
}
@media (min-width: @screen-lg-min) {
.pull-lg-left {
.pull-left();
}
.pull-lg-right {
.pull-right();
}
}
```
|
18,329,564 |
I'm building a site in Bootstrap 3.
Is there anyway to make a element use the class pull-left on smaller devices and use pull-right on larger ones?
Something like: *pull-left-sm pull-right-lg.*
I've managed to do it with jquery, catching the resize of the window. Is there any other way? Pref without duplicating the code in a hidden-x pull-left. Or is it considered more ok to duplicate code/content now when going responsive?
|
2013/08/20
|
[
"https://Stackoverflow.com/questions/18329564",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1676860/"
] |
There is no need to create your own class with media queries. Bootstrap 3 already has float ordering for media breakpoints under [Column Ordering](http://getbootstrap.com/css/#grid-column-ordering).
The syntax for the class is `col-<#grid-size>-(push|pull)-<#cols>` where `<#grid-size>` is `xs`, `sm`, `md` or `lg` and `<#cols>` is how far you want the column to move for that grid size. Push or pull is left or right of course.
I use it all the time so I know it works well.
|
Yes. Create your own style. I don’t know what element you’re trying to float left/right, but create an **application.css** file and create a CSS class for it:
```
/* default, mobile-first styles */
.logo {
float: left;
}
/* tablets and upwards */
@media (min-width: 768px) {
.logo {
float: right;
}
}
```
Don’t be afraid to write custom CSS. Bootstrap is meant to be exactly that: a bootstrap, a starter point.
|
69,448,661 |
I am new to Snakemake, and I'm wondering if I'm able to put optional output files in a snakemake rule while using `expand()`.
I'm using `bowtie2-build` to create an indexing of my reference genome, but depending on the genome size, bowtie2 creates indexing files with different extensions: `.bt2` for small genomes, and `.bt21` for big genomes.
I have the following rule:
```
rule bowtie2_build:
"""
"""
input:
"reference/"+config["reference_genome"]+".fa"
output:
# every possible extension in expand
expand("reference/"+config["reference_genome"]+"{suffix}", suffix=[".1.bt2", ".2.bt2", ".3.bt2", ".4.bt2", ".rev.1.bt2", ".rev.2.bt2", ".1.bt21", ".2.bt21", ".3.bt21", ".4.bt21", ".rev.1.bt21", ".rev.2.bt21"])
params:
output_prefix=config["reference_genome"]
shell:
"bowtie2-build {input} reference/{params.output_prefix}"
```
But now, snakemake will always look for output with all extensions, which will give an error while running, because only files with either one of the two extensions `.bt2` or `.bt21` are actually created depending on genome size.
I have tried to use regex like so:
```
output:
"reference/"+config["reference_genome"]+"{suffix, \.(1|2|3|4|rev)\.(bt2|bt21|1|2)\.?(bt2|bt21)?}"
```
And this works, but I feel like there should be an easier way for it.
|
2021/10/05
|
[
"https://Stackoverflow.com/questions/69448661",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17078546/"
] |
Perhaps you are making things more complicated than necessary. Bowtie2 (the aligner) takes in input the prefix of the index files and it will find the actual index files by itself. So I wouldn't list the index files as output of any rule. Just use a flag file to indicate that indexing has been completed. For example:
```
rule all:
input:
expand('{sample}.sam', sample= ['A', 'B', 'C']),
rule bowtie_build:
input:
fa= 'genome.fa',
output:
touch('index.done'), # Flag file
params:
index_prefix= 'genome',
shell:
r"""
bowtie2-build {input.fa} {params.index_prefix}
"""
rule bowtie_align:
input:
idx= 'index.done',
fq1= '{sample}.R1.fastq.gz',
output:
sam= '{sample}.sam',
params:
index_prefix= 'genome'
shell:
r"""
bowtie2 -x {params.index_prefix} -U {input.fq1} -S {output.sam}
"""
```
|
This approach is to rename the files with a different extension. It will print an error if such file does not exist, but you might consider this a feature...:
```py
rule bowtie2_build:
input:
"reference/"+config["reference_genome"]+".fa"
output:
expand("reference/"+config["reference_genome"]+"{suffix}", suffix=[".1.bt2", ".2.bt2", ".3.bt2", ".4.bt2", ".rev.1.bt2", ".rev.2.bt2"])
params:
output_prefix=config["reference_genome"],
file_name = "reference/"+config["reference_genome"],
shell:
"""
bowtie2-build {input} reference/{params.output_prefix}
mv -v {params.file_name}.1.bt21 {params.file_name}.1.bt2
mv -v {params.file_name}.2.bt21 {params.file_name}.2.bt2
mv -v {params.file_name}.3.bt21 {params.file_name}.3.bt2
# etc... it's also possible to put this in a bash loop
"""
```
In other examples, where the input file has information about the output, e.g. if the genome sequence size is known from the outset, then one option is to generate two rules, `bowtie2_build` and `bowtie2_build_big`, that will specify different extensions.
|
69,448,661 |
I am new to Snakemake, and I'm wondering if I'm able to put optional output files in a snakemake rule while using `expand()`.
I'm using `bowtie2-build` to create an indexing of my reference genome, but depending on the genome size, bowtie2 creates indexing files with different extensions: `.bt2` for small genomes, and `.bt21` for big genomes.
I have the following rule:
```
rule bowtie2_build:
"""
"""
input:
"reference/"+config["reference_genome"]+".fa"
output:
# every possible extension in expand
expand("reference/"+config["reference_genome"]+"{suffix}", suffix=[".1.bt2", ".2.bt2", ".3.bt2", ".4.bt2", ".rev.1.bt2", ".rev.2.bt2", ".1.bt21", ".2.bt21", ".3.bt21", ".4.bt21", ".rev.1.bt21", ".rev.2.bt21"])
params:
output_prefix=config["reference_genome"]
shell:
"bowtie2-build {input} reference/{params.output_prefix}"
```
But now, snakemake will always look for output with all extensions, which will give an error while running, because only files with either one of the two extensions `.bt2` or `.bt21` are actually created depending on genome size.
I have tried to use regex like so:
```
output:
"reference/"+config["reference_genome"]+"{suffix, \.(1|2|3|4|rev)\.(bt2|bt21|1|2)\.?(bt2|bt21)?}"
```
And this works, but I feel like there should be an easier way for it.
|
2021/10/05
|
[
"https://Stackoverflow.com/questions/69448661",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17078546/"
] |
Perhaps you are making things more complicated than necessary. Bowtie2 (the aligner) takes in input the prefix of the index files and it will find the actual index files by itself. So I wouldn't list the index files as output of any rule. Just use a flag file to indicate that indexing has been completed. For example:
```
rule all:
input:
expand('{sample}.sam', sample= ['A', 'B', 'C']),
rule bowtie_build:
input:
fa= 'genome.fa',
output:
touch('index.done'), # Flag file
params:
index_prefix= 'genome',
shell:
r"""
bowtie2-build {input.fa} {params.index_prefix}
"""
rule bowtie_align:
input:
idx= 'index.done',
fq1= '{sample}.R1.fastq.gz',
output:
sam= '{sample}.sam',
params:
index_prefix= 'genome'
shell:
r"""
bowtie2 -x {params.index_prefix} -U {input.fq1} -S {output.sam}
"""
```
|
Seems like a use for [checkpoints](https://snakemake.readthedocs.io/en/stable/snakefiles/rules.html#data-dependent-conditional-execution). With checkpoints, the DAG will be reevaluated after the checkpoint's execution. You could do something like this:
```
from glob import glob
def get_ref_index(wildcards):
"""Returns the reference index for wildcards"""
checkpoints.bowtie2_build.get() # Checks to see if the checkpoint rule has been run, might be an issue without wildcards
suffix=[".1.bt2", ".2.bt2", ".3.bt2", ".4.bt2", ".rev.1.bt2", ".rev.2.bt2", ".1.bt21", ".2.bt21", ".3.bt21", ".4.bt21", ".rev.1.bt21", ".rev.2.bt21"]
ref_files = glob.glob("reference/" + config["reference_genome"] + "*") # List files with reference genome pattern
for ref in ref_files:
suffix = ref.split(".", 1)[1] # Split on first period to grab all suffixes
if suffix in suffixes:
return ref
checkpoint bowtie2_build:
input:
"reference/"+config["reference_genome"]+".fa"
output:
touch("reference/"+config["reference_genome"]+".done") # Breadcrumb file to link to downstream rules, since we don't know what indexes we'll get
params:
output_prefix=config["reference_genome"]
shell:
"bowtie2-build {input} reference/{params.output_prefix}"
rule donwstream_rule:
input:
ref = "reference/"+config["reference_genome"]+".fa"
ref_index = get_ref_index
ref_index_done = "reference/"+config["reference_genome"]+".done"
output:
foo = "bar"
shell:
"touch bar"
```
|
59,892,408 |
I have a GUI application created with PyQt and I would like to be able to control it also from the python terminal through a kind of internal API.
Ideas :
* Using the main terminal : impossible since that it is blocked by the QApplication (by app.exec\_())
* Starting the GUI in another thread to free the main one : impossible, the QApplications have to be executed in the main one.
* ???
I don't want an 'in-app' terminal.
Do you have any other ideas ?
|
2020/01/24
|
[
"https://Stackoverflow.com/questions/59892408",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4958910/"
] |
You have to set the `data` and `columns` value. So try it like this:
```js
import React, { useState, useEffect } from "react";
import MaterialTable, { MTableToolbar } from "material-table";
const fakeFetch = () => {
return new Promise(resolve => {
resolve({
data: [
{ brand: "brand 1", price: 1, model: "123" },
{ brand: "brand 2", price: 1, model: "456" },
{ brand: "brand 3", price: 1, model: "789" }
]
});
});
};
export default function App() {
const [data, setData] = useState([]);
// When the columns don't change you don't need to hold it in state
const columns = [
{ title: "Brand", field: "brand" }, //assume here my backend schema is brand
{ title: "Price", field: "price" }, //here price
{ title: "Model no", field: "model" } //here model
];
const getProducts = async () => {
try {
const res = await fakeFetch();
setData(res.data);
} catch (error) {
console.log(error);
}
};
useEffect(() => {
getProducts();
}, []);
return (
<MaterialTable
columns={columns} // <-- Set the columns on the table
data={data} // <-- Set the data on the table
components={{
Toolbar: props => {
return (
<div>
<MTableToolbar {...props} />
</div>
);
}
}}
options={{
actionsColumnIndex: 5,
selection: true
}}
/>
);
}
```
To make it even easier you could also provide your fetch function (`fakeFetch` in this case) as the data value;
```js
data={fakeFetch} // <-- Using this you wouldn't need the [data, setData], getProducts and useEffect code.
```
[Working sandbox link](https://codesandbox.io/s/spring-pine-6h5bg?fontsize=14&hidenavigation=1&theme=dark)
|
As per the material-table approach, you have to put your whole fetched data on the `data` prop inside the `MaterialTable` component. So as far as I can understand, there is no looping made in this case by using the material-table library.
Assuming the attributes in your data object match the field names specified in your `columns` prop (if not, create an array of objects from your fetched data that matches the column fields or vice-versa).
And the code would be just the addition of the `data` prop in your table:
```
<MaterialTable
// ... existing props
data={data}
/>
```
Keep in mind that you could also use the [remote data](https://material-table.com/#/docs/features/remote-data) approach as described in the documentation which gives you the means to immediately query your data and fetch it inside the `data` prop of the table.
|
20,275,988 |
Without spending nights of digging through the source code, I was hoping someone could shed some light on how Node is able to communicate with the operating system and do such things as writing files to the file system? I've even seen a package which allows bidirectional communication with the .NET runtime.
My very simple understanding of Node is that it's the V8 engine taken from Chome and packaged up. However writing files to the file system using JavaScript from within Chrome is not possible.
How does Node allow JavaScript to extend past its sandbox? What special syntax is used by JavaScript to call out to external C++ libs?
|
2013/11/28
|
[
"https://Stackoverflow.com/questions/20275988",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17211/"
] |
V8 in Chrome isn't sandboxed because V8 is sandboxed. It's sandboxed because Chrome sandboxes it.
|
Only way to use the operating system functionality is to make system call. For example to create a new file Windows exports systemcall CreateFile(). The V8 engine interprets the javascript code and makes call to NODEJS core library
NodeJs itslef is written in c/C++ . calls are made through V8 engine to NODEJS core libraries and its these library which perform the tasks.
|
51,609,471 |
I'm new to this and I'm getting an error that I was hoping someone could help me with and explain my error.
Error:
>
> line 178, in applyThrust
>
> shipPos = self.Fighter.getPos(self.origin)
>
> AttributeError: 'Fighter' object has no attribute 'Fighter'
>
>
>
```
class Fighter(SphereCollideObj, object):
fighterCount = 0
def __init__(self, modelPath, parentNode, nodeName, posVec, traverser, scaleVec = 1.0):
super(Fighter, self).__init__(modelPath, parentNode, nodeName, 0, 0, 0, 3.0)
self.modelNode.setScale(scaleVec)
self.modelNode.setPos(posVec)
self.trav = traverser
self.origin = render.attachNewNode("origin")
self.origin.setPos(0, 0, 0)
self.origin.hide()
self.setKeyBindings()
self.hud = Hud("./Tools/Hud.x", self.modelNode, "Hud", (0, 10, 0))
def setKeyBindings(self):
self.accept("space", self.thrust, [1])
self.accept("space-up", self.thrust, [0])
def thrust(self,keyDown):
if keyDown:
taskMgr.add(self.applyThrust, "thrust")
else:
taskMgr.remove("thrust")
self.acceptOnce("space", self.thrust,[1])
self.acceptOnce("space-up", self.thrust,[0])
def applyThrust(self, task):
shipPos = self.Fighter.getPos(self.origin)
hudPos = self.hud.modelNode.getPos(self.origin)
trajectory = hudPos - shipPos
rate = 5
trajectory.normalize()
self.Fighter.setFluidPos(shipPos + trajectory * rate)
```
|
2018/07/31
|
[
"https://Stackoverflow.com/questions/51609471",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9949630/"
] |
From my point of view, the .htaccess file should look like this:
```
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /pes/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
```
The access to dashboard must be checked in your main controller, depend on how you have designed the logic.
Also, the mapping of urls must be done in `application/config/routes.php` file
|
I Have done by removing this line from my dashboard controller.
```
public fucntion index()
{
if (!$this->session->userdata('is_logged')) {
//function code
}
}
```
|
176,591 |
Has anyone developed an approach to teaching mechanics based on Lagrangian/Hamiltonian mechanics from the ground up. I mean from high school on up. This is akin to explicitly not talking about components of vectors or developing pre-calculus in a coordinate-free (coordinate agnostic).
Perhaps I'm missing the point of Lagrangian/Hamiltonian formalism, but I am to emphasise the coordinate free approach rather than the specifics of deriving the equations. For example, the pendulum can be described as a system with 2 spatial coordinates(x,y) or one angle coordinate(theta). The latter is better.
Or does the Lagrangian/Hamiltonian approach require more advanced maths than a high school student is capable of.
|
2015/04/17
|
[
"https://physics.stackexchange.com/questions/176591",
"https://physics.stackexchange.com",
"https://physics.stackexchange.com/users/75644/"
] |
The most fundamental parts of Lagrangian mechanics involve calculus. The action principle involves an integral and the Euler-Lagrange equation is a partial differential equation. Unless the students are pretty good with calculus it will be quite hard to teach.
|
Maybe you can give a rough idea about what the subject is about. You can introduce first for example the Fermat's principle of least time and maybe kind of make an analogy like.
"There is a similar principle of minimization in mechanics where you minimize another quantity called action".
Maybe if an student is interested you can give him more information. There is a Feynman lecture when he said that a High school teacher told him a little bit about the principle here is the link :
<http://www.feynmanlectures.caltech.edu/II_19.html>
|
176,591 |
Has anyone developed an approach to teaching mechanics based on Lagrangian/Hamiltonian mechanics from the ground up. I mean from high school on up. This is akin to explicitly not talking about components of vectors or developing pre-calculus in a coordinate-free (coordinate agnostic).
Perhaps I'm missing the point of Lagrangian/Hamiltonian formalism, but I am to emphasise the coordinate free approach rather than the specifics of deriving the equations. For example, the pendulum can be described as a system with 2 spatial coordinates(x,y) or one angle coordinate(theta). The latter is better.
Or does the Lagrangian/Hamiltonian approach require more advanced maths than a high school student is capable of.
|
2015/04/17
|
[
"https://physics.stackexchange.com/questions/176591",
"https://physics.stackexchange.com",
"https://physics.stackexchange.com/users/75644/"
] |
The most fundamental parts of Lagrangian mechanics involve calculus. The action principle involves an integral and the Euler-Lagrange equation is a partial differential equation. Unless the students are pretty good with calculus it will be quite hard to teach.
|
If all you are looking for is a basic introduction without the calculus of variations, then the following article (which, however, assumes knowledge of elementary calculus as a prerequisite) may be of help:
Hanc, Jozef, Edwin F. Taylor, and Slavomir Tuleja. "Deriving Lagrange’s equations using elementary calculus." American Journal of Physics 72.4 (2004): 510-513.
There is an online version available [here](http://www.eftaylor.com/pub/lagrange.html).
Source:
I've seen this method successfully used in a first year undergraduate course on classical mechanics.
|
176,591 |
Has anyone developed an approach to teaching mechanics based on Lagrangian/Hamiltonian mechanics from the ground up. I mean from high school on up. This is akin to explicitly not talking about components of vectors or developing pre-calculus in a coordinate-free (coordinate agnostic).
Perhaps I'm missing the point of Lagrangian/Hamiltonian formalism, but I am to emphasise the coordinate free approach rather than the specifics of deriving the equations. For example, the pendulum can be described as a system with 2 spatial coordinates(x,y) or one angle coordinate(theta). The latter is better.
Or does the Lagrangian/Hamiltonian approach require more advanced maths than a high school student is capable of.
|
2015/04/17
|
[
"https://physics.stackexchange.com/questions/176591",
"https://physics.stackexchange.com",
"https://physics.stackexchange.com/users/75644/"
] |
If all you are looking for is a basic introduction without the calculus of variations, then the following article (which, however, assumes knowledge of elementary calculus as a prerequisite) may be of help:
Hanc, Jozef, Edwin F. Taylor, and Slavomir Tuleja. "Deriving Lagrange’s equations using elementary calculus." American Journal of Physics 72.4 (2004): 510-513.
There is an online version available [here](http://www.eftaylor.com/pub/lagrange.html).
Source:
I've seen this method successfully used in a first year undergraduate course on classical mechanics.
|
Maybe you can give a rough idea about what the subject is about. You can introduce first for example the Fermat's principle of least time and maybe kind of make an analogy like.
"There is a similar principle of minimization in mechanics where you minimize another quantity called action".
Maybe if an student is interested you can give him more information. There is a Feynman lecture when he said that a High school teacher told him a little bit about the principle here is the link :
<http://www.feynmanlectures.caltech.edu/II_19.html>
|
19,041,165 |
I'm having some confusion with the reasoning behind what seems to me to be an inconsistency.
For example
```
public class Test
{
static int a;
public static void main(String[] args)
{
System.out.println(a);
}
}
```
So that will print out 0, as expected. But say we had this instead,
```
public class Test
{
public static void main(String[] args)
{
int a;
System.out.println(a);
}
}
```
This won't compile for me, complaining that a hasn't been initialized. I was expecting it to print out 0...
Which leads me to some questions:
1) Why don't function scoped variables have default values?
2) Could the static keyword be the reason? And why?
|
2013/09/27
|
[
"https://Stackoverflow.com/questions/19041165",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
The Java Language Specification explains the default [Initial values of Variables](http://docs.oracle.com/javase/specs/jls/se7/html/jls-4.html#jls-4.12.5)
>
> Each class variable, instance variable, or array component is
> initialized with a default value when it is created (§15.9, §15.10):
>
>
> For type byte, the default value is zero, that is, the value of
> (byte)0.
>
>
> For type short, the default value is zero, that is, the value of
> (short)0.
>
>
> For type int, the default value is zero, that is, 0.
>
>
> For type long, the default value is zero, that is, 0L.
>
>
> For type float, the default value is positive zero, that is, 0.0f.
>
>
> For type double, the default value is positive zero, that is, 0.0d.
>
>
> For type char, the default value is the null character, that is,
> '\u0000'.
>
>
> For type boolean, the default value is false.
>
>
> For all reference types (§4.3), the default value is null.
>
>
>
and also states
>
> A local variable (§14.4, §14.14) must be explicitly given a value
> before it is used, by either initialization (§14.4) or assignment
> (§15.26), in a way that can be verified using the rules for definite
> assignment (§16).
>
>
>
Both your questions can be answered by "Because the JLS says so".
A more complete answer would be the following:
A Class is a description of state and behavior. An object is the actual data. If you create an object, it must have definitive state, it cannot be in an uninitialized state.
|
>
> 1) Why don't function scoped variables have default values?
>
>
>
It is the rule defined by [JLS](http://docs.oracle.com/javase/specs/jls/se7/html/jls-4.html#jls-4.12.5) that method variables are not initialized to thier default values. You need to initialize them beforeusing
>
> 2) Could the static keyword be the reason? And why?
>
>
>
Again form [JLS](http://docs.oracle.com/javase/specs/jls/se7/html/jls-4.html#jls-4.12.5) rules, class instance variables are initialized to default values by the compiler. You may or may not initialize them.
|
19,041,165 |
I'm having some confusion with the reasoning behind what seems to me to be an inconsistency.
For example
```
public class Test
{
static int a;
public static void main(String[] args)
{
System.out.println(a);
}
}
```
So that will print out 0, as expected. But say we had this instead,
```
public class Test
{
public static void main(String[] args)
{
int a;
System.out.println(a);
}
}
```
This won't compile for me, complaining that a hasn't been initialized. I was expecting it to print out 0...
Which leads me to some questions:
1) Why don't function scoped variables have default values?
2) Could the static keyword be the reason? And why?
|
2013/09/27
|
[
"https://Stackoverflow.com/questions/19041165",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
The Java Language Specification explains the default [Initial values of Variables](http://docs.oracle.com/javase/specs/jls/se7/html/jls-4.html#jls-4.12.5)
>
> Each class variable, instance variable, or array component is
> initialized with a default value when it is created (§15.9, §15.10):
>
>
> For type byte, the default value is zero, that is, the value of
> (byte)0.
>
>
> For type short, the default value is zero, that is, the value of
> (short)0.
>
>
> For type int, the default value is zero, that is, 0.
>
>
> For type long, the default value is zero, that is, 0L.
>
>
> For type float, the default value is positive zero, that is, 0.0f.
>
>
> For type double, the default value is positive zero, that is, 0.0d.
>
>
> For type char, the default value is the null character, that is,
> '\u0000'.
>
>
> For type boolean, the default value is false.
>
>
> For all reference types (§4.3), the default value is null.
>
>
>
and also states
>
> A local variable (§14.4, §14.14) must be explicitly given a value
> before it is used, by either initialization (§14.4) or assignment
> (§15.26), in a way that can be verified using the rules for definite
> assignment (§16).
>
>
>
Both your questions can be answered by "Because the JLS says so".
A more complete answer would be the following:
A Class is a description of state and behavior. An object is the actual data. If you create an object, it must have definitive state, it cannot be in an uninitialized state.
|
Java compiler never assigns default values to Local variables as mentioned in the link <http://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html>
You have to explicitly initialize them.
|
72,269,969 |
i want to write a game Lobby for a card game.
Using React.js, Node.js and Websocket.io for achieving this.
As so far all went fine. Players are connected in the same Lobby.
But i want to print in the Lobby sth Like (Player 1: Steven, Player 2: Frank, ...).
I ended up in an infinite loop, i am trying to solve since hours.
So maybe someone can help me. It keeps re-rendering by useState i guess, but i don't know how to prevent it from.
Relevant Frontend Code:
```
const Lobby = (props) => {
const socket = props.socket;
const player = {
room: props.room,
name: props.name,
};
const [playerList, setPlayerList] = useState([]);
socket.emit("joined_lobby", player);
console.log(`${playerList}`);
useEffect(() => {
socket.on("add_user", (data) => {
setPlayerList([...playerList, data.name]);
});
}, []);
```
Relevant Server Code:
```
io.on("connection", (socket) => { console.log(`Player with ID:\[${socket.id}\] Connected`);
socket.on("join_room", (data) => {
socket.join(data);
console.log(`Player with ID:\[${socket.id}\] Joined the room ${data}`); });
socket.on("joined_lobby", (data) => {
socket.to(data.room).emit("add_user", data); });
socket.on("disconnect", () => {
console.log(`Player with ID:\[${socket.id}\] Disonnected`); }); });
```
|
2022/05/17
|
[
"https://Stackoverflow.com/questions/72269969",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15966001/"
] |
This is set by the shortcut key. Open the **Default Keyboard Shortcuts** (**File** > **Preferences** > **Keyboard Shortcuts**) and search for "acceptSelectedSuggestion". You will see that there are only two settings by default, the `Tab` and `Enter` keys.
[](https://i.stack.imgur.com/AWts8.png)
If you want to add other buttons to trigger typing intellisense, right-click on one of the settings and select `Add Keybinding`,
[](https://i.stack.imgur.com/R1HaE.png)
then press the button you want to set, and press Enter to save.
|
I think you don't need to use the python autocomplete extension. You can just use the `Python` extension.
|
72,269,969 |
i want to write a game Lobby for a card game.
Using React.js, Node.js and Websocket.io for achieving this.
As so far all went fine. Players are connected in the same Lobby.
But i want to print in the Lobby sth Like (Player 1: Steven, Player 2: Frank, ...).
I ended up in an infinite loop, i am trying to solve since hours.
So maybe someone can help me. It keeps re-rendering by useState i guess, but i don't know how to prevent it from.
Relevant Frontend Code:
```
const Lobby = (props) => {
const socket = props.socket;
const player = {
room: props.room,
name: props.name,
};
const [playerList, setPlayerList] = useState([]);
socket.emit("joined_lobby", player);
console.log(`${playerList}`);
useEffect(() => {
socket.on("add_user", (data) => {
setPlayerList([...playerList, data.name]);
});
}, []);
```
Relevant Server Code:
```
io.on("connection", (socket) => { console.log(`Player with ID:\[${socket.id}\] Connected`);
socket.on("join_room", (data) => {
socket.join(data);
console.log(`Player with ID:\[${socket.id}\] Joined the room ${data}`); });
socket.on("joined_lobby", (data) => {
socket.to(data.room).emit("add_user", data); });
socket.on("disconnect", () => {
console.log(`Player with ID:\[${socket.id}\] Disonnected`); }); });
```
|
2022/05/17
|
[
"https://Stackoverflow.com/questions/72269969",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15966001/"
] |
This is set by the shortcut key. Open the **Default Keyboard Shortcuts** (**File** > **Preferences** > **Keyboard Shortcuts**) and search for "acceptSelectedSuggestion". You will see that there are only two settings by default, the `Tab` and `Enter` keys.
[](https://i.stack.imgur.com/AWts8.png)
If you want to add other buttons to trigger typing intellisense, right-click on one of the settings and select `Add Keybinding`,
[](https://i.stack.imgur.com/R1HaE.png)
then press the button you want to set, and press Enter to save.
|
Tab or enter is required to actually *make a selection*. Otherwise, you could have custom function `printStuff`, and typing `pr(` would not necessarily pick the right one.
From what I can tell, PyCharm works the exact same way, so unclear what "acts normal" means in this context.
|
2,437,316 |
I'm wondering if I should use OpenId for my website. My first exposure to OpenId was StackOverflow, and I found it confusing that they only had a login link, yet no register link. Now that I've learned about OpenId though I prefer it over the regular way of registration.
I have a feeling that only a small percentage of the internet users know how to login with a third party account provider, and most would prefer just to create an account. It makes sense for StackOverflow to use OpenId since the target audience is tech-savvy, however my website caters to the general public.
Does anyone have any statistics or first hand experience with using OpenId versus regular registration?
|
2010/03/13
|
[
"https://Stackoverflow.com/questions/2437316",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/243494/"
] |
I think these days a lot of sites have facebook login and a lot more people know how to use facebook than openid. If I were you I'd go with facebook. e.g. dailymile.com
|
You should have it only as option, not requirement. People just don't understand this concept and often don't trust it.
Many stackexchange.com clients (hosted stackoverflow) have learned this hard way. There have been so many complaints that stackexchange.com developers had to implement traditional username/password authentication as an addition to existing OpenID method.
|
2,437,316 |
I'm wondering if I should use OpenId for my website. My first exposure to OpenId was StackOverflow, and I found it confusing that they only had a login link, yet no register link. Now that I've learned about OpenId though I prefer it over the regular way of registration.
I have a feeling that only a small percentage of the internet users know how to login with a third party account provider, and most would prefer just to create an account. It makes sense for StackOverflow to use OpenId since the target audience is tech-savvy, however my website caters to the general public.
Does anyone have any statistics or first hand experience with using OpenId versus regular registration?
|
2010/03/13
|
[
"https://Stackoverflow.com/questions/2437316",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/243494/"
] |
You should have it only as option, not requirement. People just don't understand this concept and often don't trust it.
Many stackexchange.com clients (hosted stackoverflow) have learned this hard way. There have been so many complaints that stackexchange.com developers had to implement traditional username/password authentication as an addition to existing OpenID method.
|
Several members of the [OpenID Foundation](http://openid.net/foundation/sponsoring-members/) have done that sort of user experience testing. I don't know, however, which (if any) of them have published that research. It's certainly the sort of thing that the Foundation *should* make available, as they [make some claims](http://openid.net/add-openid/) and it'd be nice to see the numbers behind them. Ask 'em?
|
2,437,316 |
I'm wondering if I should use OpenId for my website. My first exposure to OpenId was StackOverflow, and I found it confusing that they only had a login link, yet no register link. Now that I've learned about OpenId though I prefer it over the regular way of registration.
I have a feeling that only a small percentage of the internet users know how to login with a third party account provider, and most would prefer just to create an account. It makes sense for StackOverflow to use OpenId since the target audience is tech-savvy, however my website caters to the general public.
Does anyone have any statistics or first hand experience with using OpenId versus regular registration?
|
2010/03/13
|
[
"https://Stackoverflow.com/questions/2437316",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/243494/"
] |
I think these days a lot of sites have facebook login and a lot more people know how to use facebook than openid. If I were you I'd go with facebook. e.g. dailymile.com
|
Several members of the [OpenID Foundation](http://openid.net/foundation/sponsoring-members/) have done that sort of user experience testing. I don't know, however, which (if any) of them have published that research. It's certainly the sort of thing that the Foundation *should* make available, as they [make some claims](http://openid.net/add-openid/) and it'd be nice to see the numbers behind them. Ask 'em?
|
2,166,581 |
I'm creating a console application in which I'd like to record key presses (like the UP ARROW). I've created a Low Level Keyboard Hook that is supposed to capture all Key Presses in any thread and invoke my callback function, but it isn't working. The program stalls for a bit when I hit a key, but never invokes the callback. I've checked the documentation but haven't found anything. I don't know whether I'm using SetWindowsHookEx() incorrectly (to my knowledge it successfully creates the hook) or my callback function is incorrect! I'm not sure whats wrong! Thanks in advance for the help.
```
#include "Windows.h"
#include <iostream>
using namespace std;
HHOOK hookHandle;
LRESULT CALLBACK keyHandler(int nCode, WPARAM wParam, LPARAM lParam);
int _tmain(int argc, _TCHAR* argv[]) {
hookHandle = SetWindowsHookEx(WH_KEYBOARD_LL, keyHandler, NULL, 0);
if(hookHandle == NULL) {
cout << "ERROR CREATING HOOK: ";
cout << GetLastError() << endl;
getchar();
return 0;
}
MSG message;
while(GetMessage(&message, NULL, 0, 0) != 0) {
TranslateMessage( &message );
DispatchMessage( &message );
}
cout << "Press any key to quit...";
getchar();
UnhookWindowsHookEx(hookHandle);
return 0;
}
LRESULT CALLBACK keyHandler(int nCode, WPARAM wParam, LPARAM lParam) {
cout << "Hello!" << endl;
// Checks whether params contain action about keystroke
if(nCode == HC_ACTION) {
cout << ((KBDLLHOOKSTRUCT *) lParam)->vkCode << endl;
}
return CallNextHookEx(hookHandle, nCode,
wParam, lParam);
}
```
|
2010/01/30
|
[
"https://Stackoverflow.com/questions/2166581",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/262293/"
] |
You can't block on a syscall (the getchar), you have to be running a window loop and processing messages before your hook gets called.
|
On Windows XP, you need, you need to pass `hInstance` (from `WinMain`) as the third argument to `SetWindowsHookEx`. For example:
```
int WINAPI WinMain
( HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPTSTR lpCmdLine, int nCmdShow ) {
hookHandle = SetWindowsHookEx ( WH_KEYBOARD_LL, keyHandler, hInstance, 0 );
// ...
```
|
2,166,581 |
I'm creating a console application in which I'd like to record key presses (like the UP ARROW). I've created a Low Level Keyboard Hook that is supposed to capture all Key Presses in any thread and invoke my callback function, but it isn't working. The program stalls for a bit when I hit a key, but never invokes the callback. I've checked the documentation but haven't found anything. I don't know whether I'm using SetWindowsHookEx() incorrectly (to my knowledge it successfully creates the hook) or my callback function is incorrect! I'm not sure whats wrong! Thanks in advance for the help.
```
#include "Windows.h"
#include <iostream>
using namespace std;
HHOOK hookHandle;
LRESULT CALLBACK keyHandler(int nCode, WPARAM wParam, LPARAM lParam);
int _tmain(int argc, _TCHAR* argv[]) {
hookHandle = SetWindowsHookEx(WH_KEYBOARD_LL, keyHandler, NULL, 0);
if(hookHandle == NULL) {
cout << "ERROR CREATING HOOK: ";
cout << GetLastError() << endl;
getchar();
return 0;
}
MSG message;
while(GetMessage(&message, NULL, 0, 0) != 0) {
TranslateMessage( &message );
DispatchMessage( &message );
}
cout << "Press any key to quit...";
getchar();
UnhookWindowsHookEx(hookHandle);
return 0;
}
LRESULT CALLBACK keyHandler(int nCode, WPARAM wParam, LPARAM lParam) {
cout << "Hello!" << endl;
// Checks whether params contain action about keystroke
if(nCode == HC_ACTION) {
cout << ((KBDLLHOOKSTRUCT *) lParam)->vkCode << endl;
}
return CallNextHookEx(hookHandle, nCode,
wParam, lParam);
}
```
|
2010/01/30
|
[
"https://Stackoverflow.com/questions/2166581",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/262293/"
] |
You can't block on a syscall (the getchar), you have to be running a window loop and processing messages before your hook gets called.
|
I suggest simle first;
// VB: Retrieve the applications instance
HINSTANCE appInstance = GetModuleHandle(NULL);
and then:
hookHandle = SetWindowsHookEx(WH\_KEYBOARD\_LL, keyHandler, appInstance, 0);
// ..., but there are another errors later, too
|
58,859 |
Pat Cloud's "Key to Five-String Banjo" is a book of scale exercises. Before the first exercise, Mr. Cloud writes (emphasis mine):
>
> Always start slowly and increase speed on each exercise only when you are absolutely sure you are using the correct fingers. **There should be "daylight" between each note.**
>
>
>
What does it mean for there to be "daylight between each note?" Does it just mean that I should avoid playing legato, or should I be playing staccato?
|
2017/07/02
|
[
"https://music.stackexchange.com/questions/58859",
"https://music.stackexchange.com",
"https://music.stackexchange.com/users/20675/"
] |
Daylight should be between the notes like gaps in blinds: a bright streak of silence separating each note rather than an uninterrupted wall of notes.
Staccato make the notes stand out as brief interruptions of the silence. What you want is a fine leggiero making the separations stand out as brief interruptions of the sound.
|
Probably a mixture of both. Separated, as in not bleeding into each other, but not short either, as in proper staccato. The gap should be not long enough to sound like you're searching for the next note, but just short enough that it separates the last from the next. Something like when you explain in an exasperated manner to a wayward kid - "I've - told - you - enough - times - now - get - in - side!" You must understand that from one end or the other...
|
8,801,213 |
What is the best and most effective way to extract a string from a string? I will need this operation to be preforms thousands of times.
I have this string and I'd like to extract the URL. The URL is always after the "url=" substring until the end of the string. For example:
```
http://foo.com/fooimage.php?d=AQA4GxxxpcDPnw&w=130&h=130&url=http00253A00252F00252Fi1.img.com00252Fvi00252FpV4Taseyww00252Fhslt.jpg
```
and I need to extract the
```
http00253A00252F00252Fi1.img.com00252Fvi00252FpV4Taseyww00252Fhslt.jpg
```
I want to avoid using split and such.
|
2012/01/10
|
[
"https://Stackoverflow.com/questions/8801213",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/63898/"
] |
If you absolutely need the results as a string, you'll have to measure,
but I doubt that anything will be significantly faster than the most
intuitive:
```
std::string
getTrailer( std::string const& original, std::string const& key )
{
std::string::const_iterator pivot
= std::search( original.begin(), original.end(), key.begin(), key.end() );
return pivot == original.end()
? std::string() // or some error condition...
: std::string( pivot + key.size(), original.end() );
}
```
However, the fastest way is probably not to extract the string at all,
but to simply keep it as a pair of iterators. If you need this a lot,
it might be worth defining a `Substring` class which encapsulates this.
(I've found a mutable variant of this to be very effective when
parsing.) If you go this way, don't forget that the iterators will
become invalid if the original string disappears; be sure to convert
anything you want to keep into a string before this occurs.
|
you can use `std::string::find()` :
if its a char\* than just move the pointer to the position right after "url="
```
yourstring = (yourstring + yourstring.find("url=")+4 );
```
I cant think of anything faster..
|
8,801,213 |
What is the best and most effective way to extract a string from a string? I will need this operation to be preforms thousands of times.
I have this string and I'd like to extract the URL. The URL is always after the "url=" substring until the end of the string. For example:
```
http://foo.com/fooimage.php?d=AQA4GxxxpcDPnw&w=130&h=130&url=http00253A00252F00252Fi1.img.com00252Fvi00252FpV4Taseyww00252Fhslt.jpg
```
and I need to extract the
```
http00253A00252F00252Fi1.img.com00252Fvi00252FpV4Taseyww00252Fhslt.jpg
```
I want to avoid using split and such.
|
2012/01/10
|
[
"https://Stackoverflow.com/questions/8801213",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/63898/"
] |
If you absolutely need the results as a string, you'll have to measure,
but I doubt that anything will be significantly faster than the most
intuitive:
```
std::string
getTrailer( std::string const& original, std::string const& key )
{
std::string::const_iterator pivot
= std::search( original.begin(), original.end(), key.begin(), key.end() );
return pivot == original.end()
? std::string() // or some error condition...
: std::string( pivot + key.size(), original.end() );
}
```
However, the fastest way is probably not to extract the string at all,
but to simply keep it as a pair of iterators. If you need this a lot,
it might be worth defining a `Substring` class which encapsulates this.
(I've found a mutable variant of this to be very effective when
parsing.) If you go this way, don't forget that the iterators will
become invalid if the original string disappears; be sure to convert
anything you want to keep into a string before this occurs.
|
You could also look into the boost libraries.
For example [boost::split()](http://www.boost.org/doc/libs/1_41_0/doc/html/boost/algorithm/split_id1113872.html)
I don't know how they actually perform in terms of speed, but it's definitely worth a try.
|
8,801,213 |
What is the best and most effective way to extract a string from a string? I will need this operation to be preforms thousands of times.
I have this string and I'd like to extract the URL. The URL is always after the "url=" substring until the end of the string. For example:
```
http://foo.com/fooimage.php?d=AQA4GxxxpcDPnw&w=130&h=130&url=http00253A00252F00252Fi1.img.com00252Fvi00252FpV4Taseyww00252Fhslt.jpg
```
and I need to extract the
```
http00253A00252F00252Fi1.img.com00252Fvi00252FpV4Taseyww00252Fhslt.jpg
```
I want to avoid using split and such.
|
2012/01/10
|
[
"https://Stackoverflow.com/questions/8801213",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/63898/"
] |
```
std::string inStr;
//this step is necessary
size_t pos = inStr.find("url=");
if(pos != std::string::npos){
char const * url = &inStr[pos + 4];
// it is fine to do any read only operations with url
// if you would apply some modifications to url, please make a copy string
}
```
|
you can use `std::string::find()` :
if its a char\* than just move the pointer to the position right after "url="
```
yourstring = (yourstring + yourstring.find("url=")+4 );
```
I cant think of anything faster..
|
8,801,213 |
What is the best and most effective way to extract a string from a string? I will need this operation to be preforms thousands of times.
I have this string and I'd like to extract the URL. The URL is always after the "url=" substring until the end of the string. For example:
```
http://foo.com/fooimage.php?d=AQA4GxxxpcDPnw&w=130&h=130&url=http00253A00252F00252Fi1.img.com00252Fvi00252FpV4Taseyww00252Fhslt.jpg
```
and I need to extract the
```
http00253A00252F00252Fi1.img.com00252Fvi00252FpV4Taseyww00252Fhslt.jpg
```
I want to avoid using split and such.
|
2012/01/10
|
[
"https://Stackoverflow.com/questions/8801213",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/63898/"
] |
```
std::string inStr;
//this step is necessary
size_t pos = inStr.find("url=");
if(pos != std::string::npos){
char const * url = &inStr[pos + 4];
// it is fine to do any read only operations with url
// if you would apply some modifications to url, please make a copy string
}
```
|
You could also look into the boost libraries.
For example [boost::split()](http://www.boost.org/doc/libs/1_41_0/doc/html/boost/algorithm/split_id1113872.html)
I don't know how they actually perform in terms of speed, but it's definitely worth a try.
|
28,523 |
For instance for mechanical engineering; from what I've seen, Blender is quite flexible and powerful so maybe it serves well for this also?
|
2011/03/01
|
[
"https://askubuntu.com/questions/28523",
"https://askubuntu.com",
"https://askubuntu.com/users/8673/"
] |
It really depends what you are doing exactly.
In general, I would say it's not good as a CAD tool for mechanical engineering.
It's good for modeling good looking things (teaspot, tree, people etc.), but if you want to for example handle strength calculations, you are basically out of luck (unless you do everything manually).
Of course, if you have to sell something, and you need good-looking renderings, then Blender might be good tool, but that's different from designing machines or buildings from engineering point of view.
|
A project has been started to achieve blender be a useful as CAD tool, without losing it's current capabilities.
<http://www.mechanicalblender.org>
<https://blenderartists.org/forum/showthread.php?395814-Mechanical-Blender>
|
28,523 |
For instance for mechanical engineering; from what I've seen, Blender is quite flexible and powerful so maybe it serves well for this also?
|
2011/03/01
|
[
"https://askubuntu.com/questions/28523",
"https://askubuntu.com",
"https://askubuntu.com/users/8673/"
] |
Blender is an artistic tool (read "not intended for precision").
|
Tools like Blender work differently than most engineering CAD software. Blender-like apps are focused on manipulating the textures, colors, and other attributes of surfaces. However, those apps lack the ability to easily specify specific dimensions that you need to manufacture a part, as well as the ability to generate engineering drawings a machinist needs.
|
28,523 |
For instance for mechanical engineering; from what I've seen, Blender is quite flexible and powerful so maybe it serves well for this also?
|
2011/03/01
|
[
"https://askubuntu.com/questions/28523",
"https://askubuntu.com",
"https://askubuntu.com/users/8673/"
] |
It really depends what you are doing exactly.
In general, I would say it's not good as a CAD tool for mechanical engineering.
It's good for modeling good looking things (teaspot, tree, people etc.), but if you want to for example handle strength calculations, you are basically out of luck (unless you do everything manually).
Of course, if you have to sell something, and you need good-looking renderings, then Blender might be good tool, but that's different from designing machines or buildings from engineering point of view.
|
There exists project BlenderCAD, but I didn't tried it yet.
<http://sourceforge.net/projects/blendercad/>
|
28,523 |
For instance for mechanical engineering; from what I've seen, Blender is quite flexible and powerful so maybe it serves well for this also?
|
2011/03/01
|
[
"https://askubuntu.com/questions/28523",
"https://askubuntu.com",
"https://askubuntu.com/users/8673/"
] |
There exists project BlenderCAD, but I didn't tried it yet.
<http://sourceforge.net/projects/blendercad/>
|
A project has been started to achieve blender be a useful as CAD tool, without losing it's current capabilities.
<http://www.mechanicalblender.org>
<https://blenderartists.org/forum/showthread.php?395814-Mechanical-Blender>
|
28,523 |
For instance for mechanical engineering; from what I've seen, Blender is quite flexible and powerful so maybe it serves well for this also?
|
2011/03/01
|
[
"https://askubuntu.com/questions/28523",
"https://askubuntu.com",
"https://askubuntu.com/users/8673/"
] |
Blender is an artistic tool (read "not intended for precision").
|
A project has been started to achieve blender be a useful as CAD tool, without losing it's current capabilities.
<http://www.mechanicalblender.org>
<https://blenderartists.org/forum/showthread.php?395814-Mechanical-Blender>
|
28,523 |
For instance for mechanical engineering; from what I've seen, Blender is quite flexible and powerful so maybe it serves well for this also?
|
2011/03/01
|
[
"https://askubuntu.com/questions/28523",
"https://askubuntu.com",
"https://askubuntu.com/users/8673/"
] |
It really depends what you are doing exactly.
In general, I would say it's not good as a CAD tool for mechanical engineering.
It's good for modeling good looking things (teaspot, tree, people etc.), but if you want to for example handle strength calculations, you are basically out of luck (unless you do everything manually).
Of course, if you have to sell something, and you need good-looking renderings, then Blender might be good tool, but that's different from designing machines or buildings from engineering point of view.
|
Blender is an artistic tool (read "not intended for precision").
|
28,523 |
For instance for mechanical engineering; from what I've seen, Blender is quite flexible and powerful so maybe it serves well for this also?
|
2011/03/01
|
[
"https://askubuntu.com/questions/28523",
"https://askubuntu.com",
"https://askubuntu.com/users/8673/"
] |
It really depends what you are doing exactly.
In general, I would say it's not good as a CAD tool for mechanical engineering.
It's good for modeling good looking things (teaspot, tree, people etc.), but if you want to for example handle strength calculations, you are basically out of luck (unless you do everything manually).
Of course, if you have to sell something, and you need good-looking renderings, then Blender might be good tool, but that's different from designing machines or buildings from engineering point of view.
|
Tools like Blender work differently than most engineering CAD software. Blender-like apps are focused on manipulating the textures, colors, and other attributes of surfaces. However, those apps lack the ability to easily specify specific dimensions that you need to manufacture a part, as well as the ability to generate engineering drawings a machinist needs.
|
28,523 |
For instance for mechanical engineering; from what I've seen, Blender is quite flexible and powerful so maybe it serves well for this also?
|
2011/03/01
|
[
"https://askubuntu.com/questions/28523",
"https://askubuntu.com",
"https://askubuntu.com/users/8673/"
] |
A project has been started to achieve blender be a useful as CAD tool, without losing it's current capabilities.
<http://www.mechanicalblender.org>
<https://blenderartists.org/forum/showthread.php?395814-Mechanical-Blender>
|
Honest answer: NO, not at all. Blender is NOT CAD, it's an artistic tool, it blends artistic ideas and visions. CAD is quite the opposite, it kills artistic ideas, it's about maths, physics and precision.
There are many questions and solutions about CAD on this forum, but it's up to you to establish your specific requirements and what CAD suites best for you. Bit of advice: don't ask just for CAD\_period! Ask for specific equivalent (explicite names and brands) from Windows. It's more easier to find what you want that way.
Closest service to CAD for Blender could be architectural works renderings. Because Blender is good at render scenes.
|
28,523 |
For instance for mechanical engineering; from what I've seen, Blender is quite flexible and powerful so maybe it serves well for this also?
|
2011/03/01
|
[
"https://askubuntu.com/questions/28523",
"https://askubuntu.com",
"https://askubuntu.com/users/8673/"
] |
There exists project BlenderCAD, but I didn't tried it yet.
<http://sourceforge.net/projects/blendercad/>
|
Honest answer: NO, not at all. Blender is NOT CAD, it's an artistic tool, it blends artistic ideas and visions. CAD is quite the opposite, it kills artistic ideas, it's about maths, physics and precision.
There are many questions and solutions about CAD on this forum, but it's up to you to establish your specific requirements and what CAD suites best for you. Bit of advice: don't ask just for CAD\_period! Ask for specific equivalent (explicite names and brands) from Windows. It's more easier to find what you want that way.
Closest service to CAD for Blender could be architectural works renderings. Because Blender is good at render scenes.
|
28,523 |
For instance for mechanical engineering; from what I've seen, Blender is quite flexible and powerful so maybe it serves well for this also?
|
2011/03/01
|
[
"https://askubuntu.com/questions/28523",
"https://askubuntu.com",
"https://askubuntu.com/users/8673/"
] |
Blender is an artistic tool (read "not intended for precision").
|
There exists project BlenderCAD, but I didn't tried it yet.
<http://sourceforge.net/projects/blendercad/>
|
100,428 |
I'm managing a Google Suite environment, for example, for company example.com. At the moment I'm managing it via the [email protected] email address. But what I want, if possible, is to manage it via my own Google account, for example [email protected].
When I try to add my own email address as administrator I receive the following warning message:
>
> User does not exists.
>
>
>
Is this possible?
|
2016/11/16
|
[
"https://webapps.stackexchange.com/questions/100428",
"https://webapps.stackexchange.com",
"https://webapps.stackexchange.com/users/139968/"
] |
Unfortunately it is not possible. You must create a new email address within the same domain as administration account.
|
In the simple way you describe, it is not possible; i.e., one may not add `[email protected]` to `domain.com` as an administrator.
If you only want an unpaid (no email, storage, etc.) account with `superadmin` privileges to manage the domain, you can use the "Cloud Identity" service. You could also use a sub-domain, but that comes with many caveats. I've both explained below.
#### 1. Using a free (unpaid) Cloud Identity account
Using the free-tier of the Google [Cloud Identity](https://support.google.com/cloudidentity/answer/7319251) service, it *is* possible to have a free administrator account within `domain.com`. This account will not be licensed for any paid Google services, but may still be used to log in to the Google Admin Console, etc.
1. Log in to the Google Admin console with a user which has sufficient permissions to create and assign whatever admin role you require for the new user.
2. Add the free-tier of the "Cloud Identity" service using `[fly-out side menu] > Billing > Get more services`, choose `Cloud Identity` in the left column, then `Cloud Identity Free`. The free "Cloud Identity" service will be added to every user. Depending on the license assignment configuration for `domain.com`, the Admin console may offer help to disable automatic-licenses (which will matter for the new user you are about to create, as you do not want it to receive any licenses for paid services). There is information about automatic licensing [here](https://support.google.com/a/answer/6342682).
3. Create a new account. Ensure it has no Google licenses assigned. In the `Admin roles and privileges` section of the user configuration, assign whatever roles and privileges are necessary; in this case, perhaps `superadmin`. There is documentation on this, "[Make a user an admin](https://support.google.com/a/answer/172176)".
4. **Optional** After ensuring the new account works, remove `superadmin` privileges from the other paid service accounts. Obviously, you can create as many free administrative accounts as you require.
I strongly recommend all the standard security practices for the administrator account, such as 2FA or security devices, etc.
The Google "[Super administrator account best practices](https://cloud.google.com/resource-manager/docs/super-admin-best-practices)" article is quite helpful, and discusses organization admins and roles, discouraging super admin usage, etc.
#### 2. Considering using a "secondary domain"
It may be possible if you add `other-domain.com` as a "secondary domain" of `domain.com`, but this comes with various implications and limitations. The documentation is plentiful, but not particularly clear with examples and I would worry about causing confusion for the users of each domain. I suspect the domains will not be as separate as might be prefered. The documentation on [Add multiple domains or domain aliases](https://support.google.com/a/answer/7502379), contains:
>
> If you own another domain, you can add it to your Google Workspace or
> Cloud Identity account. For example, you manage multiple businesses or
> brands, each with their own domain. Depending on your needs, you add a
> domain as a domain alias or a secondary domain.
>
>
>
And, in the section no "secondary domains" it also contains:
>
> Manage separate teams of users or businesses at different domains
>
>
> For example, you signed up for Google Workspace with your-company.com
> (your primary domain). You manage a team that has their own domain,
> other-company.com. You add other-company.com as a secondary domain to
> your Google Workspace account.
>
>
>
Which both sound helpful with respect to dealing with multiple domains.
However, further on, that documentation also mentions "Pay for each user account", which seems to imply `your-company.com` will be billed for the services used by `other-company.com`. This seems to confirm it:
>
> **Important:** Some information and features are linked only to your
> primary domain. For example, you can't set up a separate billing
> address or company logo for a secondary domain.
>
>
>
So, as someone simply managing a domain (as a consultant, contractor, IT support, etc.) for a business, I would stay away from secondary domains. (i.e., Do not add another company's domain as a secondary for the purpose of managing it.)
"Secondary domains" seem more about different names or brands or units for a single business.
|
36,801,850 |
I can't seem to get this form to work properly. My web scripting knowledge is pretty limited as I'm still a student. I searched and found this [Post Self Form Validation and Submission in PHP](https://stackoverflow.com/questions/23933991/post-self-form-validation-and-submission-in-php) which is the same assignment but this person had a different problem.
For some reason when I try to test out my page ***"> Name:*** shows up as my first line but the ***">*** is the closing for the html form opening tag.
I also have this a .html because I want to submit it as one document and not have the PHP code in a separate .php document.
edit: @ Quentin - This is not related to the duplicate article that this was marked as. I'm not running an Apache server. That person solved his problem by restarting the XAMPP service I'm Windows 10 and cannot possibly have that service running.
I want it to run off one document, thus why I was using PHP\_SELF. When I save the file as a .php it doesn't do anything but display the code.
I did inspect the code in Chrome, the only way I know how to debug it. And I couldn't find anything wrong with it.
```
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Assignment 6.2 PHP Validation</title>
</head>
<body>
<?php
// define variables and set to empty values
$nameErr = $addressErr = $phoneErr = $zipErr = "";
$name = $address = $phone = $zip = "";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (empty($_POST["name"])) {
$nameErr = "Name is required";
} else {
$name = test_input($_POST["name"]);
// check if name only contains letters and whitespace
if (!preg_match("/^[a-zA-Z ]*$/",$name)) {
$nameErr = "Only letters and white space allowed";
}
}
//check name field
if (empty($_POST["address"])) {
$emailErr = "Address is required";
}
// check phone number field
if (empty($_POST['phone'])) {
$phoneErr = "Phone number is required";
} else {
$phone = test_input($_POST['phone']);
if(!preg_match("/^[0-9]{3}-[0-9]{3}-[0-9]{4}$/", $phone)) {
$phoneErr = "must be in ddd-ddd-dddd format";
}
}
//check zip code field
if (empty($_POST['zip'])) {
$zipErr = "Zip code is required";
} else {
$zip = test_input($_POST['zip']);
if(!preg_match("/^[0-9]{5}-[0-9]{4}$/", $)) {
$zipErr = "Zip code must be in ddddd-dddd format";
}
}
?>
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
Name: <input type="text" name="name">
<span class="error">* <?php echo $nameErr;?></span>
<br><br>
Address:
<input type="text" name="address">
<span class="error">* <?php echo $addressErr;?></span>
<br><br>
Phone Number:
<input type="text" name="phone">
<span class="error"><?php echo $phoneErr;?></span>
<br><br>
Zip Code:
<input type="text" name="zip">
<span class="error"><?php echo $zipErr;?></span>
<br><br>
<input type="submit" name="submit" value="Submit">
</form>
</body>
</html>
```
|
2016/04/22
|
[
"https://Stackoverflow.com/questions/36801850",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6152284/"
] |
If you have php anywhere in the code, it can't be saved as an `.html` file. Save it as a `.php` file and then Apache will call the PHP interpreter.
|
since you're saving the page as an `.html` extension, it's very likely that your php is not being processed. Try saving the page as an `.php`
|
58,005,073 |
I am setting up profile section.
>
> I want to show empty fields to a new user.
>
>
>
First I tried this, but it didn't work because new user's profile table is empty.
```
<li>Name :<br>
<p>
{{ Auth::user()->profile->name }}
</p>
</li>
```
So next I tried this one.
```
<p>@if(!empty(Auth::user()->profile->name))
{{ Auth::user()->profile->name }}
@endif</p>
```
It worked, I could see an empty field with no error. But after I inserted a 'name' and redirect to index.blade.php page, 'name' didn't show up, still empty.
>
> I want to see a profile page filled with user profile information.
>
>
>
Then, lastly, I tried this.
```
@if($profile->count() > 0)
<ul class="information">
<li>Name :<br>
<p>
{{ Auth::user()->profile->name }}
</p>
</li><br>
@endif
```
but I got an error **Undefined variable: profile.**
**UserController.php**
```
public function store(Request $request) {
$this->validate($request,[
'name' => 'required'
]);
$profile = new Profile;
$profile->name = $request->input('name');
$profile->save();
return redirect()->route('profile.index');
}
```
**web.php**
```
Route::prefix('user')->group(function(){
Route::resource('profile', 'UserController');
});
```
also I want to show profile information to an edit page.
I am glad if someone helps me out.
|
2019/09/19
|
[
"https://Stackoverflow.com/questions/58005073",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11527337/"
] |
In UserController,
```
public function index()
{
$profiles=Profile::all()
return view('your_view_file_path', compact('profiles'));
}
```
In Blade
```
@foreach($profiles as $profile)
<li>Name :<br>
<p>
{{profile->name}}
</p>
</li><br>
@enforeach
```
|
Try to change :
```
return redirect()->route('profile.index');
```
To :
```
return redirect()->route('profile.index', [$profile]);
```
|
58,005,073 |
I am setting up profile section.
>
> I want to show empty fields to a new user.
>
>
>
First I tried this, but it didn't work because new user's profile table is empty.
```
<li>Name :<br>
<p>
{{ Auth::user()->profile->name }}
</p>
</li>
```
So next I tried this one.
```
<p>@if(!empty(Auth::user()->profile->name))
{{ Auth::user()->profile->name }}
@endif</p>
```
It worked, I could see an empty field with no error. But after I inserted a 'name' and redirect to index.blade.php page, 'name' didn't show up, still empty.
>
> I want to see a profile page filled with user profile information.
>
>
>
Then, lastly, I tried this.
```
@if($profile->count() > 0)
<ul class="information">
<li>Name :<br>
<p>
{{ Auth::user()->profile->name }}
</p>
</li><br>
@endif
```
but I got an error **Undefined variable: profile.**
**UserController.php**
```
public function store(Request $request) {
$this->validate($request,[
'name' => 'required'
]);
$profile = new Profile;
$profile->name = $request->input('name');
$profile->save();
return redirect()->route('profile.index');
}
```
**web.php**
```
Route::prefix('user')->group(function(){
Route::resource('profile', 'UserController');
});
```
also I want to show profile information to an edit page.
I am glad if someone helps me out.
|
2019/09/19
|
[
"https://Stackoverflow.com/questions/58005073",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11527337/"
] |
In UserController,
```
public function index()
{
$profiles=Profile::all()
return view('your_view_file_path', compact('profiles'));
}
```
In Blade
```
@foreach($profiles as $profile)
<li>Name :<br>
<p>
{{profile->name}}
</p>
</li><br>
@enforeach
```
|
How about simply keeping name values to input tag so you can pass all values. maybe that can be issue?
```
@if($profile->count() > 0)
<ul class="information">
<li>Name :<br>
<input type="text" name="name1" value="
{{ Auth::user()->profile->name }}" />
</li><br>
@endif
```
Inside your Controller:
```
public function store(Request $request) {
$this->validate($request,[
'name' => 'required'
]);
$profile = new Profile;
$profile->name = $request->input('name1');
$profile->save();
return redirect()->route('profile.index');
}
```
|
14,187 |
have a website (www.americanbankingnews.com) that gets 40,000-50,000 page views today. It's currently sitting on a dedicated quad-core Xeon server with 8GB of ram. The site is powered by WordPress and MySQL (sitting on the same server) and I'm currently using W3 Total Cache for page and MySQL query Caching.
Unfortunately, that doesn't seem to be enough. During peak traffic times, my servers are getting a few HTTP 500 errors and pages that aren't cached load slowly.
I'm currently not using Xcache or any other PHP cache/acceleration tools.
Are there additional steps that I should take to try to optimize MySQL and PHP performance? Or should I fork over for an additional server. Specifically, I'd be interested in additional suggestions to improve MySQL performance and whether or not tools like xcache might help in this situation
|
2011/04/07
|
[
"https://wordpress.stackexchange.com/questions/14187",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/4510/"
] |
Lots of similar questions and answers:
<https://wordpress.stackexchange.com/search?q=mysql+optimize>
It comes down to using tools - like mysqltuner - to investigate the bottlenecks, checking logs for errors and memory usage, php opcode-caching, clearing post/page revisons to get the DB down to size, etc.
|
You weren't kidding, just tried going to your site and got a 500 internal error. Perhaps you can lower the number of plugins you are using and make sure all images are optimized, etc. to make page sizes smaller so they consume less bandwidth to load hence less errors.
You may also want to look into [HIP HOP for PHP](https://github.com/facebook/hiphop-php/) . I never implemented it but it was released open source by the facbook people who after creating and using it saw their server load go down by about 30%. Basically it takes regular php files, converts them to C++ binaries and serves those out.
|
14,187 |
have a website (www.americanbankingnews.com) that gets 40,000-50,000 page views today. It's currently sitting on a dedicated quad-core Xeon server with 8GB of ram. The site is powered by WordPress and MySQL (sitting on the same server) and I'm currently using W3 Total Cache for page and MySQL query Caching.
Unfortunately, that doesn't seem to be enough. During peak traffic times, my servers are getting a few HTTP 500 errors and pages that aren't cached load slowly.
I'm currently not using Xcache or any other PHP cache/acceleration tools.
Are there additional steps that I should take to try to optimize MySQL and PHP performance? Or should I fork over for an additional server. Specifically, I'd be interested in additional suggestions to improve MySQL performance and whether or not tools like xcache might help in this situation
|
2011/04/07
|
[
"https://wordpress.stackexchange.com/questions/14187",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/4510/"
] |
### Hi Matthew Paulson,
I see your using W3 Total Cache but your database and object cache is set to disk. Caching objects and your database to disk can actually have a negative performance effect especially if your getting that much traffic.
You can read more about the effects on caching database and objects to disk in an article I wrote on how to **[set up W3 Total Cache](http://c3mdigital.com/2010/09/24/reduce-page-loading-time-w3-total-cache/)** The plugin author agreed with the instructions in my settings.
To really see the benefit of database and object caching you need to be using a PHP opcode cache like APC. You can follow the copy and paste instructions in the plugin FAQ to compile and set up APC. If your on Ubuntu or Debian you can simply run the command: apt-get apc-php5 to install.
Like others have also mentioned you will get a huge performance boost and enable your site to scale much larger by setting up a reverse proxy with Nginx.
I give detailed instructions on how to configure and set it up in my **[WordPress Performance Stack.](http://wp-performance.com/2010/10/nginx-reverse-proxy-cache-wordpress-apache/)** article.
You should also read some of the other questions and answers on here. A lot of good performance and scaling advice has been given.
Good luck on your quest. Managing your own server can be very stressful sometimes.
***Edit***
Just to show the performance you can gain by installing Nginx as a reverse proxy I'm posting an Apache Benchmark test I just ran on my server:
```
x-wing ~: ab -n 1000 -c 80 http://wp-performance.com/
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking wp-performance.com (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Completed 600 requests
Completed 700 requests
Completed 800 requests
Completed 900 requests
Completed 1000 requests
Finished 1000 requests
Server Software: nginx/0.8.54
Server Hostname: wp-performance.com
Server Port: 80
Document Path: /
Document Length: 3132 bytes
Concurrency Level: 80
Time taken for tests: 0.066 seconds
Complete requests: 1000
Failed requests: 0
Write errors: 0
Total transferred: 3605000 bytes
HTML transferred: 3132000 bytes
Requests per second: 15164.15 [#/sec] (mean)
Time per request: 5.276 [ms] (mean)
Time per request: 0.066 [ms] (mean, across all concurrent requests)
Transfer rate: 53385.52 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 2 0.6 1 3
Processing: 1 4 0.8 4 5
Waiting: 1 3 0.8 3 5
Total: 3 5 0.6 5 7
Percentage of the requests served within a certain time (ms)
50% 5
66% 5
75% 6
80% 6
90% 6
95% 6
98% 6
99% 6
100% 7 (longest request)
```
Theoretically it's able to handle over 15,000 requests per second. (Same Network)
|
Hi **@Matthew Paulson:**
You may be asking the wrong question.
With your traffic you *may* want to look at at front-end cache using [**nginx**](http://nginx.org/en/). Here are Q&As for nginx here on the site, lots of relevant articles in a Google search, and plugin that can interface WordPress to nginx at wordpress.org and lastly an article on installing and configuring:
* <https://wordpress.stackexchange.com/search?q=nginx>
* <http://www.google.com/search?q=nginx+wordpress>
* <http://wordpress.org/extend/plugins/search.php?q=nginx>
* <http://elasticdog.com/2008/02/howto-install-wordpress-on-nginx/>
If that doesn't help or if you don't want to do it for some other reason please let us know **what plugins you are using**. Most of the time with WordPress performance problems are not the obvious but instead they are result of some poorly written plugins.
|
14,187 |
have a website (www.americanbankingnews.com) that gets 40,000-50,000 page views today. It's currently sitting on a dedicated quad-core Xeon server with 8GB of ram. The site is powered by WordPress and MySQL (sitting on the same server) and I'm currently using W3 Total Cache for page and MySQL query Caching.
Unfortunately, that doesn't seem to be enough. During peak traffic times, my servers are getting a few HTTP 500 errors and pages that aren't cached load slowly.
I'm currently not using Xcache or any other PHP cache/acceleration tools.
Are there additional steps that I should take to try to optimize MySQL and PHP performance? Or should I fork over for an additional server. Specifically, I'd be interested in additional suggestions to improve MySQL performance and whether or not tools like xcache might help in this situation
|
2011/04/07
|
[
"https://wordpress.stackexchange.com/questions/14187",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/4510/"
] |
### Hi Matthew Paulson,
I see your using W3 Total Cache but your database and object cache is set to disk. Caching objects and your database to disk can actually have a negative performance effect especially if your getting that much traffic.
You can read more about the effects on caching database and objects to disk in an article I wrote on how to **[set up W3 Total Cache](http://c3mdigital.com/2010/09/24/reduce-page-loading-time-w3-total-cache/)** The plugin author agreed with the instructions in my settings.
To really see the benefit of database and object caching you need to be using a PHP opcode cache like APC. You can follow the copy and paste instructions in the plugin FAQ to compile and set up APC. If your on Ubuntu or Debian you can simply run the command: apt-get apc-php5 to install.
Like others have also mentioned you will get a huge performance boost and enable your site to scale much larger by setting up a reverse proxy with Nginx.
I give detailed instructions on how to configure and set it up in my **[WordPress Performance Stack.](http://wp-performance.com/2010/10/nginx-reverse-proxy-cache-wordpress-apache/)** article.
You should also read some of the other questions and answers on here. A lot of good performance and scaling advice has been given.
Good luck on your quest. Managing your own server can be very stressful sometimes.
***Edit***
Just to show the performance you can gain by installing Nginx as a reverse proxy I'm posting an Apache Benchmark test I just ran on my server:
```
x-wing ~: ab -n 1000 -c 80 http://wp-performance.com/
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking wp-performance.com (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Completed 600 requests
Completed 700 requests
Completed 800 requests
Completed 900 requests
Completed 1000 requests
Finished 1000 requests
Server Software: nginx/0.8.54
Server Hostname: wp-performance.com
Server Port: 80
Document Path: /
Document Length: 3132 bytes
Concurrency Level: 80
Time taken for tests: 0.066 seconds
Complete requests: 1000
Failed requests: 0
Write errors: 0
Total transferred: 3605000 bytes
HTML transferred: 3132000 bytes
Requests per second: 15164.15 [#/sec] (mean)
Time per request: 5.276 [ms] (mean)
Time per request: 0.066 [ms] (mean, across all concurrent requests)
Transfer rate: 53385.52 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 2 0.6 1 3
Processing: 1 4 0.8 4 5
Waiting: 1 3 0.8 3 5
Total: 3 5 0.6 5 7
Percentage of the requests served within a certain time (ms)
50% 5
66% 5
75% 6
80% 6
90% 6
95% 6
98% 6
99% 6
100% 7 (longest request)
```
Theoretically it's able to handle over 15,000 requests per second. (Same Network)
|
i dont know what programs you installed but maybe its APC - Zend problem:
<http://www.ivankristianto.com/web-development/server/alternative-php-cache-apc-not-compatible-with-zend-optimizer/1726/>
>
> This problem happen in my VPS after i
> install Alternative PHP cache (APC).
> And also i already have Zend optimizer
> installed on the same VPS. After i
> installed APC, my WordPress blog show
> strange behavior. Sometimes i got
> Error 500 Internal Server Error, and
> sometimes i got PHP fatal error.
>
>
>
|
14,187 |
have a website (www.americanbankingnews.com) that gets 40,000-50,000 page views today. It's currently sitting on a dedicated quad-core Xeon server with 8GB of ram. The site is powered by WordPress and MySQL (sitting on the same server) and I'm currently using W3 Total Cache for page and MySQL query Caching.
Unfortunately, that doesn't seem to be enough. During peak traffic times, my servers are getting a few HTTP 500 errors and pages that aren't cached load slowly.
I'm currently not using Xcache or any other PHP cache/acceleration tools.
Are there additional steps that I should take to try to optimize MySQL and PHP performance? Or should I fork over for an additional server. Specifically, I'd be interested in additional suggestions to improve MySQL performance and whether or not tools like xcache might help in this situation
|
2011/04/07
|
[
"https://wordpress.stackexchange.com/questions/14187",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/4510/"
] |
Lots of similar questions and answers:
<https://wordpress.stackexchange.com/search?q=mysql+optimize>
It comes down to using tools - like mysqltuner - to investigate the bottlenecks, checking logs for errors and memory usage, php opcode-caching, clearing post/page revisons to get the DB down to size, etc.
|
Hi **@Matthew Paulson:**
You may be asking the wrong question.
With your traffic you *may* want to look at at front-end cache using [**nginx**](http://nginx.org/en/). Here are Q&As for nginx here on the site, lots of relevant articles in a Google search, and plugin that can interface WordPress to nginx at wordpress.org and lastly an article on installing and configuring:
* <https://wordpress.stackexchange.com/search?q=nginx>
* <http://www.google.com/search?q=nginx+wordpress>
* <http://wordpress.org/extend/plugins/search.php?q=nginx>
* <http://elasticdog.com/2008/02/howto-install-wordpress-on-nginx/>
If that doesn't help or if you don't want to do it for some other reason please let us know **what plugins you are using**. Most of the time with WordPress performance problems are not the obvious but instead they are result of some poorly written plugins.
|
14,187 |
have a website (www.americanbankingnews.com) that gets 40,000-50,000 page views today. It's currently sitting on a dedicated quad-core Xeon server with 8GB of ram. The site is powered by WordPress and MySQL (sitting on the same server) and I'm currently using W3 Total Cache for page and MySQL query Caching.
Unfortunately, that doesn't seem to be enough. During peak traffic times, my servers are getting a few HTTP 500 errors and pages that aren't cached load slowly.
I'm currently not using Xcache or any other PHP cache/acceleration tools.
Are there additional steps that I should take to try to optimize MySQL and PHP performance? Or should I fork over for an additional server. Specifically, I'd be interested in additional suggestions to improve MySQL performance and whether or not tools like xcache might help in this situation
|
2011/04/07
|
[
"https://wordpress.stackexchange.com/questions/14187",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/4510/"
] |
Hi **@Matthew Paulson:**
You may be asking the wrong question.
With your traffic you *may* want to look at at front-end cache using [**nginx**](http://nginx.org/en/). Here are Q&As for nginx here on the site, lots of relevant articles in a Google search, and plugin that can interface WordPress to nginx at wordpress.org and lastly an article on installing and configuring:
* <https://wordpress.stackexchange.com/search?q=nginx>
* <http://www.google.com/search?q=nginx+wordpress>
* <http://wordpress.org/extend/plugins/search.php?q=nginx>
* <http://elasticdog.com/2008/02/howto-install-wordpress-on-nginx/>
If that doesn't help or if you don't want to do it for some other reason please let us know **what plugins you are using**. Most of the time with WordPress performance problems are not the obvious but instead they are result of some poorly written plugins.
|
The hardware you have should easily cope with the stated traffic (as a benchmark, a site I run peaks at ~40k daily page views on a 2GB Slicehost VPS) - so that suggests something grossly wrong.
So, as other people have said, the first thing you need to do is understand where the problem(s) is/are.
1. What information does top give you when you're under load? Are you using swap memory, is your load spiking, when you sort by memory and cpu% what are the top processes?
2. Can you install something like [munin](http://www.munin.com) to give you an insight into your server?
3. Assuming you're running Apache, how is it configured - the important things to know are:
* Timeout
* KeepAlive
* MaxKeepAliveRequests
* KeepAliveTimeout
* (assuming you're running Apache in prefork mode) - all the config lines in the prefork section of your apache conf file.
4. Running this command - `ps -ylC httpd --sort:rss` will give you a indication of how much memory Apache processes are using.
5. Install [mtop](http://mtop.sourceforge.net/) and [mysqltuner](https://github.com/rackerhacker/MySQLTuner-perl) - from what I remember both are available via apt-get. You should also [turn on MySQL slow logging](http://www.petefreitag.com/item/233.cfm) - you normally just need to uncomment a line in your my.cnf file.
* mtop gives you a real time view of what SQL queries are running (slowly). mysqltuner will give you some sense of what changes you need to make to your MySQL configuration
6. As suggested by others, what happens if you turn off plugins during a busy period? Does the site speed up? What plugins do you have installed?
7. Do you have any idea of how much traffic you're getting during your busy periods - eg 4000 page views in 10 minutes.
Armed with information from these sources, you'll have a much better idea of what's going wrong.
|
14,187 |
have a website (www.americanbankingnews.com) that gets 40,000-50,000 page views today. It's currently sitting on a dedicated quad-core Xeon server with 8GB of ram. The site is powered by WordPress and MySQL (sitting on the same server) and I'm currently using W3 Total Cache for page and MySQL query Caching.
Unfortunately, that doesn't seem to be enough. During peak traffic times, my servers are getting a few HTTP 500 errors and pages that aren't cached load slowly.
I'm currently not using Xcache or any other PHP cache/acceleration tools.
Are there additional steps that I should take to try to optimize MySQL and PHP performance? Or should I fork over for an additional server. Specifically, I'd be interested in additional suggestions to improve MySQL performance and whether or not tools like xcache might help in this situation
|
2011/04/07
|
[
"https://wordpress.stackexchange.com/questions/14187",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/4510/"
] |
### Hi Matthew Paulson,
I see your using W3 Total Cache but your database and object cache is set to disk. Caching objects and your database to disk can actually have a negative performance effect especially if your getting that much traffic.
You can read more about the effects on caching database and objects to disk in an article I wrote on how to **[set up W3 Total Cache](http://c3mdigital.com/2010/09/24/reduce-page-loading-time-w3-total-cache/)** The plugin author agreed with the instructions in my settings.
To really see the benefit of database and object caching you need to be using a PHP opcode cache like APC. You can follow the copy and paste instructions in the plugin FAQ to compile and set up APC. If your on Ubuntu or Debian you can simply run the command: apt-get apc-php5 to install.
Like others have also mentioned you will get a huge performance boost and enable your site to scale much larger by setting up a reverse proxy with Nginx.
I give detailed instructions on how to configure and set it up in my **[WordPress Performance Stack.](http://wp-performance.com/2010/10/nginx-reverse-proxy-cache-wordpress-apache/)** article.
You should also read some of the other questions and answers on here. A lot of good performance and scaling advice has been given.
Good luck on your quest. Managing your own server can be very stressful sometimes.
***Edit***
Just to show the performance you can gain by installing Nginx as a reverse proxy I'm posting an Apache Benchmark test I just ran on my server:
```
x-wing ~: ab -n 1000 -c 80 http://wp-performance.com/
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking wp-performance.com (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Completed 600 requests
Completed 700 requests
Completed 800 requests
Completed 900 requests
Completed 1000 requests
Finished 1000 requests
Server Software: nginx/0.8.54
Server Hostname: wp-performance.com
Server Port: 80
Document Path: /
Document Length: 3132 bytes
Concurrency Level: 80
Time taken for tests: 0.066 seconds
Complete requests: 1000
Failed requests: 0
Write errors: 0
Total transferred: 3605000 bytes
HTML transferred: 3132000 bytes
Requests per second: 15164.15 [#/sec] (mean)
Time per request: 5.276 [ms] (mean)
Time per request: 0.066 [ms] (mean, across all concurrent requests)
Transfer rate: 53385.52 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 2 0.6 1 3
Processing: 1 4 0.8 4 5
Waiting: 1 3 0.8 3 5
Total: 3 5 0.6 5 7
Percentage of the requests served within a certain time (ms)
50% 5
66% 5
75% 6
80% 6
90% 6
95% 6
98% 6
99% 6
100% 7 (longest request)
```
Theoretically it's able to handle over 15,000 requests per second. (Same Network)
|
Lots of similar questions and answers:
<https://wordpress.stackexchange.com/search?q=mysql+optimize>
It comes down to using tools - like mysqltuner - to investigate the bottlenecks, checking logs for errors and memory usage, php opcode-caching, clearing post/page revisons to get the DB down to size, etc.
|
14,187 |
have a website (www.americanbankingnews.com) that gets 40,000-50,000 page views today. It's currently sitting on a dedicated quad-core Xeon server with 8GB of ram. The site is powered by WordPress and MySQL (sitting on the same server) and I'm currently using W3 Total Cache for page and MySQL query Caching.
Unfortunately, that doesn't seem to be enough. During peak traffic times, my servers are getting a few HTTP 500 errors and pages that aren't cached load slowly.
I'm currently not using Xcache or any other PHP cache/acceleration tools.
Are there additional steps that I should take to try to optimize MySQL and PHP performance? Or should I fork over for an additional server. Specifically, I'd be interested in additional suggestions to improve MySQL performance and whether or not tools like xcache might help in this situation
|
2011/04/07
|
[
"https://wordpress.stackexchange.com/questions/14187",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/4510/"
] |
Hi **@Matthew Paulson:**
You may be asking the wrong question.
With your traffic you *may* want to look at at front-end cache using [**nginx**](http://nginx.org/en/). Here are Q&As for nginx here on the site, lots of relevant articles in a Google search, and plugin that can interface WordPress to nginx at wordpress.org and lastly an article on installing and configuring:
* <https://wordpress.stackexchange.com/search?q=nginx>
* <http://www.google.com/search?q=nginx+wordpress>
* <http://wordpress.org/extend/plugins/search.php?q=nginx>
* <http://elasticdog.com/2008/02/howto-install-wordpress-on-nginx/>
If that doesn't help or if you don't want to do it for some other reason please let us know **what plugins you are using**. Most of the time with WordPress performance problems are not the obvious but instead they are result of some poorly written plugins.
|
You weren't kidding, just tried going to your site and got a 500 internal error. Perhaps you can lower the number of plugins you are using and make sure all images are optimized, etc. to make page sizes smaller so they consume less bandwidth to load hence less errors.
You may also want to look into [HIP HOP for PHP](https://github.com/facebook/hiphop-php/) . I never implemented it but it was released open source by the facbook people who after creating and using it saw their server load go down by about 30%. Basically it takes regular php files, converts them to C++ binaries and serves those out.
|
14,187 |
have a website (www.americanbankingnews.com) that gets 40,000-50,000 page views today. It's currently sitting on a dedicated quad-core Xeon server with 8GB of ram. The site is powered by WordPress and MySQL (sitting on the same server) and I'm currently using W3 Total Cache for page and MySQL query Caching.
Unfortunately, that doesn't seem to be enough. During peak traffic times, my servers are getting a few HTTP 500 errors and pages that aren't cached load slowly.
I'm currently not using Xcache or any other PHP cache/acceleration tools.
Are there additional steps that I should take to try to optimize MySQL and PHP performance? Or should I fork over for an additional server. Specifically, I'd be interested in additional suggestions to improve MySQL performance and whether or not tools like xcache might help in this situation
|
2011/04/07
|
[
"https://wordpress.stackexchange.com/questions/14187",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/4510/"
] |
Lots of similar questions and answers:
<https://wordpress.stackexchange.com/search?q=mysql+optimize>
It comes down to using tools - like mysqltuner - to investigate the bottlenecks, checking logs for errors and memory usage, php opcode-caching, clearing post/page revisons to get the DB down to size, etc.
|
i dont know what programs you installed but maybe its APC - Zend problem:
<http://www.ivankristianto.com/web-development/server/alternative-php-cache-apc-not-compatible-with-zend-optimizer/1726/>
>
> This problem happen in my VPS after i
> install Alternative PHP cache (APC).
> And also i already have Zend optimizer
> installed on the same VPS. After i
> installed APC, my WordPress blog show
> strange behavior. Sometimes i got
> Error 500 Internal Server Error, and
> sometimes i got PHP fatal error.
>
>
>
|
14,187 |
have a website (www.americanbankingnews.com) that gets 40,000-50,000 page views today. It's currently sitting on a dedicated quad-core Xeon server with 8GB of ram. The site is powered by WordPress and MySQL (sitting on the same server) and I'm currently using W3 Total Cache for page and MySQL query Caching.
Unfortunately, that doesn't seem to be enough. During peak traffic times, my servers are getting a few HTTP 500 errors and pages that aren't cached load slowly.
I'm currently not using Xcache or any other PHP cache/acceleration tools.
Are there additional steps that I should take to try to optimize MySQL and PHP performance? Or should I fork over for an additional server. Specifically, I'd be interested in additional suggestions to improve MySQL performance and whether or not tools like xcache might help in this situation
|
2011/04/07
|
[
"https://wordpress.stackexchange.com/questions/14187",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/4510/"
] |
Hi **@Matthew Paulson:**
You may be asking the wrong question.
With your traffic you *may* want to look at at front-end cache using [**nginx**](http://nginx.org/en/). Here are Q&As for nginx here on the site, lots of relevant articles in a Google search, and plugin that can interface WordPress to nginx at wordpress.org and lastly an article on installing and configuring:
* <https://wordpress.stackexchange.com/search?q=nginx>
* <http://www.google.com/search?q=nginx+wordpress>
* <http://wordpress.org/extend/plugins/search.php?q=nginx>
* <http://elasticdog.com/2008/02/howto-install-wordpress-on-nginx/>
If that doesn't help or if you don't want to do it for some other reason please let us know **what plugins you are using**. Most of the time with WordPress performance problems are not the obvious but instead they are result of some poorly written plugins.
|
i dont know what programs you installed but maybe its APC - Zend problem:
<http://www.ivankristianto.com/web-development/server/alternative-php-cache-apc-not-compatible-with-zend-optimizer/1726/>
>
> This problem happen in my VPS after i
> install Alternative PHP cache (APC).
> And also i already have Zend optimizer
> installed on the same VPS. After i
> installed APC, my WordPress blog show
> strange behavior. Sometimes i got
> Error 500 Internal Server Error, and
> sometimes i got PHP fatal error.
>
>
>
|
14,187 |
have a website (www.americanbankingnews.com) that gets 40,000-50,000 page views today. It's currently sitting on a dedicated quad-core Xeon server with 8GB of ram. The site is powered by WordPress and MySQL (sitting on the same server) and I'm currently using W3 Total Cache for page and MySQL query Caching.
Unfortunately, that doesn't seem to be enough. During peak traffic times, my servers are getting a few HTTP 500 errors and pages that aren't cached load slowly.
I'm currently not using Xcache or any other PHP cache/acceleration tools.
Are there additional steps that I should take to try to optimize MySQL and PHP performance? Or should I fork over for an additional server. Specifically, I'd be interested in additional suggestions to improve MySQL performance and whether or not tools like xcache might help in this situation
|
2011/04/07
|
[
"https://wordpress.stackexchange.com/questions/14187",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/4510/"
] |
Hi **@Matthew Paulson:**
You may be asking the wrong question.
With your traffic you *may* want to look at at front-end cache using [**nginx**](http://nginx.org/en/). Here are Q&As for nginx here on the site, lots of relevant articles in a Google search, and plugin that can interface WordPress to nginx at wordpress.org and lastly an article on installing and configuring:
* <https://wordpress.stackexchange.com/search?q=nginx>
* <http://www.google.com/search?q=nginx+wordpress>
* <http://wordpress.org/extend/plugins/search.php?q=nginx>
* <http://elasticdog.com/2008/02/howto-install-wordpress-on-nginx/>
If that doesn't help or if you don't want to do it for some other reason please let us know **what plugins you are using**. Most of the time with WordPress performance problems are not the obvious but instead they are result of some poorly written plugins.
|
Do you have insight in what exactly is becoming a bottleneck under high load? It could be different type of resource (CPU load, sustaining network conenctions, running out of memory, etc).
General things:
* **opcode cache** (keeping compiled PHP code in memory) is a must;
* you seem to have memory to burn, so it's worth trying **memory-based object cache** (W3TC supports it, look into that). It will make a lot of stuff more persistent and move load away from MySQL;
* if web server software is bottleneck (you don't mention what you run, Apache?) you might want to look into **alternative web server** (like nginx) or **reverse proxy** (again - you have memory to burn, I heard good things about Varnish).
|
57,905,279 |
I'll preface this question with the fact I am a newbie, and I just want a clear answer as I'm confused when I go to the internet for help. That said, here is my question:
If someone submits a pull request, how do I pull those changes to my local machine to review before merging with master? Say the branch is named **feature1**.
Would "git pull feature1" on my local machine be sufficient?
I was thinking you could to hit "Merge" button through bitbucket and then "git pull origin master" to local, but there would be no way to check the code beforehand so that doesn't seem right.
Again, my apologies if this is a very beginner question. Just hoping for some clarity. Thanks in advance.
|
2019/09/12
|
[
"https://Stackoverflow.com/questions/57905279",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10381908/"
] |
A pull request is a special ref in the format of `refs/pull/<number>/head`. Suppose there is a pull request `#29`. You can fetch it and create a local branch `p29` for it in the local repository by:
```
git fetch origin pull/29/head:p29
```
and then compare it with `master` by:
```
git diff master p29
```
If you are using a git GUI client or a user-friendly difftool, you can see the diff between the two branches in a more pleasant way.
When the review is done, you can remove `p29` by:
```
git branch -D p29
```
`p29` could be any other name you like as long as it's a valid ref name.
|
Normaly, it's best to use the following steps, considering you have a master branch and a feature branch that needs to be merged to master:
1. In your feature branch, make sure you comitted all your local changes.
2. Pull the feature branch from your remote. This will make sure that if other people worked on that feature, you don't miss those changes. Solve conflicts if any, and test if your feature branch still works (the application).
3. Pull the master branch from your remote.
4. Merge your master branch to your feature branch like `git merge --no-ff master`. No fast-forward makes sure you don't lose individual commits in your log.
5. Your feature branch is now equal to what you want to be the master branch: the master has been merged to the feature and you can now locally test if everything is alright.
6. If you are happy with the result, you can push your feature branch to your remote.
7. On the remote, you can create a pull request to merge your feature to the master branch. Because you tested your code + merge in step 5, you can be sure that the master branch will be alright. The Pull Request is now only for reviewing the code. You already tested it.
|
57,905,279 |
I'll preface this question with the fact I am a newbie, and I just want a clear answer as I'm confused when I go to the internet for help. That said, here is my question:
If someone submits a pull request, how do I pull those changes to my local machine to review before merging with master? Say the branch is named **feature1**.
Would "git pull feature1" on my local machine be sufficient?
I was thinking you could to hit "Merge" button through bitbucket and then "git pull origin master" to local, but there would be no way to check the code beforehand so that doesn't seem right.
Again, my apologies if this is a very beginner question. Just hoping for some clarity. Thanks in advance.
|
2019/09/12
|
[
"https://Stackoverflow.com/questions/57905279",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10381908/"
] |
Sometimes pull request comes from forks, in order to get them you have to give url of of fork like you do this
```
git checkout master
git checkout -b feature1
git pull 'https://github.com/user/username/fork.git' feature1
```
if everything goes successfully, your 'feature1' branch has all the changes so now you can
```
git diff master
```
to see the difference between master and the pull request, if you like it you can merge it into master like this:
```
git checkout master
git merge feature1
```
and that's it... I hope it helps
|
Normaly, it's best to use the following steps, considering you have a master branch and a feature branch that needs to be merged to master:
1. In your feature branch, make sure you comitted all your local changes.
2. Pull the feature branch from your remote. This will make sure that if other people worked on that feature, you don't miss those changes. Solve conflicts if any, and test if your feature branch still works (the application).
3. Pull the master branch from your remote.
4. Merge your master branch to your feature branch like `git merge --no-ff master`. No fast-forward makes sure you don't lose individual commits in your log.
5. Your feature branch is now equal to what you want to be the master branch: the master has been merged to the feature and you can now locally test if everything is alright.
6. If you are happy with the result, you can push your feature branch to your remote.
7. On the remote, you can create a pull request to merge your feature to the master branch. Because you tested your code + merge in step 5, you can be sure that the master branch will be alright. The Pull Request is now only for reviewing the code. You already tested it.
|
1,511,025 |
I have a silverlight app that allows the user to draw on it and save the drawing.
The strokecollection in the canvas is converted to xml attributes and stored in the database.
the only problem i have now is converting the xml back into a stroke collection.
my strokes are stored as such:
```
<Strokes>
<Stroke>
<Color A="255" R="0" G="0" B="0" />
<OutlineColor A="0" R="0" G="0" B="0" />
<Points>
<Point X="60" Y="57" PressureFactor="0.5" />
<Point X="332" Y="52" PressureFactor="0.5" />
</Points>
<Width>3</Width>
<Height>3</Height>
</Stroke>
</Strokes>
```
|
2009/10/02
|
[
"https://Stackoverflow.com/questions/1511025",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/166658/"
] |
For Moonlight 2.0 we'll be using mono's 2.6 branch from here:
<http://anonsvn.mono-project.com/source/branches/mono-2-6/>
mono trunk is going through a lot of unstable changes right now, which is why we decided to use the stable 2.6 branch instead.
|
I think Moonlight currently uses a branch of mono and mcs, so it might be best to use that - or it might just be a makfile bug in mcs trunk. You'd be best asking on the moonlight mailing list or IRC.
|
1,511,025 |
I have a silverlight app that allows the user to draw on it and save the drawing.
The strokecollection in the canvas is converted to xml attributes and stored in the database.
the only problem i have now is converting the xml back into a stroke collection.
my strokes are stored as such:
```
<Strokes>
<Stroke>
<Color A="255" R="0" G="0" B="0" />
<OutlineColor A="0" R="0" G="0" B="0" />
<Points>
<Point X="60" Y="57" PressureFactor="0.5" />
<Point X="332" Y="52" PressureFactor="0.5" />
</Points>
<Width>3</Width>
<Height>3</Height>
</Stroke>
</Strokes>
```
|
2009/10/02
|
[
"https://Stackoverflow.com/questions/1511025",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/166658/"
] |
I think Moonlight currently uses a branch of mono and mcs, so it might be best to use that - or it might just be a makfile bug in mcs trunk. You'd be best asking on the moonlight mailing list or IRC.
|
For such specific questions about building moonlight, please join us on irc.gnom.org/#moonlight or our mailing list moonlight-list @ lists.ximian.com. We can better help you that way.
|
1,511,025 |
I have a silverlight app that allows the user to draw on it and save the drawing.
The strokecollection in the canvas is converted to xml attributes and stored in the database.
the only problem i have now is converting the xml back into a stroke collection.
my strokes are stored as such:
```
<Strokes>
<Stroke>
<Color A="255" R="0" G="0" B="0" />
<OutlineColor A="0" R="0" G="0" B="0" />
<Points>
<Point X="60" Y="57" PressureFactor="0.5" />
<Point X="332" Y="52" PressureFactor="0.5" />
</Points>
<Width>3</Width>
<Height>3</Height>
</Stroke>
</Strokes>
```
|
2009/10/02
|
[
"https://Stackoverflow.com/questions/1511025",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/166658/"
] |
For Moonlight 2.0 we'll be using mono's 2.6 branch from here:
<http://anonsvn.mono-project.com/source/branches/mono-2-6/>
mono trunk is going through a lot of unstable changes right now, which is why we decided to use the stable 2.6 branch instead.
|
For such specific questions about building moonlight, please join us on irc.gnom.org/#moonlight or our mailing list moonlight-list @ lists.ximian.com. We can better help you that way.
|
44,643,443 |
I've spent a lot of time researching the keyring package trying to get a simple example to work. I'm using python 2.7 on a windows 7-x64 machine. I've installed the package and confirmed that the files are within my Lib/site-packages folder.
In this code snippet from the installation docs what is supposed to go in "system"?
```
import keyring
keyring.get_password("system", "username")
```
When I run the code i get the following error:
>
> *RuntimeError: No recommended backend was available. Install the keyrings.alt package if you want to use the non-recommended backends.*
>
>
>
It seems like it's not recognizing Windows as the backend. I feel like I'm missing a simple step. Any help is appreciated including a simple code example of pulling generic credentials from Windows Credential Manager.
|
2017/06/20
|
[
"https://Stackoverflow.com/questions/44643443",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8186108/"
] |
You may have to install the `pywin32` package. Doing so solved the problem for me.
Using `conda`:
`conda install -e environment_name_here pywin32`
Using `pip`:
`pip install pywin32`
On a tangent: For some reason, the code swallows an exception that the windows credential manager class would have otherwise thrown to alert you to this problem. [Here's the exception](https://github.com/jaraco/keyring/blob/3d3066fea9f6b2079916ca515d0d8993c15b5b28/keyring/backends/Windows.py#L61) and [here's where it's caught and thrown away](https://github.com/jaraco/keyring/blob/3d3066fea9f6b2079916ca515d0d8993c15b5b28/keyring/backend.py#L189).
|
i don't know if you can do that but instead you can ask the user to give it's credentials using this following commands
```
import admin
if not admin.isUserAdmin():
admin.runAsAdmin()
```
|
44,643,443 |
I've spent a lot of time researching the keyring package trying to get a simple example to work. I'm using python 2.7 on a windows 7-x64 machine. I've installed the package and confirmed that the files are within my Lib/site-packages folder.
In this code snippet from the installation docs what is supposed to go in "system"?
```
import keyring
keyring.get_password("system", "username")
```
When I run the code i get the following error:
>
> *RuntimeError: No recommended backend was available. Install the keyrings.alt package if you want to use the non-recommended backends.*
>
>
>
It seems like it's not recognizing Windows as the backend. I feel like I'm missing a simple step. Any help is appreciated including a simple code example of pulling generic credentials from Windows Credential Manager.
|
2017/06/20
|
[
"https://Stackoverflow.com/questions/44643443",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8186108/"
] |
Finally got this working. The information from Shaun pointed me in the right direction with installing `pywin32`. From there I did trial and error with creating test credentials in Windows Credential Manager and testing the Python keyring function.
I only got it working with Generic Credentials which is fine for my purposes. I set Internet or network address to `"test"`. Username was set to `"test_user"`. Password was set to `"test123"`. (Quotes included here for instruction, don't include when entering them.
```
print keyring.get_password("test","test_user")
```
returned the result `"test123"`
Hopefully this information helps somebody else. Thanks to Shaun for the direction needed to solve this.
|
i don't know if you can do that but instead you can ask the user to give it's credentials using this following commands
```
import admin
if not admin.isUserAdmin():
admin.runAsAdmin()
```
|
44,643,443 |
I've spent a lot of time researching the keyring package trying to get a simple example to work. I'm using python 2.7 on a windows 7-x64 machine. I've installed the package and confirmed that the files are within my Lib/site-packages folder.
In this code snippet from the installation docs what is supposed to go in "system"?
```
import keyring
keyring.get_password("system", "username")
```
When I run the code i get the following error:
>
> *RuntimeError: No recommended backend was available. Install the keyrings.alt package if you want to use the non-recommended backends.*
>
>
>
It seems like it's not recognizing Windows as the backend. I feel like I'm missing a simple step. Any help is appreciated including a simple code example of pulling generic credentials from Windows Credential Manager.
|
2017/06/20
|
[
"https://Stackoverflow.com/questions/44643443",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8186108/"
] |
Finally got this working. The information from Shaun pointed me in the right direction with installing `pywin32`. From there I did trial and error with creating test credentials in Windows Credential Manager and testing the Python keyring function.
I only got it working with Generic Credentials which is fine for my purposes. I set Internet or network address to `"test"`. Username was set to `"test_user"`. Password was set to `"test123"`. (Quotes included here for instruction, don't include when entering them.
```
print keyring.get_password("test","test_user")
```
returned the result `"test123"`
Hopefully this information helps somebody else. Thanks to Shaun for the direction needed to solve this.
|
You may have to install the `pywin32` package. Doing so solved the problem for me.
Using `conda`:
`conda install -e environment_name_here pywin32`
Using `pip`:
`pip install pywin32`
On a tangent: For some reason, the code swallows an exception that the windows credential manager class would have otherwise thrown to alert you to this problem. [Here's the exception](https://github.com/jaraco/keyring/blob/3d3066fea9f6b2079916ca515d0d8993c15b5b28/keyring/backends/Windows.py#L61) and [here's where it's caught and thrown away](https://github.com/jaraco/keyring/blob/3d3066fea9f6b2079916ca515d0d8993c15b5b28/keyring/backend.py#L189).
|
6,855 |
I'm trying out a new type of review, which includes a score card at the top *in addition to the rest of the review* to summarize how the code shapes up. I would like to standardize the scores within the card and improve it.
Here's what it currently looks like:
>
> Code Score
> ==========
>
>
> 1. **Design**: n/a
> 2. **Readability & Maintainability**: n/a
> 3. **Functionality**: n/a
> 4. **Performance**: n/a
> 5. **Security**: n/a
> 6. **Test coverage**: n/a
>
>
>
Any suggestions on improving them?
|
2016/06/23
|
[
"https://codereview.meta.stackexchange.com/questions/6855",
"https://codereview.meta.stackexchange.com",
"https://codereview.meta.stackexchange.com/users/27623/"
] |
How does a score card actually help the OP?
-------------------------------------------
Telling them their code sucks, without explaining how to improve it, is no benefit to anybody.
Telling them how to improve it, by definition, involves explaining why it's not so good at the moment. So why have the score if you're just going to tell them in your review anyway.
Additionally, code reviews are inherently subjective. You can objectively say if code follows certain standards and best practices, but then you fall into the trap of optimising for metrics you can objectively measure, as opposed to the things that are actually important (In general or in the specific context of the code).
IMO, a score card is going to be kinda feel-good but incredibly subjective and will not add anything useful to a review. It may even hurt by implying a level of objectivity and certainty that **never** exists in code.
|
I also think that this is a very bad idea.
We are already subject to users that are giving code only reviews, which are not reviews at all and don't belong on Code Review, if we start doing this score card type of deal I am afraid that new users will start posting just the score cards and not posting an actual review.
Score Cards are not needed, there is enough gaming of the SE system that goes on around here already.
We have enough things to flag and edit around here.
There is plenty to review in the code when a good question or code base is posted.
|
3,159,644 |
gcc 4.4.4 c89
I am using the code below. However, I keep getting the same number:
```
size_t i = 0;
for(i = 0; i < 3; i++) {
/* Initialize random number */
srand((unsigned int)time(NULL));
/* Added random number (simulate seconds) */
add((rand() % 30) + 1);
}
```
I would like to get 0 to 30 returned. However, the last time I ran this I got 17 three times.
Many thanks,
|
2010/07/01
|
[
"https://Stackoverflow.com/questions/3159644",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/70942/"
] |
You need to call srand just once, at the beginning of your program.
`srand` initializes the pseudo random number generator using time in seconds. If you initialize it with a particular number, you will always get the same sequence of numbers. That's why you usually want to initialize it at the beginning using the time (so that the seed is different each time you run the program) and then use only `rand` to generate numbers which seem random.
In your case the time does not change from iteration to iteration, as its resolution is just 1 second, so you are always getting the first number of the pseudo-random sequence, which is always the same.
|
I rather suggest also using gettimeofday() system call to retrieve the seed to be used to feed srand().
Something like
```
struct timeval tv;
...
gettimeofday(&tv, NULL);
srand(tv.tv_usec);
...
```
This approach can add more entropy in your pseudo number generation code.
IMHO of course
Ciao ciao
|
3,159,644 |
gcc 4.4.4 c89
I am using the code below. However, I keep getting the same number:
```
size_t i = 0;
for(i = 0; i < 3; i++) {
/* Initialize random number */
srand((unsigned int)time(NULL));
/* Added random number (simulate seconds) */
add((rand() % 30) + 1);
}
```
I would like to get 0 to 30 returned. However, the last time I ran this I got 17 three times.
Many thanks,
|
2010/07/01
|
[
"https://Stackoverflow.com/questions/3159644",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/70942/"
] |
You need to call srand just once, at the beginning of your program.
`srand` initializes the pseudo random number generator using time in seconds. If you initialize it with a particular number, you will always get the same sequence of numbers. That's why you usually want to initialize it at the beginning using the time (so that the seed is different each time you run the program) and then use only `rand` to generate numbers which seem random.
In your case the time does not change from iteration to iteration, as its resolution is just 1 second, so you are always getting the first number of the pseudo-random sequence, which is always the same.
|
You need to do `srand((unsigned int)time(NULL))` only once before the loop.
|
3,159,644 |
gcc 4.4.4 c89
I am using the code below. However, I keep getting the same number:
```
size_t i = 0;
for(i = 0; i < 3; i++) {
/* Initialize random number */
srand((unsigned int)time(NULL));
/* Added random number (simulate seconds) */
add((rand() % 30) + 1);
}
```
I would like to get 0 to 30 returned. However, the last time I ran this I got 17 three times.
Many thanks,
|
2010/07/01
|
[
"https://Stackoverflow.com/questions/3159644",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/70942/"
] |
You're seeding *inside* the loop (with the same value because of how quickly the loop will be executed), which causes the random number generated to be the same each time.
You need to move your seed function *outside* the loop:
```
/* Initialize random number */
srand((unsigned int)time(NULL));
for(i = 0; i < 3; i++) {
/* Added random number (simulate seconds) */
add((rand() % 30) + 1);
}
```
|
Seed to the pseudo Random number generator should be called only once outside the loop. Using time as a seed is good thing.
However there is still a possiblity of getting the same random number.
|
3,159,644 |
gcc 4.4.4 c89
I am using the code below. However, I keep getting the same number:
```
size_t i = 0;
for(i = 0; i < 3; i++) {
/* Initialize random number */
srand((unsigned int)time(NULL));
/* Added random number (simulate seconds) */
add((rand() % 30) + 1);
}
```
I would like to get 0 to 30 returned. However, the last time I ran this I got 17 three times.
Many thanks,
|
2010/07/01
|
[
"https://Stackoverflow.com/questions/3159644",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/70942/"
] |
You're seeding *inside* the loop (with the same value because of how quickly the loop will be executed), which causes the random number generated to be the same each time.
You need to move your seed function *outside* the loop:
```
/* Initialize random number */
srand((unsigned int)time(NULL));
for(i = 0; i < 3; i++) {
/* Added random number (simulate seconds) */
add((rand() % 30) + 1);
}
```
|
I rather suggest also using gettimeofday() system call to retrieve the seed to be used to feed srand().
Something like
```
struct timeval tv;
...
gettimeofday(&tv, NULL);
srand(tv.tv_usec);
...
```
This approach can add more entropy in your pseudo number generation code.
IMHO of course
Ciao ciao
|
3,159,644 |
gcc 4.4.4 c89
I am using the code below. However, I keep getting the same number:
```
size_t i = 0;
for(i = 0; i < 3; i++) {
/* Initialize random number */
srand((unsigned int)time(NULL));
/* Added random number (simulate seconds) */
add((rand() % 30) + 1);
}
```
I would like to get 0 to 30 returned. However, the last time I ran this I got 17 three times.
Many thanks,
|
2010/07/01
|
[
"https://Stackoverflow.com/questions/3159644",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/70942/"
] |
It is completely possible that the 3 times 17 are still completely random.
There is an about 1 in 10 chance of getting two numbers the same when using a range of 1-30 and three picks. (this is due to the [birthday problem](http://en.wikipedia.org/wiki/Birthday_problem) )
Now, getting three the same results has still a propability of 1 in 900 using the same range.
you might want to read more background on the [analysis page of random.org](http://www.random.org/analysis/)
|
Seed to the pseudo Random number generator should be called only once outside the loop. Using time as a seed is good thing.
However there is still a possiblity of getting the same random number.
|
3,159,644 |
gcc 4.4.4 c89
I am using the code below. However, I keep getting the same number:
```
size_t i = 0;
for(i = 0; i < 3; i++) {
/* Initialize random number */
srand((unsigned int)time(NULL));
/* Added random number (simulate seconds) */
add((rand() % 30) + 1);
}
```
I would like to get 0 to 30 returned. However, the last time I ran this I got 17 three times.
Many thanks,
|
2010/07/01
|
[
"https://Stackoverflow.com/questions/3159644",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/70942/"
] |
It is completely possible that the 3 times 17 are still completely random.
There is an about 1 in 10 chance of getting two numbers the same when using a range of 1-30 and three picks. (this is due to the [birthday problem](http://en.wikipedia.org/wiki/Birthday_problem) )
Now, getting three the same results has still a propability of 1 in 900 using the same range.
you might want to read more background on the [analysis page of random.org](http://www.random.org/analysis/)
|
I rather suggest also using gettimeofday() system call to retrieve the seed to be used to feed srand().
Something like
```
struct timeval tv;
...
gettimeofday(&tv, NULL);
srand(tv.tv_usec);
...
```
This approach can add more entropy in your pseudo number generation code.
IMHO of course
Ciao ciao
|
3,159,644 |
gcc 4.4.4 c89
I am using the code below. However, I keep getting the same number:
```
size_t i = 0;
for(i = 0; i < 3; i++) {
/* Initialize random number */
srand((unsigned int)time(NULL));
/* Added random number (simulate seconds) */
add((rand() % 30) + 1);
}
```
I would like to get 0 to 30 returned. However, the last time I ran this I got 17 three times.
Many thanks,
|
2010/07/01
|
[
"https://Stackoverflow.com/questions/3159644",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/70942/"
] |
You need to do `srand((unsigned int)time(NULL))` only once before the loop.
|
Seed to the pseudo Random number generator should be called only once outside the loop. Using time as a seed is good thing.
However there is still a possiblity of getting the same random number.
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.