Java script : How to find setInterval function is now running or timedout?
In my project I use two setInterval functions, One function is running all
time. The second function is start and stop dynamically according to
keyboard input. How to find state(Running or Timeout) of setInterval
funcion?
Tuesday, 10 September 2013
more then one jquery calculate on same page
more then one jquery calculate on same page
I need some help running two jquery.calculation on the same page, in my
example only the 2nd table is working, I have added the script 2x and have
renamed all the elements but it's not working.
When I remove the 2nd script the 1st one is working. When I add the 2nd
script the first one stops.
I understand that somehow these 2 scripts need to be combine but I really
do not know how.
Thank you.
Here is an example: jsfiddle example
<script>
$(document).ready(function() {
$("#idPluginVersion").text($.Calculation.version);
$("[name^=qty_]").bind("change keyup", recalc);
$("[name^=aantal_]").bind("change keyup", recalc);
$("[name^=price_]").bind("change keyup", recalc);
$("[name^=bedrag_]").bind("change keyup", recalc);
recalc();
});
function recalc() {
$("[id^=total_item]").calc(
"((qty * price) + (aantal * bedrag))",
{
qty: $("[name^=qty_]"),
aantal: $("[name^=aantal_]"),
price: $("[id^=price_]"),
bedrag: $("[id^=bedrag_]")
},
function (s) {
return s.toFixed(2);
},
function ($this) {
var sum = $this.sum();
$("#subTotal").val( sum.toFixed(2) );
}
);
}
</script>
<script>
$(document).ready(function() {
$("#idPluginVersion").text($.Calculation.version);
$("[name^=qty2_]").bind("change keyup", recalc);
$("[name^=aantal2_]").bind("change keyup", recalc);
$("[name^=price2_]").bind("change keyup", recalc);
$("[name^=bedrag2_]").bind("change keyup", recalc);
recalc();
});
function recalc() {
$("[id^=total2_item]").calc(
"((qty2 * price2) + (aantal2 * bedrag2))",
{
qty2: $("[name^=qty2_]"),
aantal2: $("[name^=aantal2_]"),
price2: $("[id^=price2_]"),
bedrag2: $("[id^=bedrag2_]")
},
function (s) {
return s.toFixed(2);
},
);
}
</script>
I need some help running two jquery.calculation on the same page, in my
example only the 2nd table is working, I have added the script 2x and have
renamed all the elements but it's not working.
When I remove the 2nd script the 1st one is working. When I add the 2nd
script the first one stops.
I understand that somehow these 2 scripts need to be combine but I really
do not know how.
Thank you.
Here is an example: jsfiddle example
<script>
$(document).ready(function() {
$("#idPluginVersion").text($.Calculation.version);
$("[name^=qty_]").bind("change keyup", recalc);
$("[name^=aantal_]").bind("change keyup", recalc);
$("[name^=price_]").bind("change keyup", recalc);
$("[name^=bedrag_]").bind("change keyup", recalc);
recalc();
});
function recalc() {
$("[id^=total_item]").calc(
"((qty * price) + (aantal * bedrag))",
{
qty: $("[name^=qty_]"),
aantal: $("[name^=aantal_]"),
price: $("[id^=price_]"),
bedrag: $("[id^=bedrag_]")
},
function (s) {
return s.toFixed(2);
},
function ($this) {
var sum = $this.sum();
$("#subTotal").val( sum.toFixed(2) );
}
);
}
</script>
<script>
$(document).ready(function() {
$("#idPluginVersion").text($.Calculation.version);
$("[name^=qty2_]").bind("change keyup", recalc);
$("[name^=aantal2_]").bind("change keyup", recalc);
$("[name^=price2_]").bind("change keyup", recalc);
$("[name^=bedrag2_]").bind("change keyup", recalc);
recalc();
});
function recalc() {
$("[id^=total2_item]").calc(
"((qty2 * price2) + (aantal2 * bedrag2))",
{
qty2: $("[name^=qty2_]"),
aantal2: $("[name^=aantal2_]"),
price2: $("[id^=price2_]"),
bedrag2: $("[id^=bedrag2_]")
},
function (s) {
return s.toFixed(2);
},
);
}
</script>
How to Bind points on to the wpf Area chart using generic list databinding in wpf
How to Bind points on to the wpf Area chart using generic list databinding
in wpf
I am working on WPF using c#. I am trying to display WPF Area chart with
values using WPF Toolkit. I have followed the CodeProject's KB Article and
write it like,
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:DV="clr-namespace:System.Windows.Controls.DataVisualization;assembly=System.Windows.Controls.DataVisualization.Toolkit"
xmlns:DVC="clr-namespace:System.Windows.Controls.DataVisualization.Charting;assembly=System.Windows.Controls.DataVisualization.Toolkit"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" x:Class="WpfChart.MainWindow"
Title="MainWindow" Height="621.053" Width="873.684">
<ScrollViewer HorizontalScrollBarVisibility="Auto"
VerticalScrollBarVisibility="Auto" Margin="0,-28,0,28">
<Grid Height="921">
<DVC:Chart x:Name="areaChart" Title="Chart Title"
VerticalAlignment="Top" Margin="33,73,24,0" Height="582"
Background="White" >
<DVC:AreaSeries DependentValuePath="Value"
IndependentValuePath="Key" ItemsSource="{Binding}"
IsSelectionEnabled="True" Title="Weeks of
Gestation"></DVC:AreaSeries>
<DVC:Chart.Palette>
<DV:ResourceDictionaryCollection>
<ResourceDictionary>
<Style x:Key="DataPointStyle"
TargetType="Control">
<Setter Property="Background"
Value="Firebrick" />
<Setter Property="BorderBrush"
Value="Black" />
</Style>
</ResourceDictionary>
</DV:ResourceDictionaryCollection>
</DVC:Chart.Palette>
<DVC:Chart.Axes>
<!-- Add Horizontal and Vertical Axes-->
<DVC:LinearAxis ShowGridLines="True"
Orientation="Y"
Title="Y Axis Title"
Interval="5" Maximum="45" Minimum="-5"
Foreground="Black"
FontFamily="Arial Black"
FontSize="16"
FontWeight="Bold"
/>
<DVC:LinearAxis ShowGridLines="True"
Orientation="X"
Title="X-Axis Title"
Interval="4" Minimum="0" Maximum="40"
Foreground="Black"
FontFamily="Arial Black"
FontSize="16"
FontWeight="Bold"
/>
</DVC:Chart.Axes>
</DVC:Chart>
</Grid>
</ScrollViewer>
</Window>
and i write code for initialization chart data like,
private void LoadAreaChartData()
{
((AreaSeries)areaChart.Series[0]).ItemsSource =
new KeyValuePair<string, int>[]{
new KeyValuePair<string, int>("3", 5)
};
}
But it does not map the points on to the chart. I need to map the point on
to the chart like,
(X,Y)--(3,5) its need to mark at the intersection of point 3 on x-axis and
point 5 on y-axis. How can i achieve this please guide me if i went in the
wrong way. Thanks in advance.
in wpf
I am working on WPF using c#. I am trying to display WPF Area chart with
values using WPF Toolkit. I have followed the CodeProject's KB Article and
write it like,
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:DV="clr-namespace:System.Windows.Controls.DataVisualization;assembly=System.Windows.Controls.DataVisualization.Toolkit"
xmlns:DVC="clr-namespace:System.Windows.Controls.DataVisualization.Charting;assembly=System.Windows.Controls.DataVisualization.Toolkit"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" x:Class="WpfChart.MainWindow"
Title="MainWindow" Height="621.053" Width="873.684">
<ScrollViewer HorizontalScrollBarVisibility="Auto"
VerticalScrollBarVisibility="Auto" Margin="0,-28,0,28">
<Grid Height="921">
<DVC:Chart x:Name="areaChart" Title="Chart Title"
VerticalAlignment="Top" Margin="33,73,24,0" Height="582"
Background="White" >
<DVC:AreaSeries DependentValuePath="Value"
IndependentValuePath="Key" ItemsSource="{Binding}"
IsSelectionEnabled="True" Title="Weeks of
Gestation"></DVC:AreaSeries>
<DVC:Chart.Palette>
<DV:ResourceDictionaryCollection>
<ResourceDictionary>
<Style x:Key="DataPointStyle"
TargetType="Control">
<Setter Property="Background"
Value="Firebrick" />
<Setter Property="BorderBrush"
Value="Black" />
</Style>
</ResourceDictionary>
</DV:ResourceDictionaryCollection>
</DVC:Chart.Palette>
<DVC:Chart.Axes>
<!-- Add Horizontal and Vertical Axes-->
<DVC:LinearAxis ShowGridLines="True"
Orientation="Y"
Title="Y Axis Title"
Interval="5" Maximum="45" Minimum="-5"
Foreground="Black"
FontFamily="Arial Black"
FontSize="16"
FontWeight="Bold"
/>
<DVC:LinearAxis ShowGridLines="True"
Orientation="X"
Title="X-Axis Title"
Interval="4" Minimum="0" Maximum="40"
Foreground="Black"
FontFamily="Arial Black"
FontSize="16"
FontWeight="Bold"
/>
</DVC:Chart.Axes>
</DVC:Chart>
</Grid>
</ScrollViewer>
</Window>
and i write code for initialization chart data like,
private void LoadAreaChartData()
{
((AreaSeries)areaChart.Series[0]).ItemsSource =
new KeyValuePair<string, int>[]{
new KeyValuePair<string, int>("3", 5)
};
}
But it does not map the points on to the chart. I need to map the point on
to the chart like,
(X,Y)--(3,5) its need to mark at the intersection of point 3 on x-axis and
point 5 on y-axis. How can i achieve this please guide me if i went in the
wrong way. Thanks in advance.
How do I make jQuery change the DOM on another webpage in my domain?
How do I make jQuery change the DOM on another webpage in my domain?
I can't figure out how to use jQuery on the webpage I'm on to make changes
to another webpage's html in my domain. Suppose I want to change the
following at mydomain.com/changedom.html:
<body>
<p id="changehere">This is the text I want to bold.</p>
</body>
and I'm in mydomain.com/index.html and I want to run jQuery to change the
previous page as below:
<script type="text/javascript"
src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js">
</script>
<script type="text/javascript">
$(document).ready(function() {
$('http://www.mydomain.com/changedom.html p#changehere').html(<b>This is
the text I want to bold.</b>');
});
</script>
doesn't work for me. Help!
I can't figure out how to use jQuery on the webpage I'm on to make changes
to another webpage's html in my domain. Suppose I want to change the
following at mydomain.com/changedom.html:
<body>
<p id="changehere">This is the text I want to bold.</p>
</body>
and I'm in mydomain.com/index.html and I want to run jQuery to change the
previous page as below:
<script type="text/javascript"
src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js">
</script>
<script type="text/javascript">
$(document).ready(function() {
$('http://www.mydomain.com/changedom.html p#changehere').html(<b>This is
the text I want to bold.</b>');
});
</script>
doesn't work for me. Help!
How to create folder in distributed cache in hadoop?
How to create folder in distributed cache in hadoop?
Is it possible to create directory inside preexisting distributed cache
and copy files from the previous directory to new directory i have
created?
Is it possible to create directory inside preexisting distributed cache
and copy files from the previous directory to new directory i have
created?
Monday, 9 September 2013
Debugging my current code, more efficient ways to do it
Debugging my current code, more efficient ways to do it
I'm currently writing a program that allows the user to input words such
as "four" + "fifty" of "six" + "fifty_five". The program with then use an
array to find the corresponding number, do calculations with the ints and
then change the ints back to word form. However I'm not currently getting
any output at all which leaves me to believe one of my loops aren't
running correctly or my calculations are off. I'll just place the part of
the code which I believe to be the problem, as I'm sure errors will be
found in that.
Function to convert int to string and return the result.
// Converts the calculated int to a string and then returns the result.
string Wordnum::write_number(int n) {
int ten;
if (n > 10) {
ten = n / 10;
n = n % 10;
}
string result = tens[ten] + "_" + units[n];
return result;
}
Function to change string to int to do calculations:
int Wordnum::read_number(string n) {
int result_ten = 0;
int result_unit = 0;
int j = 0;
// Loops through input and turns it all to lower case.
while (n[j]) {
char c;
c = n[j];
c = (tolower(c));
n[j] = c;
j++;
}
string delimiter = "_";
size_t pos = 0;
string token;
// Checks for the _ delimiter and takes the first token then checks it
against the array to "convert" from string to int.
while ((pos = n.find(delimiter)) != string::npos) {
token = n.substr(0, pos);
for (int i = 0; i < 20; i++) {
if (token == tens[i]) {
result_ten = i * 10;
}
if (token == units[i]) {
result_unit = i;
}
}
n.erase(0, pos);
}
result_ten = (result_ten + result_unit);
return result_ten;
}
How the arrays are initialized.
string const Wordnum::units[] = {"zero", "one", "two", "three", "four",
"five",
"six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen",
"fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen"};
string const Wordnum::tens[] = {"zero", "", "twenty", "thirty", "forty",
"fifty", "sixty", "seventy", "eighty", "ninety"};
All other functions are just overloaded operators, which were working in
the past. So I'm confident te problem is in here somewhere. All help will
be greatly appreciated, thanks in advance. ^^
Examples of how it should work is:
input: fifty_five + five output: sixty
input: ten - four output: six
At the moment, since I changed it to use a delimiter, I have been getting
no output what so ever, the code just fails.
I'm currently writing a program that allows the user to input words such
as "four" + "fifty" of "six" + "fifty_five". The program with then use an
array to find the corresponding number, do calculations with the ints and
then change the ints back to word form. However I'm not currently getting
any output at all which leaves me to believe one of my loops aren't
running correctly or my calculations are off. I'll just place the part of
the code which I believe to be the problem, as I'm sure errors will be
found in that.
Function to convert int to string and return the result.
// Converts the calculated int to a string and then returns the result.
string Wordnum::write_number(int n) {
int ten;
if (n > 10) {
ten = n / 10;
n = n % 10;
}
string result = tens[ten] + "_" + units[n];
return result;
}
Function to change string to int to do calculations:
int Wordnum::read_number(string n) {
int result_ten = 0;
int result_unit = 0;
int j = 0;
// Loops through input and turns it all to lower case.
while (n[j]) {
char c;
c = n[j];
c = (tolower(c));
n[j] = c;
j++;
}
string delimiter = "_";
size_t pos = 0;
string token;
// Checks for the _ delimiter and takes the first token then checks it
against the array to "convert" from string to int.
while ((pos = n.find(delimiter)) != string::npos) {
token = n.substr(0, pos);
for (int i = 0; i < 20; i++) {
if (token == tens[i]) {
result_ten = i * 10;
}
if (token == units[i]) {
result_unit = i;
}
}
n.erase(0, pos);
}
result_ten = (result_ten + result_unit);
return result_ten;
}
How the arrays are initialized.
string const Wordnum::units[] = {"zero", "one", "two", "three", "four",
"five",
"six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen",
"fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen"};
string const Wordnum::tens[] = {"zero", "", "twenty", "thirty", "forty",
"fifty", "sixty", "seventy", "eighty", "ninety"};
All other functions are just overloaded operators, which were working in
the past. So I'm confident te problem is in here somewhere. All help will
be greatly appreciated, thanks in advance. ^^
Examples of how it should work is:
input: fifty_five + five output: sixty
input: ten - four output: six
At the moment, since I changed it to use a delimiter, I have been getting
no output what so ever, the code just fails.
Testing a call to an external library in MiniTest
Testing a call to an external library in MiniTest
I am working on an application for a blog using Ruby on Rails. I have a
model called Essay with a Draper Decorator. I am also using MiniTest::Spec
for testing this application. Each Essay has a body which will be stored
as Markdown. In the EssayDecorator, I have a method called body which
renders the Markdown to html using RedCarpet.
In order to test this method, I wrote the following code:
describe '#body' do
it 'returns html from the markdown' do
essay = FactoryGirl.create(:essay)
@decorated_essay = essay.decorate
markdown = Minitest::Mock.new
@decorated_essay.stub :markdown, markdown do
markdown.expect :render, "<p>Test</p>", [essay.body]
@decorated_essay.send(:body)
markdown.verify
end
end
end
And inside the decorator I have two methods:
def body
markdown.render(model.body).html_safe
end
def markdown
Redcarpet::Markdown.new(Redcarpet::Render::HTML, :autolink => true,
:space_after_headers => true)
end
This test passes, but seems weird to me. I don't want to test that
RedCarpet is doing its job, I just want to test that I call the render
method.
Is there a best practice for mocking out this kind of thing in MiniTest? I
am pretty new to using Mocks and very new to using MiniTest.
Thanks, in advance.
I am working on an application for a blog using Ruby on Rails. I have a
model called Essay with a Draper Decorator. I am also using MiniTest::Spec
for testing this application. Each Essay has a body which will be stored
as Markdown. In the EssayDecorator, I have a method called body which
renders the Markdown to html using RedCarpet.
In order to test this method, I wrote the following code:
describe '#body' do
it 'returns html from the markdown' do
essay = FactoryGirl.create(:essay)
@decorated_essay = essay.decorate
markdown = Minitest::Mock.new
@decorated_essay.stub :markdown, markdown do
markdown.expect :render, "<p>Test</p>", [essay.body]
@decorated_essay.send(:body)
markdown.verify
end
end
end
And inside the decorator I have two methods:
def body
markdown.render(model.body).html_safe
end
def markdown
Redcarpet::Markdown.new(Redcarpet::Render::HTML, :autolink => true,
:space_after_headers => true)
end
This test passes, but seems weird to me. I don't want to test that
RedCarpet is doing its job, I just want to test that I call the render
method.
Is there a best practice for mocking out this kind of thing in MiniTest? I
am pretty new to using Mocks and very new to using MiniTest.
Thanks, in advance.
Subscribe to:
Posts (Atom)