A bug on bubble sorting
I want to sort a 2*n matrix, n is given in the input. Make a program to
output a matrix . Here is the requirment. (1)the first column MUST be
sorted in ASC, and (2)the second column in DESC if possible.
For Example, let n = 5, and the matrix is
3 4
1 2
3 5
1 6
7 3
The result should be
1 6
1 2
3 5
3 4
7 3
So I write down the code like this. First Line input the value n , and the
following lines like above.
#include <stdio.h>
#define TWO_16 65536
#define TWO_15 32768
int v[100000][2];
int z[100000];
int vec[100000];
int n;
int main()
{
int i, j;
scanf ("%d", &n); // give the value of n;
for (i = 1; i <= n; i++) // filling the matrix;
{
scanf ("%d%d", &v[i][0], &v[i][1]);
z[i] = TWO_16 * v[i][0] + TWO_15 - v[i][1];
vec[i] = i;
}
for (i = 1; i <= n; i++)
for (j = 1; j <= i; j++)
{
if (z[j] > z[i])
{
int t = vec[i];
vec[i] = vec[j];
vec[j] = t;
}
}
for (i = 1; i <= n; i++) // output the matrix
printf("%d %d\n",v[vec[i]][0],v[vec[i]][1]);
return 0;
}
But in gcc, the output is
1 6
3 5
3 4
1 2
7 3
What's more, when the first line is changed to "1 2" and the second is
changed to "3 4" in input, the result also changed.
What's the problem of my code?
Thursday, 3 October 2013
Wednesday, 2 October 2013
Use URI builder in an Android App
Use URI builder in an Android App
I'm developing an Android app. I need to build a URI for my app, to make
an API request. Unless there's another way to put a variable in a URL,
this is the easiest way I've found. I found that you need to use
Uri.Builder, but I'm not quite sure how to. My url is:
http://lapi.transitchicago.com/api/1.0/ttarrivals.aspx?key=[redacted]&mapid=`value`.
My scheme is http, authority lapi.transitchicago.com, path /api/1.0, path
segments ttarrivals.aspx, and query key=[redacted]&mapid=value.
I understand that I do uri.add, but how do I integrate it into the URI
builder? Would I add every thing, like URI.add(scheme),
URI.add(authority), and so on?
Thank you for your help.
I'm developing an Android app. I need to build a URI for my app, to make
an API request. Unless there's another way to put a variable in a URL,
this is the easiest way I've found. I found that you need to use
Uri.Builder, but I'm not quite sure how to. My url is:
http://lapi.transitchicago.com/api/1.0/ttarrivals.aspx?key=[redacted]&mapid=`value`.
My scheme is http, authority lapi.transitchicago.com, path /api/1.0, path
segments ttarrivals.aspx, and query key=[redacted]&mapid=value.
I understand that I do uri.add, but how do I integrate it into the URI
builder? Would I add every thing, like URI.add(scheme),
URI.add(authority), and so on?
Thank you for your help.
Submitting multiple values for one input field
Submitting multiple values for one input field
What I'm trying to do:
I'm trying to build a very simple visual layout builder. The idea is that,
the user selects a block, and it has some settings in it, those setting
values are stored in the hidden input, and when the user saves the page, i
store those values in the database.
Basic block is ok:
For example, user selects a 'text' block, it is added like this:
<div>
<input type="hidden" value="text" name="item_name[]">
<input type="hidden" value="" name="item_title[]">
<input type="hidden" value="sdsd" name="item_text[]">
</div>
Problem:
However, some of the blocks have more than one values for each field. For
example, 'gallery' block, which has multiple image urls, image titles etc.
I'm facing problem in finding a suitable way to put together the multiple
values and submit.
Right now I'm adding them to a string with jQuery, separated with __. I
can store the data and separate it, but the problem is that if I want to
remove any image from it, it is very difficult because I have just added
them in the string, so its hard to find it and remove it.
<div>
text item
<input type="hidden" value="gallery" name="item_name[]">
<input type="hidden" value="__http://img1.jpg__http://img2.jpg"
name="img_path[]">
<input type="hidden" value="__img1__img2" name="img_title[]">
<input type="hidden" value="" name="img_desc[]"></input>
</div>
Question:
What would be the suitable way to send multiple values for the above block
example, keeping in the mind that there will be multiple blocks having
multiple input values?
Thanks.
What I'm trying to do:
I'm trying to build a very simple visual layout builder. The idea is that,
the user selects a block, and it has some settings in it, those setting
values are stored in the hidden input, and when the user saves the page, i
store those values in the database.
Basic block is ok:
For example, user selects a 'text' block, it is added like this:
<div>
<input type="hidden" value="text" name="item_name[]">
<input type="hidden" value="" name="item_title[]">
<input type="hidden" value="sdsd" name="item_text[]">
</div>
Problem:
However, some of the blocks have more than one values for each field. For
example, 'gallery' block, which has multiple image urls, image titles etc.
I'm facing problem in finding a suitable way to put together the multiple
values and submit.
Right now I'm adding them to a string with jQuery, separated with __. I
can store the data and separate it, but the problem is that if I want to
remove any image from it, it is very difficult because I have just added
them in the string, so its hard to find it and remove it.
<div>
text item
<input type="hidden" value="gallery" name="item_name[]">
<input type="hidden" value="__http://img1.jpg__http://img2.jpg"
name="img_path[]">
<input type="hidden" value="__img1__img2" name="img_title[]">
<input type="hidden" value="" name="img_desc[]"></input>
</div>
Question:
What would be the suitable way to send multiple values for the above block
example, keeping in the mind that there will be multiple blocks having
multiple input values?
Thanks.
Check if IEnumerable is of a ValueType (at runtime)
Check if IEnumerable is of a ValueType (at runtime)
How do I check if an object I receive as a method result is not ValueType
and not IEnumerable<ValueType>?
Here is what I wrote:
MethodInfo selectedOverload = SelectOverload(selectedMethodOverloads);
object result = ExecuteAndShowResult(selectedOverload);
ExploreResult(result);
private static void ExploreResult(object result)
{
if (result != null &&
!(result is ValueType) &&
!((IEnumerable)result).GetType().GetProperty("Item").PropertyType) is
ValueType)
)
Console.WriteLine("explore");
}
Unfortunately type of PropertyType is Type, its content is the type I need
to check (e.g. int) but I don't know how to.
How do I check if an object I receive as a method result is not ValueType
and not IEnumerable<ValueType>?
Here is what I wrote:
MethodInfo selectedOverload = SelectOverload(selectedMethodOverloads);
object result = ExecuteAndShowResult(selectedOverload);
ExploreResult(result);
private static void ExploreResult(object result)
{
if (result != null &&
!(result is ValueType) &&
!((IEnumerable)result).GetType().GetProperty("Item").PropertyType) is
ValueType)
)
Console.WriteLine("explore");
}
Unfortunately type of PropertyType is Type, its content is the type I need
to check (e.g. int) but I don't know how to.
Saving Qlist to a file. Qt
Saving Qlist to a file. Qt
I have a qlist 'List' of objects of my own class. I want to save this to a
file for later use. I want to be able to open that file later, and use the
qlist to add more data (or modify,etc). I am using qt static build.
How should I go about this ? (little new at this)
I have a qlist 'List' of objects of my own class. I want to save this to a
file for later use. I want to be able to open that file later, and use the
qlist to add more data (or modify,etc). I am using qt static build.
How should I go about this ? (little new at this)
Tuesday, 1 October 2013
expectation calculation in probability and statistics
expectation calculation in probability and statistics
2 four-sided dice are rolled. X = number of odd dice Y = number of even
dice Z = number of dice showing 1 or 2 So each of X, Y, Z only takes on
the values 0, 1, 2. (a) joint p.m.f. of (X,Y)? joint p.m.f. of (X,Z). You
can give your answers in the form of 3 by 3 tables. (b) Are X and Y
independent? Are X and Z independent? (c) Compute E(XY ) and E(XZ).
WHAT I TRIED IS - The faces on a four-sided die are labeled with the
numbers 1, 2, 3, and 4. Upon throwing the dice, each one will land with
exactly one of its faces upwards. You will therefore see two numbers, one
for each die. Suppose, for the sake of example, that you see a 2 and a 4.
Both of these are even numbers. None of them are odd numbers. Let's count:
no dice show an odd number, two dice show even numbers, and one die shows
a number in the set {1,2}. Therefore, for this throw,, X=0, Y=2, and Z=1.
There are 16 combinations (1,1) (1,2)(1,3) (1,4)(2,1)(2,2)(2,3)(2,4) ...
(4,1 )(4,2 )(4,3 )(4,4 ) There are only 2 case when no dice show an odd
number, two dice show even numbers, and one die shows a number in the set
{1,2}. ---> when (2,2) (2,4 ) occurs. Here X= 0, Y =2, Z =1 Both odd and
one is in {1,2} is --> (1,1)(1,3)(3,1) Here, X= 2, Y =0, Z =1 Just as we
have to in the case with one discrete random variable, in order to find
the "joint probability distribution" of X and Y, we first need to define
the support of X and Y.
The support of X is: S1 = {2, 4} And, the support of Y is: S2 = {1, 3}
X, Y and Z combinations are - {(1,1), (1,2), (1,3), (1,4), (2,1), (2,2),
(2,3), (2,4), (3,1), (3,2), (3,3), (3,4), (4,1), (4,2), (4,3), (4,4)} Out
of this, the X, Y, Z values are respectively,
(2,0,1) , (1,1,2) ,
(2,0,1),(1,1,1),(1,1,2),(0,2,1),(1,1,1),(0,2,1),(2,0,1),(1,1,1),(2,0,0),(1,1,0),(1,1,1),(0,2,1),(1,1,0),(0,2,0).
b) The random variables X and Y are independent if and only if: P(X= x, Y
= y) = P(X = x) ~ P(Y = y) for allx¸S1,y¸S2.
if we again take a look back at the representation of our joint p.m.f. in
tabular form, you might notice that the following holds true: P(X=x,Y=y)
for allx¸S1,y¸S2. When this happens, we say that X and Y are
independent.
Similarly for X, Z, they are also independent.
c) I am not sure how to do
help please.
2 four-sided dice are rolled. X = number of odd dice Y = number of even
dice Z = number of dice showing 1 or 2 So each of X, Y, Z only takes on
the values 0, 1, 2. (a) joint p.m.f. of (X,Y)? joint p.m.f. of (X,Z). You
can give your answers in the form of 3 by 3 tables. (b) Are X and Y
independent? Are X and Z independent? (c) Compute E(XY ) and E(XZ).
WHAT I TRIED IS - The faces on a four-sided die are labeled with the
numbers 1, 2, 3, and 4. Upon throwing the dice, each one will land with
exactly one of its faces upwards. You will therefore see two numbers, one
for each die. Suppose, for the sake of example, that you see a 2 and a 4.
Both of these are even numbers. None of them are odd numbers. Let's count:
no dice show an odd number, two dice show even numbers, and one die shows
a number in the set {1,2}. Therefore, for this throw,, X=0, Y=2, and Z=1.
There are 16 combinations (1,1) (1,2)(1,3) (1,4)(2,1)(2,2)(2,3)(2,4) ...
(4,1 )(4,2 )(4,3 )(4,4 ) There are only 2 case when no dice show an odd
number, two dice show even numbers, and one die shows a number in the set
{1,2}. ---> when (2,2) (2,4 ) occurs. Here X= 0, Y =2, Z =1 Both odd and
one is in {1,2} is --> (1,1)(1,3)(3,1) Here, X= 2, Y =0, Z =1 Just as we
have to in the case with one discrete random variable, in order to find
the "joint probability distribution" of X and Y, we first need to define
the support of X and Y.
The support of X is: S1 = {2, 4} And, the support of Y is: S2 = {1, 3}
X, Y and Z combinations are - {(1,1), (1,2), (1,3), (1,4), (2,1), (2,2),
(2,3), (2,4), (3,1), (3,2), (3,3), (3,4), (4,1), (4,2), (4,3), (4,4)} Out
of this, the X, Y, Z values are respectively,
(2,0,1) , (1,1,2) ,
(2,0,1),(1,1,1),(1,1,2),(0,2,1),(1,1,1),(0,2,1),(2,0,1),(1,1,1),(2,0,0),(1,1,0),(1,1,1),(0,2,1),(1,1,0),(0,2,0).
b) The random variables X and Y are independent if and only if: P(X= x, Y
= y) = P(X = x) ~ P(Y = y) for allx¸S1,y¸S2.
if we again take a look back at the representation of our joint p.m.f. in
tabular form, you might notice that the following holds true: P(X=x,Y=y)
for allx¸S1,y¸S2. When this happens, we say that X and Y are
independent.
Similarly for X, Z, they are also independent.
c) I am not sure how to do
help please.
ToRequestContext method missing in servicestack
ToRequestContext method missing in servicestack
Using some examples I am attempting to get SS authentication working in an
asp.net MVC application. I am using this line:
authService.RequestContext =
System.Web.HttpContext.Current.ToRequestContext();
No matter what I do, I cannot find "ToRequestContext". I believe I've
added the proper using:
using ServiceStack.WebHost.Endpoints.Extensions;
Any suggestions?
Using some examples I am attempting to get SS authentication working in an
asp.net MVC application. I am using this line:
authService.RequestContext =
System.Web.HttpContext.Current.ToRequestContext();
No matter what I do, I cannot find "ToRequestContext". I believe I've
added the proper using:
using ServiceStack.WebHost.Endpoints.Extensions;
Any suggestions?
Apache https crashes when ServerName set correctly
Apache https crashes when ServerName set correctly
I have a problem with my server :/
Following environment: - Windows Server 2008 RC2 - IIS handles one website
- Apache handles two 3rd party administration tools and an SVN repo -
HTTPS in Apache - IIS without HTTPS
Now the problem: The certificate seem to be installed "correctly" because
the sites that are handled by apache can be accessed through HTTPS. But
when we try to access SVN through HTTPS we get an error from the JDK that
says "the hostname that is send through the https protocol does not match
the remote server name".
And thats correctly, because in the httpd.conf the ServerName is set to
localhost. The problem now is, if I set the ServerName to the correct
value, the site does not respond anymore. The apache errorlog does only
say "child process exited unexpectedly with exitcode 255". That it seems
like apache tries to restart the child over and over again, but everytime
it fails with that message. Also in debug mode there are not more specific
information.
Does anyone have an idea what could be the problem?
Thanks in advance
I have a problem with my server :/
Following environment: - Windows Server 2008 RC2 - IIS handles one website
- Apache handles two 3rd party administration tools and an SVN repo -
HTTPS in Apache - IIS without HTTPS
Now the problem: The certificate seem to be installed "correctly" because
the sites that are handled by apache can be accessed through HTTPS. But
when we try to access SVN through HTTPS we get an error from the JDK that
says "the hostname that is send through the https protocol does not match
the remote server name".
And thats correctly, because in the httpd.conf the ServerName is set to
localhost. The problem now is, if I set the ServerName to the correct
value, the site does not respond anymore. The apache errorlog does only
say "child process exited unexpectedly with exitcode 255". That it seems
like apache tries to restart the child over and over again, but everytime
it fails with that message. Also in debug mode there are not more specific
information.
Does anyone have an idea what could be the problem?
Thanks in advance
Single term for "elephants going berserk" english.stackexchange.com
Single term for "elephants going berserk" – english.stackexchange.com
Is there any single term for "Elephants going berserk"? Can we say that
the elephant got wild and started destroying whatever is in its path? Is
there any term for that? Hope you understand my ...
Is there any single term for "Elephants going berserk"? Can we say that
the elephant got wild and started destroying whatever is in its path? Is
there any term for that? Hope you understand my ...
Monday, 30 September 2013
How many regions do $n$ lines divide the plane into?
How many regions do $n$ lines divide the plane into?
Suppose you draw $n \ge 0$ distinct lines in the plane, one after another,
none of the lines parallel to any other and no three lines intersecting at
a common point. The plane will, as a result, be divided into how many
different regions $L_n$? Find an expression for $L_n$ in terms of
$L_{n-1}$, solve it explicitly, and indicate what is $L_{10}$.
I have tried to come up with a solution but cannot. A little guidance
would be very helpful.
Suppose you draw $n \ge 0$ distinct lines in the plane, one after another,
none of the lines parallel to any other and no three lines intersecting at
a common point. The plane will, as a result, be divided into how many
different regions $L_n$? Find an expression for $L_n$ in terms of
$L_{n-1}$, solve it explicitly, and indicate what is $L_{10}$.
I have tried to come up with a solution but cannot. A little guidance
would be very helpful.
$ - \sum=?iso-8859-1?Q?=5F{n=3D1}^\infty_\frac{?=(-1)^n}{2^n-1} =? \sum_{n=1}^\infty \frac{1}{2^n+1}$ mathoverflow.net
$ - \sum_{n=1}^\infty \frac{(-1)^n}{2^n-1} =? \sum_{n=1}^\infty
\frac{1}{2^n+1}$ – mathoverflow.net
Numerical evidence suggests: $$ - \sum_{n=1}^\infty \frac{(-1)^n}{2^n-1}
=? \sum_{n=1}^\infty \frac{1}{2^n+1} \approx 0.764499780348444 $$ Couldn't
find cancellation via rearrangement. For the ...
\frac{1}{2^n+1}$ – mathoverflow.net
Numerical evidence suggests: $$ - \sum_{n=1}^\infty \frac{(-1)^n}{2^n-1}
=? \sum_{n=1}^\infty \frac{1}{2^n+1} \approx 0.764499780348444 $$ Couldn't
find cancellation via rearrangement. For the ...
CakePHP relations with different association keys
CakePHP relations with different association keys
I have two models User and Post. But the relation here is based on
username in both tables. ie. Post.username and User.username
I am trying with following hasMany relation in user.php with cakephp 1.3
'Post' => array(
'className' => 'Post',
'dependent' => true,
'foreignKey' => 'username',
'associatedKey' => 'username'
),
But it's not creating relations between both models, when i am trying to
fetch data using.
pr( $this->User->find('all') );
Here is the output even when posts are there for user 'vinni'
Array(
[User] => Array(
id => 2
name => 'Vinay',
username => 'vinni'
[Post] => Array
(
)
)
)
I have two models User and Post. But the relation here is based on
username in both tables. ie. Post.username and User.username
I am trying with following hasMany relation in user.php with cakephp 1.3
'Post' => array(
'className' => 'Post',
'dependent' => true,
'foreignKey' => 'username',
'associatedKey' => 'username'
),
But it's not creating relations between both models, when i am trying to
fetch data using.
pr( $this->User->find('all') );
Here is the output even when posts are there for user 'vinni'
Array(
[User] => Array(
id => 2
name => 'Vinay',
username => 'vinni'
[Post] => Array
(
)
)
)
-SOLVED- Why is this echoing Resource id #5 -Resource id #6?
-SOLVED- Why is this echoing Resource id #5 -Resource id #6?
<?php
$text = mysql_query("SELECT `Text` FROM `Banner` WHERE `ID`='1'");
$user = mysql_query("SELECT `User` FROM `Banner` WHERE `ID`='1'");
echo $text . " -" . $user; ?>
It's for a announcement box.
I'm gonna make a UPDATE mysql_query to update it.
The database is set to: ID - 1 Text - Welcome to PeopleHub! User - Thomas
Doyle
<?php
$text = mysql_query("SELECT `Text` FROM `Banner` WHERE `ID`='1'");
$user = mysql_query("SELECT `User` FROM `Banner` WHERE `ID`='1'");
echo $text . " -" . $user; ?>
It's for a announcement box.
I'm gonna make a UPDATE mysql_query to update it.
The database is set to: ID - 1 Text - Welcome to PeopleHub! User - Thomas
Doyle
Sunday, 29 September 2013
Replace navigation bar cancel button with back button
Replace navigation bar cancel button with back button
I have a table view controller embedded in a navigation controller. The
table cells are all static and selecting any of them will segue to another
table view. When segue happened, the navigation bar shows 'Cancel' button
for the new view, instead of 'Back' button.
I could add a back button in code like
self.navigationItem.backBarButtonItem =
[[UIBarButtonItem alloc] initWithTitle:@"Back"
style:UIBarButtonSystemItemCancel
target:nil
action:nil];
self.navigationItem.leftBarButtonItem =
self.navigationItem.backBarButtonItem;
But then the back button would be a rectangle shape, not the default back
button shape which has an angle on the left edge. How to simply change the
cancel button to a system back button?
I have a table view controller embedded in a navigation controller. The
table cells are all static and selecting any of them will segue to another
table view. When segue happened, the navigation bar shows 'Cancel' button
for the new view, instead of 'Back' button.
I could add a back button in code like
self.navigationItem.backBarButtonItem =
[[UIBarButtonItem alloc] initWithTitle:@"Back"
style:UIBarButtonSystemItemCancel
target:nil
action:nil];
self.navigationItem.leftBarButtonItem =
self.navigationItem.backBarButtonItem;
But then the back button would be a rectangle shape, not the default back
button shape which has an angle on the left edge. How to simply change the
cancel button to a system back button?
How to pass variables values from .post response to PHP
How to pass variables values from .post response to PHP
I'm trying to run Geocode from Google Maps Api with my wp-admin plugin. I
have my own post type where is input for address of place, and jQuery code
watching for click on div. So that's my code:
Plugin Code [PHP]:
add_action( 'wp_ajax_generate_geocode', array($this, 'generate_geocode') );
[...]
//here is my test function that is waiting for response and doing something.
public function generate_geocode() {
print_r($_POST);
die();
}
AJAX Code [JS with jQuery]:
jQuery(document).ready(function() {
var lat = '';
var lng = '';
jQuery('#generate-geocode').on('click', function() {
var address = jQuery('#address').val();
// alert(address);
var geocoder = new google.maps.Geocoder();
geocoder.geocode({address: address}, function(results, status) {
//alert(status);
if (status == google.maps.GeocoderStatus.OK) {
lat = results[0].geometry.location.lat();
lng = results[0].geometry.location.lng();
alert(lat + ' ' + lng);
}
});
data = {
action: 'generate_geocode',
lat: lat,
lng: lng
};
jQuery.post(ajaxurl, data, function(response) {
alert(response);
});
});
});
My problem is that I don't know how to pass lat and lng variables or it's
values (value of results[0].geometry.location.lat() and
results[0].geometry.location.lng()) to my PHP code. So for a now I have in
my alert:
Array
(
[action] => generate_geocode
[lat] =>
[lng] =>
)
Can You tell me how to pass that values? And maybe there is better way? :)
I'm trying to run Geocode from Google Maps Api with my wp-admin plugin. I
have my own post type where is input for address of place, and jQuery code
watching for click on div. So that's my code:
Plugin Code [PHP]:
add_action( 'wp_ajax_generate_geocode', array($this, 'generate_geocode') );
[...]
//here is my test function that is waiting for response and doing something.
public function generate_geocode() {
print_r($_POST);
die();
}
AJAX Code [JS with jQuery]:
jQuery(document).ready(function() {
var lat = '';
var lng = '';
jQuery('#generate-geocode').on('click', function() {
var address = jQuery('#address').val();
// alert(address);
var geocoder = new google.maps.Geocoder();
geocoder.geocode({address: address}, function(results, status) {
//alert(status);
if (status == google.maps.GeocoderStatus.OK) {
lat = results[0].geometry.location.lat();
lng = results[0].geometry.location.lng();
alert(lat + ' ' + lng);
}
});
data = {
action: 'generate_geocode',
lat: lat,
lng: lng
};
jQuery.post(ajaxurl, data, function(response) {
alert(response);
});
});
});
My problem is that I don't know how to pass lat and lng variables or it's
values (value of results[0].geometry.location.lat() and
results[0].geometry.location.lng()) to my PHP code. So for a now I have in
my alert:
Array
(
[action] => generate_geocode
[lat] =>
[lng] =>
)
Can You tell me how to pass that values? And maybe there is better way? :)
Stacks, java,stack cannot be resolved type ,
Stacks, java,stack cannot be resolved type ,
trying to make a stack that lets the users input how many numbers gonna be
in stack first in first out , with 2 methods push and pop , push puts
element on the stack and pop removes the element on top .Attempting to
call the push method and the stack have more spaces then an exception is
thrown. Attempting to call the pop and stack is empty then even if an
exception is thrown. The question is little hard to understand but thats
because of my english
Here is my main class (Application)
package com.example.undantag.main;
import java.util.Scanner;
public class Application {
public static void main(String[] args) {
Stack2 st = new Stack2();
System.out.println("Stack "+st);
System.out.println("Please enter how many numbers you would like
to enter");
Scanner scan = new Scanner(System.in);
int totalnumber = scan.nextInt();
System.out.println("Please enter the number you would like to
begin");
int beginnumber = scan.nextInt();
showPush(st, beginnumber, totalnumber);
System.out.println("Please enter how many numbers you would like
to delete");
int deletenumber = scan.nextInt();
if(deletenumber > totalnumber){
throw new IllegalArgumentException("Invalid number");
}
else{
for(int i=0; i<=deletenumber; i++)
{
showpop(st);
}
}
}
}
This is the second class
package com.example.undantag.main;
public class Stack2 {
public static int i;
static int TotalNumber(int totalnumber){
return totalnumber;
}
static void showPush(Stack st, int a, int totalnumber){
for(int i = 0; i <=totalnumber; i++)
{
st.push(new Integer (a++));
System.out.println("Push("+a + ") ");
}
}
static void showpop(Stack st){
System.out.print("Pop: ");
Integer a = (Integer) st.pop();
System.out.println(a);
System.out.println("Stack: "+st);
}
}
trying to make a stack that lets the users input how many numbers gonna be
in stack first in first out , with 2 methods push and pop , push puts
element on the stack and pop removes the element on top .Attempting to
call the push method and the stack have more spaces then an exception is
thrown. Attempting to call the pop and stack is empty then even if an
exception is thrown. The question is little hard to understand but thats
because of my english
Here is my main class (Application)
package com.example.undantag.main;
import java.util.Scanner;
public class Application {
public static void main(String[] args) {
Stack2 st = new Stack2();
System.out.println("Stack "+st);
System.out.println("Please enter how many numbers you would like
to enter");
Scanner scan = new Scanner(System.in);
int totalnumber = scan.nextInt();
System.out.println("Please enter the number you would like to
begin");
int beginnumber = scan.nextInt();
showPush(st, beginnumber, totalnumber);
System.out.println("Please enter how many numbers you would like
to delete");
int deletenumber = scan.nextInt();
if(deletenumber > totalnumber){
throw new IllegalArgumentException("Invalid number");
}
else{
for(int i=0; i<=deletenumber; i++)
{
showpop(st);
}
}
}
}
This is the second class
package com.example.undantag.main;
public class Stack2 {
public static int i;
static int TotalNumber(int totalnumber){
return totalnumber;
}
static void showPush(Stack st, int a, int totalnumber){
for(int i = 0; i <=totalnumber; i++)
{
st.push(new Integer (a++));
System.out.println("Push("+a + ") ");
}
}
static void showpop(Stack st){
System.out.print("Pop: ");
Integer a = (Integer) st.pop();
System.out.println(a);
System.out.println("Stack: "+st);
}
}
using ajax in zend framework 1.12
using ajax in zend framework 1.12
I'm beginner in zend framework and ajax I try to do a simple code with
ajax and zend , it contain a div , text and button when the button is
pressed the value of the text is populated into the div however when I
press the button nothing is happened :S here is my codes please help me
this is the layout
/index/test.phtml
<script
src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"
type="text/javascript"></script>
<!--for display text and submit fields i use viewHelpers it's very
comfortable and easy way.-->
<div class="submit_area">
<?php echo $this->formText('message', 'empty', array('size' => 32, 'id'
=> 'message')) ?>
<?php echo $this->formSubmit('submitTo', 'submit', array('id' =>
'submitTo')) ?>
<div class="show-msg"></div>
<script >
//for send data i'll use jquery library
$(document).ready(
function(){
<?php echo "ready" ?>
//By clicking on button submit condition makes validate on empty
message
//unless field message will be not empty , the programm make send
data to
//controller via ajax
$("#submitTo").click(function() {
var message = $('#message').val();
if (message != '') {
//run ajax
$.post('index/ajax',
{'message' : message},
//callback function
function (respond) {
//put respond in class show-msg
$(".show-msg").html(respond);
}
);
}
});
});
--------------------------------------------
and this is the code in controller
class IndexController extends Zend_Controller_Action
{
public function init()
{
/* Initialize action controller here */
}
public function checkAction()
{
// action body
$request = $this->getRequest()->getPost();
//referring to the index
//gets value from ajax request
$message = $request['message'];
// makes disable renderer
$this->_helper->viewRenderer->setNoRender();
//makes disable layout
$this->_helper->getHelper('layout')->disableLayout();
//return callback message to the function javascript
echo $message;
}
public function testAction()
{
// action body
}
}
I'm beginner in zend framework and ajax I try to do a simple code with
ajax and zend , it contain a div , text and button when the button is
pressed the value of the text is populated into the div however when I
press the button nothing is happened :S here is my codes please help me
this is the layout
/index/test.phtml
<script
src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"
type="text/javascript"></script>
<!--for display text and submit fields i use viewHelpers it's very
comfortable and easy way.-->
<div class="submit_area">
<?php echo $this->formText('message', 'empty', array('size' => 32, 'id'
=> 'message')) ?>
<?php echo $this->formSubmit('submitTo', 'submit', array('id' =>
'submitTo')) ?>
<div class="show-msg"></div>
<script >
//for send data i'll use jquery library
$(document).ready(
function(){
<?php echo "ready" ?>
//By clicking on button submit condition makes validate on empty
message
//unless field message will be not empty , the programm make send
data to
//controller via ajax
$("#submitTo").click(function() {
var message = $('#message').val();
if (message != '') {
//run ajax
$.post('index/ajax',
{'message' : message},
//callback function
function (respond) {
//put respond in class show-msg
$(".show-msg").html(respond);
}
);
}
});
});
--------------------------------------------
and this is the code in controller
class IndexController extends Zend_Controller_Action
{
public function init()
{
/* Initialize action controller here */
}
public function checkAction()
{
// action body
$request = $this->getRequest()->getPost();
//referring to the index
//gets value from ajax request
$message = $request['message'];
// makes disable renderer
$this->_helper->viewRenderer->setNoRender();
//makes disable layout
$this->_helper->getHelper('layout')->disableLayout();
//return callback message to the function javascript
echo $message;
}
public function testAction()
{
// action body
}
}
Saturday, 28 September 2013
Finding the derivative of a quadratic function at a particular point
Finding the derivative of a quadratic function at a particular point
The question states:
Suppose $f(x)=-5x^2+x-3$.
Find $f'(-1)$.
So I worked out the problem as follows:
\begin{align*} f'(-1)&=\lim_{h\to 0}\frac{-5(h^2+1)+h-13}{h} \\
&=\frac{-5h^2+h-18}{h} \\
&=\frac{h^2\left(-5+\frac{h}{h^2}-\frac{18}{h^2}\right)}{h^2\left(\frac{h}{h^2}\right)}
\end{align*} In which the third step I assume I am doing it wrong because
I believe factoring out only works if I have an expression in the
denominator instead of just the variable $h$.
Would anyone mind telling me where I am going wrong in this problem?
The question states:
Suppose $f(x)=-5x^2+x-3$.
Find $f'(-1)$.
So I worked out the problem as follows:
\begin{align*} f'(-1)&=\lim_{h\to 0}\frac{-5(h^2+1)+h-13}{h} \\
&=\frac{-5h^2+h-18}{h} \\
&=\frac{h^2\left(-5+\frac{h}{h^2}-\frac{18}{h^2}\right)}{h^2\left(\frac{h}{h^2}\right)}
\end{align*} In which the third step I assume I am doing it wrong because
I believe factoring out only works if I have an expression in the
denominator instead of just the variable $h$.
Would anyone mind telling me where I am going wrong in this problem?
Widget preview image size
Widget preview image size
I need to set a preview image for my widget and I used emulator to create
one. The problem is I don't know if 1 image is OK for all resolutions. The
emulator was a xhdpi one. Should I use each emulator variant(hdpi, mdpi,
...) to generate a preview for all resolutions(xhdpi, hdpi and mdpi) or
this one is enough?
I need to set a preview image for my widget and I used emulator to create
one. The problem is I don't know if 1 image is OK for all resolutions. The
emulator was a xhdpi one. Should I use each emulator variant(hdpi, mdpi,
...) to generate a preview for all resolutions(xhdpi, hdpi and mdpi) or
this one is enough?
Eclipse LogCat error. What's the point?
Eclipse LogCat error. What's the point?
When I try to open the Activity, I have an error.
In that Activity I collect the names, photos and contact numbers, and set
them in a ListView.
java.lang.RuntimeException: Unable to start activity
ComponentInfo{com.amber/com.alice.ContactsActivity}:
java.lang.ArrayIndexOutOfBoundsException: length=5; index=5 at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2071)
at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2096)
at android.app.ActivityThread.access$600(ActivityThread.java:138) at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1207) at
android.os.Handler.dispatchMessage(Handler.java:99) at
android.os.Looper.loop(Looper.java:213) at
android.app.ActivityThread.main(ActivityThread.java:4787) at
java.lang.reflect.Method.invokeNative(Native Method) at
java.lang.reflect.Method.invoke(Method.java:511) at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556) at
dalvik.system.NativeStart.main(Native Method) Caused by:
java.lang.ArrayIndexOutOfBoundsException: length=5; index=5 at
com.alice.Classes.Contact.Add(Contact.java:20) at
com.alice.ContactsActivity.onCreate(ContactsActivity.java:137) at
android.app.Activity.performCreate(Activity.java:5008) at
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2035)
... 11 more
When I try to open the Activity, I have an error.
In that Activity I collect the names, photos and contact numbers, and set
them in a ListView.
java.lang.RuntimeException: Unable to start activity
ComponentInfo{com.amber/com.alice.ContactsActivity}:
java.lang.ArrayIndexOutOfBoundsException: length=5; index=5 at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2071)
at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2096)
at android.app.ActivityThread.access$600(ActivityThread.java:138) at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1207) at
android.os.Handler.dispatchMessage(Handler.java:99) at
android.os.Looper.loop(Looper.java:213) at
android.app.ActivityThread.main(ActivityThread.java:4787) at
java.lang.reflect.Method.invokeNative(Native Method) at
java.lang.reflect.Method.invoke(Method.java:511) at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556) at
dalvik.system.NativeStart.main(Native Method) Caused by:
java.lang.ArrayIndexOutOfBoundsException: length=5; index=5 at
com.alice.Classes.Contact.Add(Contact.java:20) at
com.alice.ContactsActivity.onCreate(ContactsActivity.java:137) at
android.app.Activity.performCreate(Activity.java:5008) at
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2035)
... 11 more
how can i change the arrow cursor image to hand image for my web page
how can i change the arrow cursor image to hand image for my web page
I want to change the image of my cursor,instead of it I want the hand
image ,when I will take the cursor on the side bar menu than cursor image
should be hand.
I want to change the image of my cursor,instead of it I want the hand
image ,when I will take the cursor on the side bar menu than cursor image
should be hand.
Friday, 27 September 2013
akaike criterion: ar() vs arima() in R
akaike criterion: ar() vs arima() in R
I've ve got drastic difference between AIC for ar(1) and arima(1,0,0):
a<-ar(rn, lags=1)
a$aic 0 1 2 3 4 5 6 7 ...
6.0215169 1.2184962 2.0020937 1.1786418 0.9002231 0.0000000 1.1728207 ...
b<-arima(rn, order=c(1,0,0)) b$aic [1] -6840.676
The regression coeff are rather close though: -0.068 for ar and -0.077 for
arima. Will greatly appreciate any comments. Alec
I've ve got drastic difference between AIC for ar(1) and arima(1,0,0):
a<-ar(rn, lags=1)
a$aic 0 1 2 3 4 5 6 7 ...
6.0215169 1.2184962 2.0020937 1.1786418 0.9002231 0.0000000 1.1728207 ...
b<-arima(rn, order=c(1,0,0)) b$aic [1] -6840.676
The regression coeff are rather close though: -0.068 for ar and -0.077 for
arima. Will greatly appreciate any comments. Alec
Asynchronous iteratee processing in Scalaz
Asynchronous iteratee processing in Scalaz
I've been using Scalaz 7 iteratees to process a large (i.e., unbounded)
stream of data in constant heap space. Now I'd like to perform the
processing in parallel, working on P chunks of data at a time. I still
have to limit heap space, but it's reasonable to assume that there's
enough heap to store P chunks of data and the accumulated results of the
computation.
In code, it looks something like this:
type ErrorOrT[M[+_], A] = EitherT[M, Throwable, A]
type ErrorOr[A] = ErrorOrT[IO, A]
def processChunk(c: Chunk): Result
def process(data: EnumeratorT[Chunk, ErrorOr]): IterateeT[Chunk, ErrorOr,
List[Result]] =
Iteratee.foldM[Chunk, ErrorOr, List[Result]](Nil) { (rs, c) =>
processChunk(c) :: rs
} &= data
I'm aware of the Task class and thought of mapping over the enumerator to
create a stream of tasks:
data map (c => Task.delay(processChunk(c)))
But I'm still not sure how to manage the non-determinism. While consuming
the stream, how do I ensure that P tasks are running whenever possible?
I've been using Scalaz 7 iteratees to process a large (i.e., unbounded)
stream of data in constant heap space. Now I'd like to perform the
processing in parallel, working on P chunks of data at a time. I still
have to limit heap space, but it's reasonable to assume that there's
enough heap to store P chunks of data and the accumulated results of the
computation.
In code, it looks something like this:
type ErrorOrT[M[+_], A] = EitherT[M, Throwable, A]
type ErrorOr[A] = ErrorOrT[IO, A]
def processChunk(c: Chunk): Result
def process(data: EnumeratorT[Chunk, ErrorOr]): IterateeT[Chunk, ErrorOr,
List[Result]] =
Iteratee.foldM[Chunk, ErrorOr, List[Result]](Nil) { (rs, c) =>
processChunk(c) :: rs
} &= data
I'm aware of the Task class and thought of mapping over the enumerator to
create a stream of tasks:
data map (c => Task.delay(processChunk(c)))
But I'm still not sure how to manage the non-determinism. While consuming
the stream, how do I ensure that P tasks are running whenever possible?
how to resume the timer from where it was paused using jquery
how to resume the timer from where it was paused using jquery
My app looks like this image(http://i.stack.imgur.com/0sqzi.png) , i am
having this code http://jsfiddle.net/XYevE/1/ ,but this code has one
problem,
Problem is when i press PAUSE btn & after few seconds again if i press the
play button then then timer is starting from the beginning . The timer
should continue from the current pause time,if user clicks play button
followed by pause button.
Please help me for this, i am trying to solve this issue since last 2
days. But still its not solved as per my app requirement.
My app looks like this image(http://i.stack.imgur.com/0sqzi.png) , i am
having this code http://jsfiddle.net/XYevE/1/ ,but this code has one
problem,
Problem is when i press PAUSE btn & after few seconds again if i press the
play button then then timer is starting from the beginning . The timer
should continue from the current pause time,if user clicks play button
followed by pause button.
Please help me for this, i am trying to solve this issue since last 2
days. But still its not solved as per my app requirement.
error on passing from controller to views in codeigniter?
error on passing from controller to views in codeigniter?
i want to passing data from model to controller then to view this code
explain it.
the model
public function get_all_college_name() {
$q = $this -> db -> query('select * from college');
if ($q -> num_rows() > 0) {
foreach ($q->result() as $row) {
$data[] = $row;
}
return $data;
}
}
the controller code
public function index() {
$this -> load -> model('retriver_data');
$data['rows'] = $this -> retriver_data -> get_all_college_name();
$this -> load -> view('home', $data);
//$this -> view_something('home', $data);
}
the view code
<body>
<?php
foreach ($rows as $r) {
echo $r -> name;
}
?>
</body>
the error appears
A PHP Error was encountered
Severity: Warning
Message: Invalid argument supplied for foreach()
Filename: views/home.php
Line Number: 8
i want to passing data from model to controller then to view this code
explain it.
the model
public function get_all_college_name() {
$q = $this -> db -> query('select * from college');
if ($q -> num_rows() > 0) {
foreach ($q->result() as $row) {
$data[] = $row;
}
return $data;
}
}
the controller code
public function index() {
$this -> load -> model('retriver_data');
$data['rows'] = $this -> retriver_data -> get_all_college_name();
$this -> load -> view('home', $data);
//$this -> view_something('home', $data);
}
the view code
<body>
<?php
foreach ($rows as $r) {
echo $r -> name;
}
?>
</body>
the error appears
A PHP Error was encountered
Severity: Warning
Message: Invalid argument supplied for foreach()
Filename: views/home.php
Line Number: 8
Jquery animation on hover
Jquery animation on hover
I'm very new to jquery and I've been trying to achieve something like this
http://jsfiddle.net/rniestroj/nZhbg/ but it doesn't seem to be working on
my code. I don't understand if i have the jquery part wrong?
Here is what i have:
In the code, the second part of the jquary with img0...etc is the fade in
and out of my header.
index.php
<html>
<head>
<link rel="stylesheet" href="css/style2.css" type="text/css">
</head>
<body>
<!-- JQuery script for fade in and fade out of the whole page-->
<script>
$(".circle1").hover(
function(){
$(".circle1info").animate({left: '+=1000',bottom: '+=1000'}, 1750);
},
function(){
$(".circle1info").animate({left: '-=1000',bottom: '-=1000'}, 1750);
});
$( "#img0" ).delay(1000).fadeIn(3000, function() {
$( "#img1" ).fadeIn(3000, function() {
$( "#img2" ).fadeIn(3000, function() {
$( "#img3" ).fadeIn(3000, function() {
$( "#img4" ).fadeIn(3000, function() {
$( "#rightpanel" ).fadeIn(500, function() {
$( "#leftpanel" ).fadeIn(500, function() {
});
});
});
});
});
});
return false;
});
</script>
<img class="smdmascot" src="/images/fade/samplemd_mascot.png"><br>
<img class="circle4" src="/images/fade/circle4.png"><br>
<img class="circle3" src="/images/fade/circle3.png"><br>
<img class="circle2" src="/images/fade/circle2.png"><br>
<img class="circle1" src="/images/fade/circle1.png"><br>
<img class="circle1info" src="/images/fade/coupon_slider.png">
</body>
</html>
css: (i took some of the img0...etc stuff out so its easier to look at)
a:link { color: #FFFFFF; }
a:visited { color: #FFFFFF; }
a:hover { color: #000000; }
a:active { color: #FFFFFF; }
.maindiv {
position: absolute;
}
.circle1 {
position: absolute;
z-index: 5;
left: 545px;
top: 715px;
}
.circle1info {
position: absolute;
z-index: -5;
left: 545px;
top: 715px;
}
.circle2 {
position: absolute;
z-index: 4;
left: 579px;
top: 600px;
}
.circle3 {
position: absolute;
z-index: 3;
left: 597px;
top: 515px;
}
.circle4 {
position: absolute;
z-index: 2;
left: 618px;
top: 450px;
}
.smdmascot {
position: absolute;
z-index: 1;
left: 580px;
top: 320px;
}
</style>
I greatly appreciate any help.
I'm very new to jquery and I've been trying to achieve something like this
http://jsfiddle.net/rniestroj/nZhbg/ but it doesn't seem to be working on
my code. I don't understand if i have the jquery part wrong?
Here is what i have:
In the code, the second part of the jquary with img0...etc is the fade in
and out of my header.
index.php
<html>
<head>
<link rel="stylesheet" href="css/style2.css" type="text/css">
</head>
<body>
<!-- JQuery script for fade in and fade out of the whole page-->
<script>
$(".circle1").hover(
function(){
$(".circle1info").animate({left: '+=1000',bottom: '+=1000'}, 1750);
},
function(){
$(".circle1info").animate({left: '-=1000',bottom: '-=1000'}, 1750);
});
$( "#img0" ).delay(1000).fadeIn(3000, function() {
$( "#img1" ).fadeIn(3000, function() {
$( "#img2" ).fadeIn(3000, function() {
$( "#img3" ).fadeIn(3000, function() {
$( "#img4" ).fadeIn(3000, function() {
$( "#rightpanel" ).fadeIn(500, function() {
$( "#leftpanel" ).fadeIn(500, function() {
});
});
});
});
});
});
return false;
});
</script>
<img class="smdmascot" src="/images/fade/samplemd_mascot.png"><br>
<img class="circle4" src="/images/fade/circle4.png"><br>
<img class="circle3" src="/images/fade/circle3.png"><br>
<img class="circle2" src="/images/fade/circle2.png"><br>
<img class="circle1" src="/images/fade/circle1.png"><br>
<img class="circle1info" src="/images/fade/coupon_slider.png">
</body>
</html>
css: (i took some of the img0...etc stuff out so its easier to look at)
a:link { color: #FFFFFF; }
a:visited { color: #FFFFFF; }
a:hover { color: #000000; }
a:active { color: #FFFFFF; }
.maindiv {
position: absolute;
}
.circle1 {
position: absolute;
z-index: 5;
left: 545px;
top: 715px;
}
.circle1info {
position: absolute;
z-index: -5;
left: 545px;
top: 715px;
}
.circle2 {
position: absolute;
z-index: 4;
left: 579px;
top: 600px;
}
.circle3 {
position: absolute;
z-index: 3;
left: 597px;
top: 515px;
}
.circle4 {
position: absolute;
z-index: 2;
left: 618px;
top: 450px;
}
.smdmascot {
position: absolute;
z-index: 1;
left: 580px;
top: 320px;
}
</style>
I greatly appreciate any help.
update database from textbox
update database from textbox
Hi Guys Im trying to update my database this is my probleme: i have first
page with gridview showing my table with checkbox i select an arrow then i
click update this button keep the the id of the row in SessionID and
transfert me to the second page with all row infos i selected in
textboxs(in load page ) i change a textbox value then i click on second
button to update the database using the sessionID the probleme is that the
textboxs keep the old values ty guys and sorry for my bad english
Hi Guys Im trying to update my database this is my probleme: i have first
page with gridview showing my table with checkbox i select an arrow then i
click update this button keep the the id of the row in SessionID and
transfert me to the second page with all row infos i selected in
textboxs(in load page ) i change a textbox value then i click on second
button to update the database using the sessionID the probleme is that the
textboxs keep the old values ty guys and sorry for my bad english
Thursday, 26 September 2013
how to add double/triple spaces between words in a string in java?
how to add double/triple spaces between words in a string in java?
I have a string which has single space between words. There will be almost
30 words. I need the single space to be replaced with two/three spaces.
How can I do that using replaceAll() ?
I have a string which has single space between words. There will be almost
30 words. I need the single space to be replaced with two/three spaces.
How can I do that using replaceAll() ?
Thursday, 19 September 2013
How to add an element into a multiMap?
How to add an element into a multiMap?
I'm using a multimap to sort my words by length. The integer is the word's
length. I was wondering how I can add words to the List.
Map<Integer, List<String>> mmap = new HashMap<Integer, List<String>>();
Say I have two words, "bob" and "can" they are both 3 letters. Could
someone give me a little pointer on how I would do this?
I'm using a multimap to sort my words by length. The integer is the word's
length. I was wondering how I can add words to the List.
Map<Integer, List<String>> mmap = new HashMap<Integer, List<String>>();
Say I have two words, "bob" and "can" they are both 3 letters. Could
someone give me a little pointer on how I would do this?
Scroll Height of System.Windows.Controls.WebBrowser
Scroll Height of System.Windows.Controls.WebBrowser
I am using the System.Windows.Controls.WebBrowser control, and I need to
get the height of the rendered html document.
The only height value I've found is WebBrowser.Document.body.offsetheight.
However, this is the same value as the control's height.
I know the height of the page must be stored someplace since the scroll
bar knows the value.
Everything I find in my searching has been about the
Windows.Forms.WebBrowser.
I am using the System.Windows.Controls.WebBrowser control, and I need to
get the height of the rendered html document.
The only height value I've found is WebBrowser.Document.body.offsetheight.
However, this is the same value as the control's height.
I know the height of the page must be stored someplace since the scroll
bar knows the value.
Everything I find in my searching has been about the
Windows.Forms.WebBrowser.
drupal 7 content views
drupal 7 content views
I am building a user customizable game site in Drupal 7. I have done this
before using php/mysql but just learning drupal. I need to set this up so
an authenticated user can upload 2-8 prize images ,set odds for each prize
as an integer value, and select an animation template that will be used. I
have set up content types for game, prize, and animation template. Here is
the basic table structure needed:
game table gameId int auto userId int templateId int numberOfPrizes int
prizes table prizeId gameId int auto prizeImage image prizeOdds int
game Template(Animation) table templateId int auto filename string
How do I set this up so a user can upload images and set correclating odds
to each prize(image). Then on the play game page I will need to load
images based on gameId and roll the dice once to determine the prize
won(should be a winner every time)data based on gameId. There is a lot of
custom HTML5/Javascript in use for the game. I currently have a test game
play page set up that does everything except show the prize images and
know the winning prize: http://qrgames.co/animation-lobsters
All input is appreciated. BW
I am building a user customizable game site in Drupal 7. I have done this
before using php/mysql but just learning drupal. I need to set this up so
an authenticated user can upload 2-8 prize images ,set odds for each prize
as an integer value, and select an animation template that will be used. I
have set up content types for game, prize, and animation template. Here is
the basic table structure needed:
game table gameId int auto userId int templateId int numberOfPrizes int
prizes table prizeId gameId int auto prizeImage image prizeOdds int
game Template(Animation) table templateId int auto filename string
How do I set this up so a user can upload images and set correclating odds
to each prize(image). Then on the play game page I will need to load
images based on gameId and roll the dice once to determine the prize
won(should be a winner every time)data based on gameId. There is a lot of
custom HTML5/Javascript in use for the game. I currently have a test game
play page set up that does everything except show the prize images and
know the winning prize: http://qrgames.co/animation-lobsters
All input is appreciated. BW
No data load my outputText of Primefaces?
No data load my outputText of Primefaces?
I have a question I have a DataTable, where I have a button in a column
edit, capture the Id of the record, and make a list that record to load
the data in the object system, peroHola, I have a question I have a
DataTable, where I have a button in a column edit, capture the Id of the
record, and make a list that record to load the data in the object system,
but my text box value is charging.
<p:dataTable id="dataTable" var="sis" value="#{listSistMB.system}"
paginator="true" rows="10" rowIndexVar="rowIndex"
selection="#{listSistMB.system}"
paginatorTemplate="{CurrentPageReport} {FirstPageLink}
{PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink}
{RowsPerPageDropdown}"
rowsPerPageTemplate="5,10,15">
<p:column>
<f:facet name="header">
<h:outputText value="Status" />
</f:facet>
<p:selectBooleanButton value="#{sis.stStatus}" onLabel="A"
offLabel="I" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Edit" />
</f:facet>
<p:commandButton id="selectEdit" action="#{listSistMB.editSystem}"
icon="ui-icon-search" title="Editar System">
<f:param name="codCode" value="#{sis.cdCode}"/>
</p:commandButton>
</p:column>
</p:dataTable>
In the controller I headed this way the system object.
@Component("listSistMB")
@Scope("view")
public class MantenanceSystemController implements Serializable{
private System system = new System();
public String editSystem(){
try {
String cdCode =
(String)FacesContext.getCurrentInstance().getExternalContext().
getRequestParameterMap().get("codCode");
system = confSistemaService.buscarPorId(Long.valueOf(cdCode));
} catch (Exception e) {
e.printStackTrace();
}
return "register-system";
}
It's not charging me the value of the text box.
<p:inputText value="#{listSistMB.system.nbNomCorto}" />
I have a question I have a DataTable, where I have a button in a column
edit, capture the Id of the record, and make a list that record to load
the data in the object system, peroHola, I have a question I have a
DataTable, where I have a button in a column edit, capture the Id of the
record, and make a list that record to load the data in the object system,
but my text box value is charging.
<p:dataTable id="dataTable" var="sis" value="#{listSistMB.system}"
paginator="true" rows="10" rowIndexVar="rowIndex"
selection="#{listSistMB.system}"
paginatorTemplate="{CurrentPageReport} {FirstPageLink}
{PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink}
{RowsPerPageDropdown}"
rowsPerPageTemplate="5,10,15">
<p:column>
<f:facet name="header">
<h:outputText value="Status" />
</f:facet>
<p:selectBooleanButton value="#{sis.stStatus}" onLabel="A"
offLabel="I" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Edit" />
</f:facet>
<p:commandButton id="selectEdit" action="#{listSistMB.editSystem}"
icon="ui-icon-search" title="Editar System">
<f:param name="codCode" value="#{sis.cdCode}"/>
</p:commandButton>
</p:column>
</p:dataTable>
In the controller I headed this way the system object.
@Component("listSistMB")
@Scope("view")
public class MantenanceSystemController implements Serializable{
private System system = new System();
public String editSystem(){
try {
String cdCode =
(String)FacesContext.getCurrentInstance().getExternalContext().
getRequestParameterMap().get("codCode");
system = confSistemaService.buscarPorId(Long.valueOf(cdCode));
} catch (Exception e) {
e.printStackTrace();
}
return "register-system";
}
It's not charging me the value of the text box.
<p:inputText value="#{listSistMB.system.nbNomCorto}" />
MongoDb: Using as a graph database for finding "friends" of "friends" for example?
MongoDb: Using as a graph database for finding "friends" of "friends" for
example?
I have been investigating a graph database and I have found neo4j and
although this seems ideal I have also come across mongodb.
Mongodb is not an official graph database but I wondered if it could be
used for my scenerio ?
I writing an application where users can have friends and those friends
can have friends etc... The typical social part of a social network.
I was wondering in my situation can mongodb suffice ?
How easy would it be to implement or do I really need to focus on REAL
graph db's.?
I do notice foursquare are using mongodb so I presume it supports there
infrastructure.
But how easy would it be to find all friends of my friends that also have
friends in commun - for example
Any help really appreciated here.
example?
I have been investigating a graph database and I have found neo4j and
although this seems ideal I have also come across mongodb.
Mongodb is not an official graph database but I wondered if it could be
used for my scenerio ?
I writing an application where users can have friends and those friends
can have friends etc... The typical social part of a social network.
I was wondering in my situation can mongodb suffice ?
How easy would it be to implement or do I really need to focus on REAL
graph db's.?
I do notice foursquare are using mongodb so I presume it supports there
infrastructure.
But how easy would it be to find all friends of my friends that also have
friends in commun - for example
Any help really appreciated here.
How to use downloaded JSON object stored in NSArray?
How to use downloaded JSON object stored in NSArray?
I am using SZJsonParser to download JSON object from a site. Here's my code:
#import <Foundation/Foundation.h>
#import "SZJsonParser.h"
int main(int argc, const char * argv[])
{
@autoreleasepool
{
// insert code here...
NSURL *url = [[NSURL alloc]
initWithString:@"http://mymovieapi.com/?title=Cars"];
NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url];
NSData *data = [NSURLConnection sendSynchronousRequest:request
returningResponse:nil error:nil];
NSString *str = [[NSString alloc] initWithData:data
encoding:NSUTF8StringEncoding];
NSArray *arr = [str jsonObject];
for (int i = 0; i < [arr count]; i ++)
{
NSLog(@"%@",[arr objectAtIndex:i]);
}
}
return 0;
}
When I run the Terminal app, here's the output:
2013-09-19 15:54:49.957 SimpleJSONTerminal[24160:303] {
actors = (
"Owen Wilson",
"Paul Newman",
"Bonnie Hunt",
"Larry the Cable Guy",
"Cheech Marin",
"Tony Shalhoub",
"Guido Quaroni",
"Jenifer Lewis",
"Paul Dooley",
"Michael Wallis",
"George Carlin",
"Katherine Helmond",
"John Ratzenberger",
"Joe Ranft",
"Michael Keaton"
);
"also_known_as" = (
"Cars - Quatre roues"
);
country = (
USA
);
directors = (
"John Lasseter",
"Joe Ranft"
);
genres = (
Animation,
Adventure,
Comedy,
Family,
Sport
);
"imdb_id" = tt0317219;
"imdb_url" = "http://www.imdb.com/title/tt0317219/";
language = (
English,
Italian,
Japanese,
Yiddish
);
"plot_simple" = "A hot-shot race-car named Lightning McQueen gets
waylaid in Radiator Springs, where he finds the true meaning of
friendship and family.";
poster = {
cover =
"http://imdb-poster.b0.upaiyun.com/000/317/219.jpg!cover?_upt=65f114a91379629498";
imdb =
"http://ia.media-imdb.com/images/M/MV5BMTE5Mzk5MTA2Ml5BMl5BanBnXkFtZTYwNTY3NTc2._V1_SY317_CR0,0,214,317_.jpg";
};
rating = "7.3";
"rating_count" = 150431;
"release_date" = 20060822;
runtime = (
"117 min"
);
title = "Cars - Quatre roues\n \"Cars\"";
type = VG;
writers = (
"John Lasseter",
"Joe Ranft"
);
year = 2006;
}
How do I store this in an NSDictionary so that I can use the "title" as a
Key and then get the information ?
Thanks
I am using SZJsonParser to download JSON object from a site. Here's my code:
#import <Foundation/Foundation.h>
#import "SZJsonParser.h"
int main(int argc, const char * argv[])
{
@autoreleasepool
{
// insert code here...
NSURL *url = [[NSURL alloc]
initWithString:@"http://mymovieapi.com/?title=Cars"];
NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url];
NSData *data = [NSURLConnection sendSynchronousRequest:request
returningResponse:nil error:nil];
NSString *str = [[NSString alloc] initWithData:data
encoding:NSUTF8StringEncoding];
NSArray *arr = [str jsonObject];
for (int i = 0; i < [arr count]; i ++)
{
NSLog(@"%@",[arr objectAtIndex:i]);
}
}
return 0;
}
When I run the Terminal app, here's the output:
2013-09-19 15:54:49.957 SimpleJSONTerminal[24160:303] {
actors = (
"Owen Wilson",
"Paul Newman",
"Bonnie Hunt",
"Larry the Cable Guy",
"Cheech Marin",
"Tony Shalhoub",
"Guido Quaroni",
"Jenifer Lewis",
"Paul Dooley",
"Michael Wallis",
"George Carlin",
"Katherine Helmond",
"John Ratzenberger",
"Joe Ranft",
"Michael Keaton"
);
"also_known_as" = (
"Cars - Quatre roues"
);
country = (
USA
);
directors = (
"John Lasseter",
"Joe Ranft"
);
genres = (
Animation,
Adventure,
Comedy,
Family,
Sport
);
"imdb_id" = tt0317219;
"imdb_url" = "http://www.imdb.com/title/tt0317219/";
language = (
English,
Italian,
Japanese,
Yiddish
);
"plot_simple" = "A hot-shot race-car named Lightning McQueen gets
waylaid in Radiator Springs, where he finds the true meaning of
friendship and family.";
poster = {
cover =
"http://imdb-poster.b0.upaiyun.com/000/317/219.jpg!cover?_upt=65f114a91379629498";
imdb =
"http://ia.media-imdb.com/images/M/MV5BMTE5Mzk5MTA2Ml5BMl5BanBnXkFtZTYwNTY3NTc2._V1_SY317_CR0,0,214,317_.jpg";
};
rating = "7.3";
"rating_count" = 150431;
"release_date" = 20060822;
runtime = (
"117 min"
);
title = "Cars - Quatre roues\n \"Cars\"";
type = VG;
writers = (
"John Lasseter",
"Joe Ranft"
);
year = 2006;
}
How do I store this in an NSDictionary so that I can use the "title" as a
Key and then get the information ?
Thanks
jQuery add "close & open" container to split list
jQuery add "close & open" container to split list
im trying to split a list via jQuery. I need some fix, because else the
navigation would crash my theme.
Heres my code, i already tried several things like append, after,
insertAfter. The problem is that jquery always adds the closing and reopen
tag in the right order - i need it the other way:
<ul>
<li>link here</li>
<li>link here</li>
<li>link here</li>
<li>link here</li>
</ul>
this is what i want:
<ul>
<li>link here</li>
<li>link here</li>
</ul><ul>
<li>link here</li>
<li>link here</li>
</ul>
this is my code so far:
var thirdLevelNavigation = $('ul.sub-menu').clone();
var countItems = 0;
thirdLevelNavigation.children('li').each(function() {
if(countItems == 5) {
// heres the trouble-maker
$('</ul><ul class="sub-menu">').insertAfter(this);
countItems = 0;
}
countItems++;
});
thirdLevelNavigation.appendTo('.menu-main-container');
(its a sub-nav tweak for multi dimensional wordpress navigations)
TIA!
im trying to split a list via jQuery. I need some fix, because else the
navigation would crash my theme.
Heres my code, i already tried several things like append, after,
insertAfter. The problem is that jquery always adds the closing and reopen
tag in the right order - i need it the other way:
<ul>
<li>link here</li>
<li>link here</li>
<li>link here</li>
<li>link here</li>
</ul>
this is what i want:
<ul>
<li>link here</li>
<li>link here</li>
</ul><ul>
<li>link here</li>
<li>link here</li>
</ul>
this is my code so far:
var thirdLevelNavigation = $('ul.sub-menu').clone();
var countItems = 0;
thirdLevelNavigation.children('li').each(function() {
if(countItems == 5) {
// heres the trouble-maker
$('</ul><ul class="sub-menu">').insertAfter(this);
countItems = 0;
}
countItems++;
});
thirdLevelNavigation.appendTo('.menu-main-container');
(its a sub-nav tweak for multi dimensional wordpress navigations)
TIA!
Wednesday, 18 September 2013
Unable to insert Dynamics CRM record via SOAP request for datatype "Money"
Unable to insert Dynamics CRM record via SOAP request for datatype "Money"
I am trying to send an XML SOAP request(given below) to my Microsoft
Dynamics crm . However its throwing me error. I realized that it goes
through if I avoid
<b:KeyValuePairOfstringanyType> <c:key>new_grantprojecttotalcost</c:key>
<c:value i:type='a:Money'><b:Value>1234.00</b:Value></c:value>
</b:KeyValuePairOfstringanyType><b:KeyValuePairOfstringanyType>
<c:key>new_grantprojectfundingrequired</c:key> <c:value
i:type='a:Money'><b:Value>123.00</b:Value></c:value>
</b:KeyValuePairOfstringanyType>
which is of datatype Money.
The complete request looks like this
<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope"
xmlns:a="http://www.w3.org/2005/08/addressing"
xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<s:Header>
<a:Action s:mustUnderstand="1">
http://schemas.microsoft.com/xrm/2011/Contracts/Services/IOrganizationService/Create</a:Action>
<a:MessageID>
urn:uuid:6511f419-3d6d-446f-852e-ffd1169d1d14</a:MessageID>
<a:ReplyTo>
<a:Address>
http://www.w3.org/2005/08/addressing/anonymous</a:Address>
</a:ReplyTo>
<VsDebuggerCausalityData
xmlns="http://schemas.microsoft.com/vstudio/diagnostics/servicemodelsink">
uIDPozJEz+P/wJdOhoN2XNauvYcAAAAAK0Y6fOjvMEqbgs9ivCmFPaZlxcAnCJ1GiX+Rpi09nSYACQAA</VsDebuggerCausalityData>
<a:To s:mustUnderstand="1">
https://scy.crm4.dynamics.com/XRMServices/2011/Organization.svc</a:To>
<o:Security s:mustUnderstand="1"
xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<u:Timestamp u:Id="_0">
<u:Created>2013-09-19T05:27:01.35Z</u:Created>
<u:Expires>2013-09-19T05:32:01.35Z</u:Expires>
</u:Timestamp>
<EncryptedData Id="Assertion0"
Type="http://www.w3.org/2001/04/xmlenc#Element"
xmlns="http://www.w3.org/2001/04/xmlenc#">
<EncryptionMethod
Algorithm="http://www.w3.org/2001/04/xmlenc#tripledes-cbc">
</EncryptionMethod>
<ds:KeyInfo
xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
<EncryptedKey>
<EncryptionMethod
Algorithm="http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p">
</EncryptionMethod>
<ds:KeyInfo Id="keyinfo">
<wsse:SecurityTokenReference
xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:KeyIdentifier
EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary"
ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509SubjectKeyIdentifier">
</wsse:KeyIdentifier>
</wsse:SecurityTokenReference>
</ds:KeyInfo>
<CipherData>
<CipherValue>
</CipherValue>
</CipherData>
</EncryptedKey>
</ds:KeyInfo>
<CipherData>
<CipherValue>
</CipherValue>
</CipherData>
</EncryptedData>
</o:Security>
</s:Header>
<s:Body>
<Create
xmlns='http://schemas.microsoft.com/xrm/2011/Contracts/Services'>
<entity xmlns:b='http://schemas.microsoft.com/xrm/2011/Contracts'
xmlns:i='http://www.w3.org/2001/XMLSchema-instance'>
<b:Attributes
xmlns:c='http://schemas.datacontract.org/2004/07/System.Collections.Generic'><b:KeyValuePairOfstringanyType>
<c:key>scy_name</c:key>
<c:value i:type='d:string'
xmlns:d='http://www.w3.org/2001/XMLSchema'>Business Grant
Programme Application</c:value>
</b:KeyValuePairOfstringanyType><b:KeyValuePairOfstringanyType>
<c:key>new_fullname</c:key>
<c:value i:type='d:string'
xmlns:d='http://www.w3.org/2001/XMLSchema'>Aboo Tafadar4</c:value>
</b:KeyValuePairOfstringanyType><b:KeyValuePairOfstringanyType>
<c:key>new_jobtitle</c:key>
<c:value i:type='d:string'
xmlns:d='http://www.w3.org/2001/XMLSchema'>Iquara</c:value>
</b:KeyValuePairOfstringanyType><b:KeyValuePairOfstringanyType>
<c:key>scy_accountname</c:key>
<c:value i:type='d:string'
xmlns:d='http://www.w3.org/2001/XMLSchema'>Iquara</c:value>
</b:KeyValuePairOfstringanyType><b:KeyValuePairOfstringanyType>
<c:key>scy_emailaddress</c:key>
<c:value i:type='d:string'
xmlns:d='http://www.w3.org/2001/XMLSchema'>soyeed2004@gmail.com</c:value>
</b:KeyValuePairOfstringanyType><b:KeyValuePairOfstringanyType>
<c:key>scy_contactphone</c:key>
<c:value i:type='d:string'
xmlns:d='http://www.w3.org/2001/XMLSchema'>913642225808</c:value>
</b:KeyValuePairOfstringanyType><b:KeyValuePairOfstringanyType>
<c:key>scy_addressline1</c:key>
<c:value i:type='d:string'
xmlns:d='http://www.w3.org/2001/XMLSchema'>Bivar Road</c:value>
</b:KeyValuePairOfstringanyType><b:KeyValuePairOfstringanyType>
<c:key>scy_addressline2</c:key>
<c:value i:type='d:string'
xmlns:d='http://www.w3.org/2001/XMLSchema'>aaaa</c:value>
</b:KeyValuePairOfstringanyType><b:KeyValuePairOfstringanyType>
<c:key>scy_addressline3</c:key>
<c:value i:type='d:string'
xmlns:d='http://www.w3.org/2001/XMLSchema'>Iquara Ltd,
Catalyst</c:value>
</b:KeyValuePairOfstringanyType><b:KeyValuePairOfstringanyType>
<c:key>scy_city</c:key>
<c:value i:type='d:string'
xmlns:d='http://www.w3.org/2001/XMLSchema'>York</c:value>
</b:KeyValuePairOfstringanyType><b:KeyValuePairOfstringanyType>
<c:key>scy_postcode</c:key>
<c:value i:type='d:string'
xmlns:d='http://www.w3.org/2001/XMLSchema'>yo103jy</c:value>
</b:KeyValuePairOfstringanyType><b:KeyValuePairOfstringanyType>
<c:key>new_registeredaddress1</c:key>
<c:value i:type='d:string'
xmlns:d='http://www.w3.org/2001/XMLSchema'>Iquara Ltd,
Catalyst</c:value>
</b:KeyValuePairOfstringanyType><b:KeyValuePairOfstringanyType>
<c:key>new_registeredaddress2</c:key>
<c:value i:type='d:string'
xmlns:d='http://www.w3.org/2001/XMLSchema'>University of
York</c:value>
</b:KeyValuePairOfstringanyType><b:KeyValuePairOfstringanyType>
<c:key>new_registeredaddress3</c:key>
<c:value i:type='d:string'
xmlns:d='http://www.w3.org/2001/XMLSchema'>Iquara Ltd,
Catalyst</c:value>
</b:KeyValuePairOfstringanyType><b:KeyValuePairOfstringanyType>
<c:key>new_registeredcity</c:key>
<c:value i:type='d:string'
xmlns:d='http://www.w3.org/2001/XMLSchema'>York</c:value>
</b:KeyValuePairOfstringanyType><b:KeyValuePairOfstringanyType>
<c:key>new_registeredpostcode</c:key>
<c:value i:type='d:string'
xmlns:d='http://www.w3.org/2001/XMLSchema'>yo103jy</c:value>
</b:KeyValuePairOfstringanyType><b:KeyValuePairOfstringanyType>
<c:key>scy_websiteurl</c:key>
<c:value i:type='d:string'
xmlns:d='http://www.w3.org/2001/XMLSchema'>iquara</c:value>
</b:KeyValuePairOfstringanyType><b:KeyValuePairOfstringanyType>
<c:key>scy_companynumber</c:key>
<c:value i:type='d:string'
xmlns:d='http://www.w3.org/2001/XMLSchema'>1787686</c:value>
</b:KeyValuePairOfstringanyType><b:KeyValuePairOfstringanyType>
<c:key>new_yearstartedtrading</c:key>
<c:value i:type='d:string'
xmlns:d='http://www.w3.org/2001/XMLSchema'>1980</c:value>
</b:KeyValuePairOfstringanyType><b:KeyValuePairOfstringanyType>
<c:key>scy_description</c:key>
<c:value i:type='d:string'
xmlns:d='http://www.w3.org/2001/XMLSchema'>hghghjg</c:value>
</b:KeyValuePairOfstringanyType><b:KeyValuePairOfstringanyType>
<c:key>new_grantprojectdescription</c:key>
<c:value i:type='d:string'
xmlns:d='http://www.w3.org/2001/XMLSchema'>khkkjh</c:value>
</b:KeyValuePairOfstringanyType><b:KeyValuePairOfstringanyType>
<c:key>new_grantprojecttotalcost</c:key>
<c:value i:type='a:Money'><b:Value>1234.00</b:Value></c:value>
</b:KeyValuePairOfstringanyType><b:KeyValuePairOfstringanyType>
<c:key>new_grantprojectfundingrequired</c:key>
<c:value i:type='a:Money'><b:Value>123.00</b:Value></c:value>
</b:KeyValuePairOfstringanyType><b:KeyValuePairOfstringanyType>
<c:key>scy_leadsource</c:key>
<c:value
i:type='b:OptionSetValue'><b:Value>798110007</b:Value></c:value>
</b:KeyValuePairOfstringanyType><b:KeyValuePairOfstringanyType>
<c:key>new_sendmarketinginfo</c:key>
<c:value
i:type='b:OptionSetValue'><b:Value>100000001</b:Value></c:value>
</b:KeyValuePairOfstringanyType><b:KeyValuePairOfstringanyType>
<c:key>new_grantprojecteligibility</c:key>
<c:value
i:type='b:OptionSetValue'><b:Value>100000000</b:Value></c:value>
</b:KeyValuePairOfstringanyType></b:Attributes>
<b:EntityState i:nil='true'/>
<b:FormattedValues
xmlns:c='http://schemas.datacontract.org/2004/07/System.Collections.Generic'/>
<b:Id>00000000-0000-0000-0000-000000000000</b:Id>
<b:LogicalName>scy_webformrecord</b:LogicalName>
<b:RelatedEntities
xmlns:c='http://schemas.datacontract.org/2004/07/System.Collections.Generic'/>
</entity>
</Create>
</s:Body>
</s:Envelope>
I am trying to send an XML SOAP request(given below) to my Microsoft
Dynamics crm . However its throwing me error. I realized that it goes
through if I avoid
<b:KeyValuePairOfstringanyType> <c:key>new_grantprojecttotalcost</c:key>
<c:value i:type='a:Money'><b:Value>1234.00</b:Value></c:value>
</b:KeyValuePairOfstringanyType><b:KeyValuePairOfstringanyType>
<c:key>new_grantprojectfundingrequired</c:key> <c:value
i:type='a:Money'><b:Value>123.00</b:Value></c:value>
</b:KeyValuePairOfstringanyType>
which is of datatype Money.
The complete request looks like this
<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope"
xmlns:a="http://www.w3.org/2005/08/addressing"
xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<s:Header>
<a:Action s:mustUnderstand="1">
http://schemas.microsoft.com/xrm/2011/Contracts/Services/IOrganizationService/Create</a:Action>
<a:MessageID>
urn:uuid:6511f419-3d6d-446f-852e-ffd1169d1d14</a:MessageID>
<a:ReplyTo>
<a:Address>
http://www.w3.org/2005/08/addressing/anonymous</a:Address>
</a:ReplyTo>
<VsDebuggerCausalityData
xmlns="http://schemas.microsoft.com/vstudio/diagnostics/servicemodelsink">
uIDPozJEz+P/wJdOhoN2XNauvYcAAAAAK0Y6fOjvMEqbgs9ivCmFPaZlxcAnCJ1GiX+Rpi09nSYACQAA</VsDebuggerCausalityData>
<a:To s:mustUnderstand="1">
https://scy.crm4.dynamics.com/XRMServices/2011/Organization.svc</a:To>
<o:Security s:mustUnderstand="1"
xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<u:Timestamp u:Id="_0">
<u:Created>2013-09-19T05:27:01.35Z</u:Created>
<u:Expires>2013-09-19T05:32:01.35Z</u:Expires>
</u:Timestamp>
<EncryptedData Id="Assertion0"
Type="http://www.w3.org/2001/04/xmlenc#Element"
xmlns="http://www.w3.org/2001/04/xmlenc#">
<EncryptionMethod
Algorithm="http://www.w3.org/2001/04/xmlenc#tripledes-cbc">
</EncryptionMethod>
<ds:KeyInfo
xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
<EncryptedKey>
<EncryptionMethod
Algorithm="http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p">
</EncryptionMethod>
<ds:KeyInfo Id="keyinfo">
<wsse:SecurityTokenReference
xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:KeyIdentifier
EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary"
ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509SubjectKeyIdentifier">
</wsse:KeyIdentifier>
</wsse:SecurityTokenReference>
</ds:KeyInfo>
<CipherData>
<CipherValue>
</CipherValue>
</CipherData>
</EncryptedKey>
</ds:KeyInfo>
<CipherData>
<CipherValue>
</CipherValue>
</CipherData>
</EncryptedData>
</o:Security>
</s:Header>
<s:Body>
<Create
xmlns='http://schemas.microsoft.com/xrm/2011/Contracts/Services'>
<entity xmlns:b='http://schemas.microsoft.com/xrm/2011/Contracts'
xmlns:i='http://www.w3.org/2001/XMLSchema-instance'>
<b:Attributes
xmlns:c='http://schemas.datacontract.org/2004/07/System.Collections.Generic'><b:KeyValuePairOfstringanyType>
<c:key>scy_name</c:key>
<c:value i:type='d:string'
xmlns:d='http://www.w3.org/2001/XMLSchema'>Business Grant
Programme Application</c:value>
</b:KeyValuePairOfstringanyType><b:KeyValuePairOfstringanyType>
<c:key>new_fullname</c:key>
<c:value i:type='d:string'
xmlns:d='http://www.w3.org/2001/XMLSchema'>Aboo Tafadar4</c:value>
</b:KeyValuePairOfstringanyType><b:KeyValuePairOfstringanyType>
<c:key>new_jobtitle</c:key>
<c:value i:type='d:string'
xmlns:d='http://www.w3.org/2001/XMLSchema'>Iquara</c:value>
</b:KeyValuePairOfstringanyType><b:KeyValuePairOfstringanyType>
<c:key>scy_accountname</c:key>
<c:value i:type='d:string'
xmlns:d='http://www.w3.org/2001/XMLSchema'>Iquara</c:value>
</b:KeyValuePairOfstringanyType><b:KeyValuePairOfstringanyType>
<c:key>scy_emailaddress</c:key>
<c:value i:type='d:string'
xmlns:d='http://www.w3.org/2001/XMLSchema'>soyeed2004@gmail.com</c:value>
</b:KeyValuePairOfstringanyType><b:KeyValuePairOfstringanyType>
<c:key>scy_contactphone</c:key>
<c:value i:type='d:string'
xmlns:d='http://www.w3.org/2001/XMLSchema'>913642225808</c:value>
</b:KeyValuePairOfstringanyType><b:KeyValuePairOfstringanyType>
<c:key>scy_addressline1</c:key>
<c:value i:type='d:string'
xmlns:d='http://www.w3.org/2001/XMLSchema'>Bivar Road</c:value>
</b:KeyValuePairOfstringanyType><b:KeyValuePairOfstringanyType>
<c:key>scy_addressline2</c:key>
<c:value i:type='d:string'
xmlns:d='http://www.w3.org/2001/XMLSchema'>aaaa</c:value>
</b:KeyValuePairOfstringanyType><b:KeyValuePairOfstringanyType>
<c:key>scy_addressline3</c:key>
<c:value i:type='d:string'
xmlns:d='http://www.w3.org/2001/XMLSchema'>Iquara Ltd,
Catalyst</c:value>
</b:KeyValuePairOfstringanyType><b:KeyValuePairOfstringanyType>
<c:key>scy_city</c:key>
<c:value i:type='d:string'
xmlns:d='http://www.w3.org/2001/XMLSchema'>York</c:value>
</b:KeyValuePairOfstringanyType><b:KeyValuePairOfstringanyType>
<c:key>scy_postcode</c:key>
<c:value i:type='d:string'
xmlns:d='http://www.w3.org/2001/XMLSchema'>yo103jy</c:value>
</b:KeyValuePairOfstringanyType><b:KeyValuePairOfstringanyType>
<c:key>new_registeredaddress1</c:key>
<c:value i:type='d:string'
xmlns:d='http://www.w3.org/2001/XMLSchema'>Iquara Ltd,
Catalyst</c:value>
</b:KeyValuePairOfstringanyType><b:KeyValuePairOfstringanyType>
<c:key>new_registeredaddress2</c:key>
<c:value i:type='d:string'
xmlns:d='http://www.w3.org/2001/XMLSchema'>University of
York</c:value>
</b:KeyValuePairOfstringanyType><b:KeyValuePairOfstringanyType>
<c:key>new_registeredaddress3</c:key>
<c:value i:type='d:string'
xmlns:d='http://www.w3.org/2001/XMLSchema'>Iquara Ltd,
Catalyst</c:value>
</b:KeyValuePairOfstringanyType><b:KeyValuePairOfstringanyType>
<c:key>new_registeredcity</c:key>
<c:value i:type='d:string'
xmlns:d='http://www.w3.org/2001/XMLSchema'>York</c:value>
</b:KeyValuePairOfstringanyType><b:KeyValuePairOfstringanyType>
<c:key>new_registeredpostcode</c:key>
<c:value i:type='d:string'
xmlns:d='http://www.w3.org/2001/XMLSchema'>yo103jy</c:value>
</b:KeyValuePairOfstringanyType><b:KeyValuePairOfstringanyType>
<c:key>scy_websiteurl</c:key>
<c:value i:type='d:string'
xmlns:d='http://www.w3.org/2001/XMLSchema'>iquara</c:value>
</b:KeyValuePairOfstringanyType><b:KeyValuePairOfstringanyType>
<c:key>scy_companynumber</c:key>
<c:value i:type='d:string'
xmlns:d='http://www.w3.org/2001/XMLSchema'>1787686</c:value>
</b:KeyValuePairOfstringanyType><b:KeyValuePairOfstringanyType>
<c:key>new_yearstartedtrading</c:key>
<c:value i:type='d:string'
xmlns:d='http://www.w3.org/2001/XMLSchema'>1980</c:value>
</b:KeyValuePairOfstringanyType><b:KeyValuePairOfstringanyType>
<c:key>scy_description</c:key>
<c:value i:type='d:string'
xmlns:d='http://www.w3.org/2001/XMLSchema'>hghghjg</c:value>
</b:KeyValuePairOfstringanyType><b:KeyValuePairOfstringanyType>
<c:key>new_grantprojectdescription</c:key>
<c:value i:type='d:string'
xmlns:d='http://www.w3.org/2001/XMLSchema'>khkkjh</c:value>
</b:KeyValuePairOfstringanyType><b:KeyValuePairOfstringanyType>
<c:key>new_grantprojecttotalcost</c:key>
<c:value i:type='a:Money'><b:Value>1234.00</b:Value></c:value>
</b:KeyValuePairOfstringanyType><b:KeyValuePairOfstringanyType>
<c:key>new_grantprojectfundingrequired</c:key>
<c:value i:type='a:Money'><b:Value>123.00</b:Value></c:value>
</b:KeyValuePairOfstringanyType><b:KeyValuePairOfstringanyType>
<c:key>scy_leadsource</c:key>
<c:value
i:type='b:OptionSetValue'><b:Value>798110007</b:Value></c:value>
</b:KeyValuePairOfstringanyType><b:KeyValuePairOfstringanyType>
<c:key>new_sendmarketinginfo</c:key>
<c:value
i:type='b:OptionSetValue'><b:Value>100000001</b:Value></c:value>
</b:KeyValuePairOfstringanyType><b:KeyValuePairOfstringanyType>
<c:key>new_grantprojecteligibility</c:key>
<c:value
i:type='b:OptionSetValue'><b:Value>100000000</b:Value></c:value>
</b:KeyValuePairOfstringanyType></b:Attributes>
<b:EntityState i:nil='true'/>
<b:FormattedValues
xmlns:c='http://schemas.datacontract.org/2004/07/System.Collections.Generic'/>
<b:Id>00000000-0000-0000-0000-000000000000</b:Id>
<b:LogicalName>scy_webformrecord</b:LogicalName>
<b:RelatedEntities
xmlns:c='http://schemas.datacontract.org/2004/07/System.Collections.Generic'/>
</entity>
</Create>
</s:Body>
</s:Envelope>
Why does this recursive function not print done twice?
Why does this recursive function not print done twice?
I'm still trying to understand recursion and what I expected the code to
print and what actually printed is different.
so here's the code which is just based off a simple example I found on
youtube,
def count(n):
if n > 0:
print "Count 1", ", ", n
count(n - 1)
print "Count 2", ", ", n
else:
print "Done"
count(1)
and this is what it prints,
Count 1 , 1
Done
Count 2 , 1
What I expected was
Count 1 , 1
Done
Done
My understanding (which of course is wrong) is that count(1) (for the
outer count function) will be called and because 1 is greater than 0 will
print 1, then count(1 - 1) (inner count function) will call count(0)
(outer count function) and since 0 is not greater than 1 this will print
Done. Then I thought the return from count(1 - 1) (inner count function)
would also return Done and since there were no other n values entered into
the inner count() that would be it. I'm not understanding how done prints
once and 1 prints twice???
I'm still trying to understand recursion and what I expected the code to
print and what actually printed is different.
so here's the code which is just based off a simple example I found on
youtube,
def count(n):
if n > 0:
print "Count 1", ", ", n
count(n - 1)
print "Count 2", ", ", n
else:
print "Done"
count(1)
and this is what it prints,
Count 1 , 1
Done
Count 2 , 1
What I expected was
Count 1 , 1
Done
Done
My understanding (which of course is wrong) is that count(1) (for the
outer count function) will be called and because 1 is greater than 0 will
print 1, then count(1 - 1) (inner count function) will call count(0)
(outer count function) and since 0 is not greater than 1 this will print
Done. Then I thought the return from count(1 - 1) (inner count function)
would also return Done and since there were no other n values entered into
the inner count() that would be it. I'm not understanding how done prints
once and 1 prints twice???
Changing ADUC Account expiration date via command saves wrong date
Changing ADUC Account expiration date via command saves wrong date
I am trying to make a simple batch file to change a user's ADUC expiration
to a specified date.
Using the below command the date always appears in ADUC as one day prior
to what I set:
net user myname /expires:09/17/13 /domain
In ADUC, the date will be: 09/16/2013. No matter what, the date that
appears in ADUC is one day before the day I set.
The documentation I found for this indicates
Note that the account expires at the beginning of the specified date.
So does this mean, If i wanted the account to be expired today, I would
send the command for today and ADUC would interpret that as yesterday?
Thanks in advance, I just want to get this right.
I am trying to make a simple batch file to change a user's ADUC expiration
to a specified date.
Using the below command the date always appears in ADUC as one day prior
to what I set:
net user myname /expires:09/17/13 /domain
In ADUC, the date will be: 09/16/2013. No matter what, the date that
appears in ADUC is one day before the day I set.
The documentation I found for this indicates
Note that the account expires at the beginning of the specified date.
So does this mean, If i wanted the account to be expired today, I would
send the command for today and ADUC would interpret that as yesterday?
Thanks in advance, I just want to get this right.
Can I avoid duplicated css with Zurb Foundation 4?
Can I avoid duplicated css with Zurb Foundation 4?
Im using ZF4 and I recently noted how big my css files are. On one page in
particular I have 10 lines of sass, that uses the grid mixins, so I
"optimized" my imports, and got to this
@import "settings";
@import "foundation/components/global"; // *always required
@import "foundation/components/grid";
.tag-list-filter {
@include grid-row('nest-collapse');
.sub-nav {
@include grid-column(6);
margin: 0;
}
.date-in-filter {
@include grid-column(4,true);
label {
display: inline;
}
input[type="text"] {
display: inline;
width: 50%;
}
}
The two imports gives me an overhead of 700 lines of CSS!!!. And Im more
than glad to add those 700 lines in my app.css, given that I have lots of
pages that uses the grid system, but why should I have that much
duplicated css in all my pages?
Is there a way I can avoid that?
Im using ZF4 and I recently noted how big my css files are. On one page in
particular I have 10 lines of sass, that uses the grid mixins, so I
"optimized" my imports, and got to this
@import "settings";
@import "foundation/components/global"; // *always required
@import "foundation/components/grid";
.tag-list-filter {
@include grid-row('nest-collapse');
.sub-nav {
@include grid-column(6);
margin: 0;
}
.date-in-filter {
@include grid-column(4,true);
label {
display: inline;
}
input[type="text"] {
display: inline;
width: 50%;
}
}
The two imports gives me an overhead of 700 lines of CSS!!!. And Im more
than glad to add those 700 lines in my app.css, given that I have lots of
pages that uses the grid system, but why should I have that much
duplicated css in all my pages?
Is there a way I can avoid that?
binding image in windows phone 8
binding image in windows phone 8
Can i bind image to xaml without needing to use image source (the
predominant method) which it is (In xaml page):
<Image Height="170" Width="220" Source="{Binding Source=Img}" ></Image>
because i have image converted from byte array and doesn't have any name
or source. like here:
Image Img = new Image();
Img=ByteArraytoBitmap(ob0[0].Img.ToArray());
public BitmapImage ByteArraytoBitmap(Byte[] byteArray)
{
MemoryStream stream = new MemoryStream(byteArray);
BitmapImage bitmapImage = new BitmapImage();
bitmapImage.SetSource(stream);
return bitmapImage;
}
Can i bind image to xaml without needing to use image source (the
predominant method) which it is (In xaml page):
<Image Height="170" Width="220" Source="{Binding Source=Img}" ></Image>
because i have image converted from byte array and doesn't have any name
or source. like here:
Image Img = new Image();
Img=ByteArraytoBitmap(ob0[0].Img.ToArray());
public BitmapImage ByteArraytoBitmap(Byte[] byteArray)
{
MemoryStream stream = new MemoryStream(byteArray);
BitmapImage bitmapImage = new BitmapImage();
bitmapImage.SetSource(stream);
return bitmapImage;
}
jquery mobile refresh issue
jquery mobile refresh issue
basically what i'm trying to do is to make a list items in a unorderedlist
tag.
<ul data-role="listview" id="places" data-inset="true">
</ul>
now each list item got a info and a picture - which is in a javascript file.
var listOfPlaces = [
{ place: "paris", visited: "no", pic: "1.jpg"},
{ place: "london", visited: "yes", pic: "2.jpg"}];
localStorage.setItem("placesList", JSON.stringify(listOfPlaces));
now what im trying to do is that by using a for loop i want to create a
item inside the list of the places with a value "yes" for the visited key.
but not only this, i also want to make the option that when pressed on the
list item, than a large pic will shown in a popup.
so what i've done is the this code -
<script>
var dataPlace = localStorage.getItem("placesList"); var placesInfo =
JSON.parse(dataPlace);
$(function () {
placelist();
$("#places ul").listview('refresh');
})
function placelist() {
var i = 0;
for (i = 0; i < placesInfo .length ; i++) {
if (placesInfo[i].visited == "yes") {
$("#places ul").append('
Place's name: ' + placesInfo [i].model + "
');
$("#poUp").append('<div data-role="popup" id="pic' + i +
'"data-overlay-theme="a" data-theme="d"
data-corners="false"><a href="#" data-rel="back"
data-role="button" data-theme="a" data-icon="delete"
data-iconpos="notext" class="ui-btn-right"> Close</a><img
class="photo" style="max-height:512px;" src="pics/' +
placesInfo[i].pic + '"/></a> </div>');
now from what i have tried this code "static" - i have put it in the body
of the html and it worked fine - but when im using it this way im getting
the list - and underneath it i see all the pics with a close kind of link
text next to it.
im guessing that the problem is because i need to use a code like the
listview('refresh'), that i have for the list item, the things is that i
am not sure how to use the refresh method with other elements.
so if anyone could help and explain what im doing wrong, and how can i
solve it, thank you for any kind of help
basically what i'm trying to do is to make a list items in a unorderedlist
tag.
<ul data-role="listview" id="places" data-inset="true">
</ul>
now each list item got a info and a picture - which is in a javascript file.
var listOfPlaces = [
{ place: "paris", visited: "no", pic: "1.jpg"},
{ place: "london", visited: "yes", pic: "2.jpg"}];
localStorage.setItem("placesList", JSON.stringify(listOfPlaces));
now what im trying to do is that by using a for loop i want to create a
item inside the list of the places with a value "yes" for the visited key.
but not only this, i also want to make the option that when pressed on the
list item, than a large pic will shown in a popup.
so what i've done is the this code -
<script>
var dataPlace = localStorage.getItem("placesList"); var placesInfo =
JSON.parse(dataPlace);
$(function () {
placelist();
$("#places ul").listview('refresh');
})
function placelist() {
var i = 0;
for (i = 0; i < placesInfo .length ; i++) {
if (placesInfo[i].visited == "yes") {
$("#places ul").append('
Place's name: ' + placesInfo [i].model + "
');
$("#poUp").append('<div data-role="popup" id="pic' + i +
'"data-overlay-theme="a" data-theme="d"
data-corners="false"><a href="#" data-rel="back"
data-role="button" data-theme="a" data-icon="delete"
data-iconpos="notext" class="ui-btn-right"> Close</a><img
class="photo" style="max-height:512px;" src="pics/' +
placesInfo[i].pic + '"/></a> </div>');
now from what i have tried this code "static" - i have put it in the body
of the html and it worked fine - but when im using it this way im getting
the list - and underneath it i see all the pics with a close kind of link
text next to it.
im guessing that the problem is because i need to use a code like the
listview('refresh'), that i have for the list item, the things is that i
am not sure how to use the refresh method with other elements.
so if anyone could help and explain what im doing wrong, and how can i
solve it, thank you for any kind of help
How can I change the shape of a gridview to circular?
How can I change the shape of a gridview to circular?
How can I change the square shape of a GridView to circular or is it
possible to display a gridview on a circular object or say an image?
I have tried to :-
1-add cssclass to the gridview where css class had a line of code for a
background image
2-applied headerclass css to the gridview and gave the image source there.
3-applied a backimage property to the Grid.
(the image in all the 3 cases was a circle)
css is
.circle{ background:url(circle.png);
opacity:0.5;height:176px;width:176px;}
and i m trying to insert the GridView in my aspx page in visual studio 10
But nothing seems to work the way i want . The GridView Cells were
misaligned in first 2 cases.
Please suggest me a right way if possible.
Thanks in advance
How can I change the square shape of a GridView to circular or is it
possible to display a gridview on a circular object or say an image?
I have tried to :-
1-add cssclass to the gridview where css class had a line of code for a
background image
2-applied headerclass css to the gridview and gave the image source there.
3-applied a backimage property to the Grid.
(the image in all the 3 cases was a circle)
css is
.circle{ background:url(circle.png);
opacity:0.5;height:176px;width:176px;}
and i m trying to insert the GridView in my aspx page in visual studio 10
But nothing seems to work the way i want . The GridView Cells were
misaligned in first 2 cases.
Please suggest me a right way if possible.
Thanks in advance
How to create in View new row after each next row
How to create in View new row after each next row
Is here some way how to create new row after each row in View ? Row should
have same count of columns and their names and I would like to use
conditions to fill them.
Example:
row A : 120 2122 bike 20130203 --- row from table from dbs row B : 120
4444 012 0 ---new row
Is it possible?(by procedure or somehow else?)
Is here some way how to create new row after each row in View ? Row should
have same count of columns and their names and I would like to use
conditions to fill them.
Example:
row A : 120 2122 bike 20130203 --- row from table from dbs row B : 120
4444 012 0 ---new row
Is it possible?(by procedure or somehow else?)
Tuesday, 17 September 2013
Haskell: use Maybe but print an actual number rather than "Just ... "
Haskell: use Maybe but print an actual number rather than "Just ... "
So here is my program. I want to implement a maximum function on my own
for an assignment. The problem is that to me it seems weird to print the
number with the word "Just" in front of it... How would I fix this to
print just a number?
mymax :: Ord a=>[a]->Maybe a
mymax [] = Nothing
mymax [x] = Just x
mymax (x:y:xs) = if x < y then mymax(y:xs) else mymax(x:xs)
So here is my program. I want to implement a maximum function on my own
for an assignment. The problem is that to me it seems weird to print the
number with the word "Just" in front of it... How would I fix this to
print just a number?
mymax :: Ord a=>[a]->Maybe a
mymax [] = Nothing
mymax [x] = Just x
mymax (x:y:xs) = if x < y then mymax(y:xs) else mymax(x:xs)
retrieve random content from a string indexed associative array PHP
retrieve random content from a string indexed associative array PHP
I am trying to retrieve a random array from a string indexed associative
array. The code is as follows and I keep encountering errors:
$suite['heart']=1;
$suite['heart']=2;
$suite['heart']=3;
$suite['heart']=4;
$suite['heart']=5;
$rand = array_rand($suite);
$card1 = $suite[$rand];
print $card1;
My results have been static and continuously displaying number 5, I want
it to display any of the random numbers.
Thank you in advance!
I am trying to retrieve a random array from a string indexed associative
array. The code is as follows and I keep encountering errors:
$suite['heart']=1;
$suite['heart']=2;
$suite['heart']=3;
$suite['heart']=4;
$suite['heart']=5;
$rand = array_rand($suite);
$card1 = $suite[$rand];
print $card1;
My results have been static and continuously displaying number 5, I want
it to display any of the random numbers.
Thank you in advance!
R get objects' names from the list of objects
R get objects' names from the list of objects
I try to get an object's name from the list containing this object. I
searched through similar questions and find some suggestions about using
the deparse(substitute(object)) formula:
> my.list <- list(model.product, model.i, model.add)
> lapply(my.list, function(model) deparse(substitute(model)))
and the result is:
[[1]]
[1] "X[[1L]]"
[[2]]
[1] "X[[2L]]"
[[3]]
[1] "X[[3L]]"
whereas I want to obtain:
[1] "model.product", "model.i", "model.add"
Thank you in advance for being of some help!
I try to get an object's name from the list containing this object. I
searched through similar questions and find some suggestions about using
the deparse(substitute(object)) formula:
> my.list <- list(model.product, model.i, model.add)
> lapply(my.list, function(model) deparse(substitute(model)))
and the result is:
[[1]]
[1] "X[[1L]]"
[[2]]
[1] "X[[2L]]"
[[3]]
[1] "X[[3L]]"
whereas I want to obtain:
[1] "model.product", "model.i", "model.add"
Thank you in advance for being of some help!
How to refactor an AJAX process in Yii
How to refactor an AJAX process in Yii
I need a help in refactoring, or in design :). I did my webapp, it works
well. But I still can't understand well the Ajax process in the Yii. For
example, when I use the $.fn.yiiGridView.update() method, I saw this
return by the all webpage and not just with the content of CGridView. It
was interesting for me.
But now: at the index view, I use a CGridView, but without pager! This is
a simple bet game webapp. And at the index.php I view only 10 bet/result
on the page, and after 10 seconds I view the next 10 bet/result and again
the next 10 result/bet after 10 seconds :), with JavaScript.
The simple process like this:
actionIndex() is called, it renders the index.php (the index.php contains
the JS codes the design, but not the CGridView, where the webapp views the
results)
index.php rendert the _ajaxIndex.php files content.
The JS code calculate the next 10 result, which will have to view on the
webpage.
actionAjaxIndex() is called. This give therefresh content of
_ajaxIndex.php repeat from the 3. again.
The JS code calculate again the next 10 resut...
Notice: While the admins insert the results at the admin webpage, the
webapp has to show the temporary results. This is why I need to refresh
the summary and the round JS variables in the _ajaxIndex.php
Controller
/**
* Lists all models.
*/
public function actionIndex() {
Yii::app()->language='hu';
$model = new Result('search');
$model->unsetAttributes();
if (isset($_GET['Result']))
$model->attributes = $_GET['Result'];
if (isset($_POST['offset']) && $_POST['offset'] >= 0)
$model->offset = $_POST['offset'];
$summary = Result::getCountSavedResults();
$model->isLimited = true;
$this->layout='projector';
$this->render('index', array('model' => $model, 'summary'=>$summary));
//$this->actionAjaxIndex();
}
/**
* List all models by Ajax request.
*/
public function actionAjaxIndex() {
Yii::app()->language='hu';
$model = new Result('search');
$model->unsetAttributes(); // clear any default values
if (isset($_GET['Result']))
$model->attributes = $_GET['Result'];
if (isset($_POST['offset']) && $_POST['offset'] >= 0)
$model->offset = $_POST['offset'];
$summary = Result::getCountSavedResults();
$model->isLimited = true;
$this->renderPartial('_ajaxIndex', array('model' => $model,
'summary'=>$summary));
}
I would like to terminate this code repeat in the actionIndex(). But I
don't have any idea how I can do... I tried to call actionAjaxIndex etc.
But before I can call the actionAjaxIndex I got PHP errors from Yii.
(Summary variable is not exist, etc.)
View - Index.php
<!--<h1><?php echo Yii::t('strings','Results'); ?></h1>-->
<?php
echo CHtml::image(Yii::app()->request->baseUrl.'/images/toplista.jpg',
"Fogadás");
?>
<script type="text/javascript">
// Initialize the variables for calculating
var summary = <?php echo $summary ?>; // get all stored results
var timeout = 10 * 1000; // in Milliseconds -> multiply with 1000 to
use seconds
var current = 0;
var turn = 0;
var rounds = Math.floor(summary / 10);
</script>
<?php $this->renderPartial('_ajaxIndex', array('model'=>$model,
'summary'=>$summary)); ?>
<script type="text/javascript">
// Refresh the CGridView's content in _ajaxIndex.php
window.setInterval("refresh()", timeout);
// Get the offset to the search() to set the criteria
// Increase turn.
function counter(){
turn += 1;
if(turn > rounds){
turn = 0;
}
return turn *10;
}
function refresh() {
<?php
echo CHtml::ajax(array(
'url'=> CController::createUrl("result/ajaxIndex"),
'type'=>'post',
'data'=> array('offset'=>'js: counter()'),
'replace'=> '#ajax-result-grid',
))
?>
}
</script>
View - _ajaxIndex.php
<?php
/* @var $model Result */
?>
<?php $this->widget('zii.widgets.grid.CGridView', array(
'id'=>'ajax-result-grid',
'dataProvider'=>$model->search(),
'columns'=>array(
array(
'header'=>Yii::t('strings','No.'),
'value'=> $model->offset.' + $row+1',
'htmlOptions'=>array('style'=>'width:50px;'),
),
array(
'header'=>Yii::t('strings','team_name'),
'name'=>'team_id',
'value'=>'$data->team->name'
),
array(
'header'=>Yii::t('strings','value'),
'name'=>'value',
'value'=>'$data->value'
),
),
)); ?>
<script type="text/javascript">
// This is need while the admins insert the results during this page
is run.
summary = <?php echo $summary ?>;
rounds = Math.floor(summary / 10);
</script>
Yes, I think I don't understand clearly the Ajax process in the Yii :/.
I need a help in refactoring, or in design :). I did my webapp, it works
well. But I still can't understand well the Ajax process in the Yii. For
example, when I use the $.fn.yiiGridView.update() method, I saw this
return by the all webpage and not just with the content of CGridView. It
was interesting for me.
But now: at the index view, I use a CGridView, but without pager! This is
a simple bet game webapp. And at the index.php I view only 10 bet/result
on the page, and after 10 seconds I view the next 10 bet/result and again
the next 10 result/bet after 10 seconds :), with JavaScript.
The simple process like this:
actionIndex() is called, it renders the index.php (the index.php contains
the JS codes the design, but not the CGridView, where the webapp views the
results)
index.php rendert the _ajaxIndex.php files content.
The JS code calculate the next 10 result, which will have to view on the
webpage.
actionAjaxIndex() is called. This give therefresh content of
_ajaxIndex.php repeat from the 3. again.
The JS code calculate again the next 10 resut...
Notice: While the admins insert the results at the admin webpage, the
webapp has to show the temporary results. This is why I need to refresh
the summary and the round JS variables in the _ajaxIndex.php
Controller
/**
* Lists all models.
*/
public function actionIndex() {
Yii::app()->language='hu';
$model = new Result('search');
$model->unsetAttributes();
if (isset($_GET['Result']))
$model->attributes = $_GET['Result'];
if (isset($_POST['offset']) && $_POST['offset'] >= 0)
$model->offset = $_POST['offset'];
$summary = Result::getCountSavedResults();
$model->isLimited = true;
$this->layout='projector';
$this->render('index', array('model' => $model, 'summary'=>$summary));
//$this->actionAjaxIndex();
}
/**
* List all models by Ajax request.
*/
public function actionAjaxIndex() {
Yii::app()->language='hu';
$model = new Result('search');
$model->unsetAttributes(); // clear any default values
if (isset($_GET['Result']))
$model->attributes = $_GET['Result'];
if (isset($_POST['offset']) && $_POST['offset'] >= 0)
$model->offset = $_POST['offset'];
$summary = Result::getCountSavedResults();
$model->isLimited = true;
$this->renderPartial('_ajaxIndex', array('model' => $model,
'summary'=>$summary));
}
I would like to terminate this code repeat in the actionIndex(). But I
don't have any idea how I can do... I tried to call actionAjaxIndex etc.
But before I can call the actionAjaxIndex I got PHP errors from Yii.
(Summary variable is not exist, etc.)
View - Index.php
<!--<h1><?php echo Yii::t('strings','Results'); ?></h1>-->
<?php
echo CHtml::image(Yii::app()->request->baseUrl.'/images/toplista.jpg',
"Fogadás");
?>
<script type="text/javascript">
// Initialize the variables for calculating
var summary = <?php echo $summary ?>; // get all stored results
var timeout = 10 * 1000; // in Milliseconds -> multiply with 1000 to
use seconds
var current = 0;
var turn = 0;
var rounds = Math.floor(summary / 10);
</script>
<?php $this->renderPartial('_ajaxIndex', array('model'=>$model,
'summary'=>$summary)); ?>
<script type="text/javascript">
// Refresh the CGridView's content in _ajaxIndex.php
window.setInterval("refresh()", timeout);
// Get the offset to the search() to set the criteria
// Increase turn.
function counter(){
turn += 1;
if(turn > rounds){
turn = 0;
}
return turn *10;
}
function refresh() {
<?php
echo CHtml::ajax(array(
'url'=> CController::createUrl("result/ajaxIndex"),
'type'=>'post',
'data'=> array('offset'=>'js: counter()'),
'replace'=> '#ajax-result-grid',
))
?>
}
</script>
View - _ajaxIndex.php
<?php
/* @var $model Result */
?>
<?php $this->widget('zii.widgets.grid.CGridView', array(
'id'=>'ajax-result-grid',
'dataProvider'=>$model->search(),
'columns'=>array(
array(
'header'=>Yii::t('strings','No.'),
'value'=> $model->offset.' + $row+1',
'htmlOptions'=>array('style'=>'width:50px;'),
),
array(
'header'=>Yii::t('strings','team_name'),
'name'=>'team_id',
'value'=>'$data->team->name'
),
array(
'header'=>Yii::t('strings','value'),
'name'=>'value',
'value'=>'$data->value'
),
),
)); ?>
<script type="text/javascript">
// This is need while the admins insert the results during this page
is run.
summary = <?php echo $summary ?>;
rounds = Math.floor(summary / 10);
</script>
Yes, I think I don't understand clearly the Ajax process in the Yii :/.
Sinatra app crashes without error on Heroku but works fine locally via foreman - tips?
Sinatra app crashes without error on Heroku but works fine locally via
foreman - tips?
I have a simple Sinatra app that is working fine locally with Foreman. But
on Heroku it crashes instantly, without much further information about the
error:
2013-09-17T18:52:37.449716+00:00 heroku[router]: at=error code=H10
desc="App crashed" method=GET path=/ host=rfcstd.herokuapp.com
fwd="38.122.223.90" dyno= connect= service= status=503 bytes=
2013-09-17T18:55:29.671059+00:00 heroku[router]: at=error code=H10
desc="App crashed" method=GET path=/ host=rfcstd.herokuapp.com
fwd="38.122.223.90" dyno= connect= service= status=503 bytes=
There is no further information about the error
My app is based on https://developers.google.com/+/quickstart/ruby. I have
been trying multiple iterations of Procfile and config.ru to get it to
work, e.g.
Procfile.rb >
web: bundle exec ruby signing.rb -p $PORT
Answer:
Starting process with command `bundle exec rackup config.ru -p 14469`
configuration /app/config.ru not found
There was no config.ru included in the app so then I tried creating that
myself:
Procfile.rb >
web: bundle exec rackup ./config.ru -p $PORT
OR
web: bundle exec rackup config.ru -p $PORT
Config.ru >
require './signin.rb'
run Sinatra::Application
Answer:
at=error code=H10 desc="App crashed" method=GET path=/
host=rfcstd.herokuapp.com fwd="38.122.223.90" dyno= connect= service=
status=503 bytes=
The Google-coded signin.rb starts up Sinatra, which I think is not a
standard way of launching it as a rack app. It seems that Heroku detects
the rack app but then chokes on some files not being available... Here is
a snippet of signin.rb for good measure:
##
# The Google+ Ruby Quickstart lets you get started with the Google+ platform
# in a few minutes.
#
# The app demonstrates:
# * Using the Google+ Sign-In button to get an OAuth 2.0 refresh token.
# * Exchanging the refresh token for an access token.
# * Making Google+ API requests with the access token, including getting a
# list of people that the user has circled.
# * Disconnecting the app from the user's Google account and revoking
tokens.
#
# Author: class@google.com (Gus Class)
require 'bundler/setup'
require 'base64'
require 'rubygems'
require 'json'
require 'sinatra'
require 'google/api_client'
require 'google/api_client/client_secrets'
require 'net/https'
require 'uri'
require 'open-uri'
use Rack::Session::Pool, :expire_after => 86400 # 1 day
# Configuration
# See the README.md for getting the OAuth 2.0 client ID and
# client secret.
# Configuration that you probably don't have to change
APPLICATION_NAME = 'MyAppName'
PLUS_LOGIN_SCOPE = 'https://www.googleapis.com/auth/plus.login'
#set :port, 5000
# Build the global client
$credentials = Google::APIClient::ClientSecrets.load
$authorization = Signet::OAuth2::Client.new(
:authorization_uri => $credentials.authorization_uri,
:token_credential_uri => $credentials.token_credential_uri,
:client_id => $credentials.client_id,
:client_secret => $credentials.client_secret,
:redirect_uri => $credentials.redirect_uris.first,
:scope => PLUS_LOGIN_SCOPE)
$client = Google::APIClient.new(:application_name => APPLICATION_NAME,
:application_version => '0.1')
foreman - tips?
I have a simple Sinatra app that is working fine locally with Foreman. But
on Heroku it crashes instantly, without much further information about the
error:
2013-09-17T18:52:37.449716+00:00 heroku[router]: at=error code=H10
desc="App crashed" method=GET path=/ host=rfcstd.herokuapp.com
fwd="38.122.223.90" dyno= connect= service= status=503 bytes=
2013-09-17T18:55:29.671059+00:00 heroku[router]: at=error code=H10
desc="App crashed" method=GET path=/ host=rfcstd.herokuapp.com
fwd="38.122.223.90" dyno= connect= service= status=503 bytes=
There is no further information about the error
My app is based on https://developers.google.com/+/quickstart/ruby. I have
been trying multiple iterations of Procfile and config.ru to get it to
work, e.g.
Procfile.rb >
web: bundle exec ruby signing.rb -p $PORT
Answer:
Starting process with command `bundle exec rackup config.ru -p 14469`
configuration /app/config.ru not found
There was no config.ru included in the app so then I tried creating that
myself:
Procfile.rb >
web: bundle exec rackup ./config.ru -p $PORT
OR
web: bundle exec rackup config.ru -p $PORT
Config.ru >
require './signin.rb'
run Sinatra::Application
Answer:
at=error code=H10 desc="App crashed" method=GET path=/
host=rfcstd.herokuapp.com fwd="38.122.223.90" dyno= connect= service=
status=503 bytes=
The Google-coded signin.rb starts up Sinatra, which I think is not a
standard way of launching it as a rack app. It seems that Heroku detects
the rack app but then chokes on some files not being available... Here is
a snippet of signin.rb for good measure:
##
# The Google+ Ruby Quickstart lets you get started with the Google+ platform
# in a few minutes.
#
# The app demonstrates:
# * Using the Google+ Sign-In button to get an OAuth 2.0 refresh token.
# * Exchanging the refresh token for an access token.
# * Making Google+ API requests with the access token, including getting a
# list of people that the user has circled.
# * Disconnecting the app from the user's Google account and revoking
tokens.
#
# Author: class@google.com (Gus Class)
require 'bundler/setup'
require 'base64'
require 'rubygems'
require 'json'
require 'sinatra'
require 'google/api_client'
require 'google/api_client/client_secrets'
require 'net/https'
require 'uri'
require 'open-uri'
use Rack::Session::Pool, :expire_after => 86400 # 1 day
# Configuration
# See the README.md for getting the OAuth 2.0 client ID and
# client secret.
# Configuration that you probably don't have to change
APPLICATION_NAME = 'MyAppName'
PLUS_LOGIN_SCOPE = 'https://www.googleapis.com/auth/plus.login'
#set :port, 5000
# Build the global client
$credentials = Google::APIClient::ClientSecrets.load
$authorization = Signet::OAuth2::Client.new(
:authorization_uri => $credentials.authorization_uri,
:token_credential_uri => $credentials.token_credential_uri,
:client_id => $credentials.client_id,
:client_secret => $credentials.client_secret,
:redirect_uri => $credentials.redirect_uris.first,
:scope => PLUS_LOGIN_SCOPE)
$client = Google::APIClient.new(:application_name => APPLICATION_NAME,
:application_version => '0.1')
How to return the smallest integers from array?
How to return the smallest integers from array?
I have an array int[] a= {5,3,1,2} and I want to make a method that picks
out the "k" smallest numbers and return an array with the k smallest
integers in ascending order. But when I run this code I get the output:
[1,3]. I know the code skips some numbers somehow, but I cant twist my
brain to fix it. Any ideas?
public static int[] nrSmallest(int[] a, int k) {
if(k <1 || k>a.length)
throw new IllegalArgumentException("must be at least 1");
int[] values= Arrays.copyOf(a, k);
Arrays.sort(values);
int counter= k-1;
for(int i= k; i < a.length; i++) {
if(a[i]< values[counter]) {
for(int j= k-1; j> counter; j--) {
if(values[j]> values[j-1])
values[j]= values[j-1];
else if(values[j]< values[j-1]) {
int temp= values[j-1];
values[j-1]= values[j];
values[j]= temp;
}
}
if(a[i]< values[counter])
values[counter]= a[i];
}
if(counter> 0) counter--;
}
return values;
}
I have an array int[] a= {5,3,1,2} and I want to make a method that picks
out the "k" smallest numbers and return an array with the k smallest
integers in ascending order. But when I run this code I get the output:
[1,3]. I know the code skips some numbers somehow, but I cant twist my
brain to fix it. Any ideas?
public static int[] nrSmallest(int[] a, int k) {
if(k <1 || k>a.length)
throw new IllegalArgumentException("must be at least 1");
int[] values= Arrays.copyOf(a, k);
Arrays.sort(values);
int counter= k-1;
for(int i= k; i < a.length; i++) {
if(a[i]< values[counter]) {
for(int j= k-1; j> counter; j--) {
if(values[j]> values[j-1])
values[j]= values[j-1];
else if(values[j]< values[j-1]) {
int temp= values[j-1];
values[j-1]= values[j];
values[j]= temp;
}
}
if(a[i]< values[counter])
values[counter]= a[i];
}
if(counter> 0) counter--;
}
return values;
}
Sunday, 15 September 2013
Jave Segmentation fault on Raspberry Pi
Jave Segmentation fault on Raspberry Pi
I am trying to run Java in Raspberry Pi - Rasbian.
echo $JAVA_HOME = /usr/lib/jvm/java-7-openjdk-armhf/ echo $PATH =
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games:/usr/local/grails/bin:/usr/lib/jvm/java-7-openjdk-armhf/bin/
which java = /usr/lib/jvm/java-7-openjdk-armhf/jre/bin/java
pi@raspberrypi ~ $ java
Segmentation fault
I have spent a day on this and am lost, any ideas?
I am trying to run Java in Raspberry Pi - Rasbian.
echo $JAVA_HOME = /usr/lib/jvm/java-7-openjdk-armhf/ echo $PATH =
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games:/usr/local/grails/bin:/usr/lib/jvm/java-7-openjdk-armhf/bin/
which java = /usr/lib/jvm/java-7-openjdk-armhf/jre/bin/java
pi@raspberrypi ~ $ java
Segmentation fault
I have spent a day on this and am lost, any ideas?
looking for concept assistance with javascript, css and html
looking for concept assistance with javascript, css and html
I am messing around with javascript and css trying to get my website to be
more interactive. I am now looking to do two things, I need the user to be
able to input a list of names first, then I want to go back and list the
entered names in a column and have the user enter more information such as
height and weight and skill level in additional columns.
I figure I will use an array for the first part, but for the first part, I
am trying to find if there are other ways besides a form to do the second
part.
Is an array the best way to do the first part, and can I build a form on
the fly, or is there a better way to enter the data?
Thanks in advance for the assistance.
I am messing around with javascript and css trying to get my website to be
more interactive. I am now looking to do two things, I need the user to be
able to input a list of names first, then I want to go back and list the
entered names in a column and have the user enter more information such as
height and weight and skill level in additional columns.
I figure I will use an array for the first part, but for the first part, I
am trying to find if there are other ways besides a form to do the second
part.
Is an array the best way to do the first part, and can I build a form on
the fly, or is there a better way to enter the data?
Thanks in advance for the assistance.
PHP: Browser version number user-agent with Version/x.x.x (Safari & Opera)
PHP: Browser version number user-agent with Version/x.x.x (Safari & Opera)
I wrote a simple class to check for user agents to display a warning for
incompatible browsers. I'm doing this server side, I know it's possible
client side.
Okey first off, I'm not much good for writing regexes..
I wrote a regex that searches for lower case browser names followed by the
version number. I do a foreach() with an array something like this:
<?php
$browsers = Array('msie','chrome','safari','firefox','opera');
foreach($browsers as $i => $browser)
{
$regex = "#({$browser})[/ ]([0-9.]*)#i";
if(preg_match($regex, $useragent, $matches))
{
echo "Browser: \"{$matches[0]}\", version: \"{$matches[1]}\"";
}
}
?>
This would yield: Browser: "Firefox", version "23.0.6".
I found this works for Firefox, MS IE, and older versions of Opera.
However some browsers like Safari and the newer versions of Opera have a
different user-agent string that contains Version/x.x.x, which is
Just to give you the an idea here are 3 user-agent strings and what I need
is highlighted.
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_4) AppleWebKit/536.30.1
(KHTML, like Gecko) Version/6.0.5 Safari/536.30.1
Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)
Opera/9.80 (Windows NT 6.0) Presto/2.12.388 Version/12.14
So in each of these the following human logic correct:
If there is a Version/x.x.x in the string that is the version number.
If there isn't then Browsername/x.x.x is the version number.
Also if you look at the 1st and last user-agent string above, you can see
the Version can come before or after the browser name.
Can somebody help me to make a regex to be used with preg_match()? Do I
need to use a conditional statement or can I search for optional
groupings? I'm a bit confused..
Thanks!
I wrote a simple class to check for user agents to display a warning for
incompatible browsers. I'm doing this server side, I know it's possible
client side.
Okey first off, I'm not much good for writing regexes..
I wrote a regex that searches for lower case browser names followed by the
version number. I do a foreach() with an array something like this:
<?php
$browsers = Array('msie','chrome','safari','firefox','opera');
foreach($browsers as $i => $browser)
{
$regex = "#({$browser})[/ ]([0-9.]*)#i";
if(preg_match($regex, $useragent, $matches))
{
echo "Browser: \"{$matches[0]}\", version: \"{$matches[1]}\"";
}
}
?>
This would yield: Browser: "Firefox", version "23.0.6".
I found this works for Firefox, MS IE, and older versions of Opera.
However some browsers like Safari and the newer versions of Opera have a
different user-agent string that contains Version/x.x.x, which is
Just to give you the an idea here are 3 user-agent strings and what I need
is highlighted.
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_4) AppleWebKit/536.30.1
(KHTML, like Gecko) Version/6.0.5 Safari/536.30.1
Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)
Opera/9.80 (Windows NT 6.0) Presto/2.12.388 Version/12.14
So in each of these the following human logic correct:
If there is a Version/x.x.x in the string that is the version number.
If there isn't then Browsername/x.x.x is the version number.
Also if you look at the 1st and last user-agent string above, you can see
the Version can come before or after the browser name.
Can somebody help me to make a regex to be used with preg_match()? Do I
need to use a conditional statement or can I search for optional
groupings? I'm a bit confused..
Thanks!
Finding the Distance from A Pixel to an Edge
Finding the Distance from A Pixel to an Edge
I am trying to write an algorithm to find the minimum distance from every
pixel in the image to an edge which is black. An example image is found
below:
This is the algorithm currently have:
Starting from the pixel (R,C) I check every pixel around (R,C) that is d=1
pixels away from R,C. If I do not hit a black pixel, then I check every
pixel around (R,C) that is d =2 pixels away from R,C ... and this carries
on (with d increasing) until I find a black pixel and then I calculate the
Euclidean Distance from R,C. Note that I am making sure that the pixels I
check do not exceed the boundaries of the image).
However because I am doing this for every pixel, the algorithm is very slow.
Does anyone know a faster way to doing this? Any help will be highly
appreciated. I am coding in C++ and OpenCV so any algorithm making use of
these will be preferred.
I am trying to write an algorithm to find the minimum distance from every
pixel in the image to an edge which is black. An example image is found
below:
This is the algorithm currently have:
Starting from the pixel (R,C) I check every pixel around (R,C) that is d=1
pixels away from R,C. If I do not hit a black pixel, then I check every
pixel around (R,C) that is d =2 pixels away from R,C ... and this carries
on (with d increasing) until I find a black pixel and then I calculate the
Euclidean Distance from R,C. Note that I am making sure that the pixels I
check do not exceed the boundaries of the image).
However because I am doing this for every pixel, the algorithm is very slow.
Does anyone know a faster way to doing this? Any help will be highly
appreciated. I am coding in C++ and OpenCV so any algorithm making use of
these will be preferred.
How to check a meta_value using ajax in wordpress?
How to check a meta_value using ajax in wordpress?
I need to check if a meta value already exists using ajax, if exists
display error otherwise carry on.
This a query that I have to display the name list:
$args = array(
'posts_per_page' => -1,
'meta_key' => 'user_submit_name',
'meta_value' => get_the_author(),
'meta_compare' => '='
);
So basically we have an input field for author name, while the user write
its name, the site checks if the value already exists. If so display an
error (Username already exists, try another one) otherwise it's ok.
The value that I need to check I guess is 'meta_value' => get_the_author()
I need to check if a meta value already exists using ajax, if exists
display error otherwise carry on.
This a query that I have to display the name list:
$args = array(
'posts_per_page' => -1,
'meta_key' => 'user_submit_name',
'meta_value' => get_the_author(),
'meta_compare' => '='
);
So basically we have an input field for author name, while the user write
its name, the site checks if the value already exists. If so display an
error (Username already exists, try another one) otherwise it's ok.
The value that I need to check I guess is 'meta_value' => get_the_author()
Div pushing sibling Div's contents
Div pushing sibling Div's contents
I have 2 divs nested in the body (a) and (b). Div (b) has a negative top
margin so it sits on top of div (a).
Everything's fine except the content's of div (b) are stuck a the bottom,
below div (a) as it would appear the css properties of their parent have
not affected them.
Here's the html:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Website</title>
<script src="js/jquery-1.9.1.min.js"></script>
<link href="css/carousel.css" rel="stylesheet" type="text/css" />
<link href="css/style.css" rel="stylesheet" type="text/css">
</head>
<body>
<div class="top-menu">
<div class="container">
<div class="logo"><img src="img/logo.png" alt="logo"></div>
<ul class="nav">
<li>who we are</li>
<li>what we do</li>
</ul>
<input type="text" placeholder="login/register" class="header-login">
<button type="submit" class="header-btn"></button>
<span class="za"><img src="img/south-africa.png"></span>
<span class="sng"><img src="img/singapore.png"></span>
</div>
</div>
<div class="carousel-main">
<div id="myCarousel" class="carousel slide">
<div class="container">
<ol class="carousel-indicators">
<li data-target="#myCarousel" data-slide-to="0"
class="active"></li>
<li data-target="#myCarousel" data-slide-to="1"></li>
<li data-target="#myCarousel" data-slide-to="2"></li>
</ol>
</div>
<div class="carousel-inner home-carousel">
<div class="item active">
<img src="img/1.jpg">
<div class="container">
<div class="carousel-caption">
<h3>Risk Management and<br>
Business Finance made simple. </h3>
</div>
</div>
</div>
<div class="item">
<img src="img/2.jpg">
<div class="container">
<div class="carousel-caption">
<h3>Manage my company.</h3>
</div>
</div>
</div>
<div class="item">
<img src="img/3.jpg">
<div class="container">
<div class="carousel-caption">
<h3>Investing my money.</h3>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="sub-menu">
<ul>
<li>finance</li>
<li>Manage</li>
<li>invest</li>
</ul>
</div>
<script src="js/bootstrap.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$('#myCarousel').carousel({
interval: 9000
});
$('#myCarousel').carousel('pause');
});
</script>
</body>
</html>
Here's the style.css
@charset "utf-8";
/* CSS Document */
/* http://meyerweb.com/eric/tools/css/reset/
v2.0 | 20110126
License: none (public domain)
*/
@import
url(http://fonts.googleapis.com/css?family=Source+Sans+Pro:400,700,900);
html, body
{
width:100%;
height:100%;
font-family: 'Source Sans Pro', sans-serif !importantsa;
}
html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed,
figure, figcaption, footer, header, hgroup,
menu, nav, output, ruby, section, summary,
time, mark, audio, video {
margin: 0;
padding: 0;
border: 0;
font-size: 100%;
font: inherit;
}
/* HTML5 display-role reset for older browsers */
article, aside, details, figcaption, figure,
footer, header, hgroup, menu, nav, section {
display: block;
}
body {
line-height: 1;
}
ol, ul {
list-style: none;
}
blockquote, q {
quotes: none;
}
blockquote:before, blockquote:after,
q:before, q:after {
content: '';
content: none;
}
table {
border-collapse: collapse;
border-spacing: 0;
}
.top-menu
{
height:70px;
width:100%;
}
.logo
{
height:100%;
width:277px;
float:left;
}
.logo img
{
height:100%;
}
.container
{
width:960px;
margin:0 auto;
position:relative;
}
.top-menu .nav
{
float:left;
}
.top-menu ul li
{
display:inline-block;
padding:30px 10px;
text-transform:uppercase;
font-family: 'Source Sans Pro', sans-serif;
color:#808184;
}
.header-login
{
font-family: 'Source Sans Pro', sans-serif;
margin:25px;
padding-left:10px;
font-size:17px;
text-transform:uppercase;
background-color:#ededed;
border:none;
max-width:140px;
float:left;
}
.header-btn
{
height:30px;
width:30px;
background-image:url(../img/login.png);
background-color:transparent;
border:none;
margin-top:22px;
margin-left:-20px;
margin-right:30px;
float:left;
}
.top-menu span
{
margin-top:27px;
float:left;
margin-left:10px;
}
.sub-menu
{
width:100%;
height:170px;
margin-top:-280px;
background-color:rgba(247,148,30,0.6);
z-index:2;
}
.sub-menu ul
{
margin:0 auto;
width:600px;
height:100%;
}
.sub-menu ul li
{
display:inline-block;
height:200px;
width:190px;
text-transform:uppercase;
color:#fff;
}
Here's the carousel.css:
@charset "UTF-8";
/* CSS Document */
.carousel {
margin-bottom: 20px;
line-height: 1;
float:left;
z-index:-1;
}
.carousel-inner {
position: relative;
width: 100%;
height:700px;
overflow: hidden;
z-index:-1;
}
.carousel-inner > .item {
position: relative;
display: none;
overflow: hidden;
-webkit-transition: 0.6s ease-in-out left;
-moz-transition: 0.6s ease-in-out left;
-o-transition: 0.6s ease-in-out left;
transition: 0.6s ease-in-out left;
height:100%;
}
.carousel-inner > .item > img,
.carousel-inner > .item > a > img {
display: block;
line-height: 1;
}
.carousel-inner > .active,
.carousel-inner > .next,
.carousel-inner > .prev {
display: block;
}
.carousel-inner > .active {
left: 0;
}
.carousel-inner > .next,
.carousel-inner > .prev {
position: absolute;
top: 0;
width: 100%;
}
.carousel-inner > .next {
left: 100%;
}
.carousel-inner > .prev {
left: -100%;
}
.carousel-inner > .next.left,
.carousel-inner > .prev.right {
left: 0;
}
.carousel-inner > .active.left {
left: -100%;
}
.carousel-inner > .active.right {
left: 100%;
}
.carousel-indicators {
position: absolute;
top:600px;
right:0;
z-index: 5;
margin: 0 auto;
list-style: none;
}
.carousel-indicators li {
display: block;
float: left;
width: 20px;
height: 20px;
margin-left: 5px;
text-indent: -999px;
background-image:url(../img/indicator.png);
background-repeat:no-repeat;
opacity:0.6;
}
.carousel-indicators .active {
opacity:1;
}
.slider
{
height:700px;
width:800px;
margin: 0 auto;
margin-bottom:20px;
}
.slider img
{
width:100%;
}
.carousel-main
{
height:700px;
background-color: transparent;
margin: 0 auto;
width:100%;
}
.home-carousel > .item > img, .home-carousel > .item > a > img {
display: block;
line-height: 1;
min-height:100%;
width:100%;
max-height:100%;
}
.inner-carousel > .item > img, .inner-carousel > .item > a > img {
display: block;
line-height: 1;
height:350px;
width:800px;
}
.carousel-caption {
position: absolute;
top: -400px;
font-family: 'Source Sans Pro', sans-serif;
}
.carousel-caption h3 {
font-weight:900;
font-size:45px;
line-height:44px;
letter-spacing:-1px;
color:#fff;
text-shadow: rgba(0,0,0, 0.5) 1px 1px 2px;
}
.carousel-caption p {
font-weight:100;
font-size:18px;
line-height:38px;
margin-top:-30px;
}
.carousel-main #myCarousel
{
width:100%;
height:700px;
margin: 0 auto;
margin-bottom:-200px;
}
.carousel-control {
position: absolute;
top: 400px;
left: 0px;
width: 60px;
height: 60px;
margin-top: -20px;
font-size: 60px;
font-weight: 100;
line-height: 30px;
color: #ffffff;
text-align: center;
background-image:url(../img/leftarrow.png);
background-size:cover;
background-color:transparent;
border: 0px solid rgb(255, 255, 255);
border-radius: 100px;
opacity: 1;
filter: alpha(opacity=50);
transition: all 2s ease-in-out;
-webkit-transition: all .6s ease-in-out; /** Chrome & Safari **/
-moz-transition: all .6s ease-in-out; /** Firefox **/
-o-transition: all .6s ease-in-out;
}
.carousel-control.right {
right:0;
left: auto;
background-image:url(../img/rightarrow.png);
}
.carousel-control:hover {
color: rgb(255, 255, 255);
opacity:.6;
text-decoration: none;
}
.carousel-control:focus {
background-color:none;
text-decoration: none;
opacity: 0.9;
}
.home-carousel .carousel-caption h4 {
font-weight:500;
font-size:29px;
color:#F7F4ED;
line-height:35px;
margin: 20px 0 20px;
text-align:center;
}
.home-carousel .carousel-caption .introduction {
font-weight:300;
font-size:13px;
line-height:19px;
text-align:center;
margin:0 auto;
color:#F7F4ED;
height:200px;
width:250px;
}
@media (max-width: 1030px) {
.carousel-control {
position: absolute;
bottom:0;
left: 0px;
margin-top:225px;
width: 60px;
height: 60px;
font-size: 60px;
font-weight: 100;
line-height: 30px;
color: #ffffff;
text-align: center;
background-image:url(../img/leftarrow.png);
background-size:cover;
background-color:#474C71;
border: 0px solid rgb(255, 255, 255);
border-radius: 0px;
opacity: 1;
filter: alpha(opacity=50);
transition: all 2s ease-in-out;
-webkit-transition: all .6s ease-in-out; /** Chrome & Safari **/
-moz-transition: all .6s ease-in-out; /** Firefox **/
-o-transition: all .6s ease-in-out;
}
.carousel-control.right {
left: 61px;
background-image:url(../img/rightarrow.png);
}
}
Here's a working version of the same:
http://deeptest.co.za/apexpeak/
Please help and thank you
I have 2 divs nested in the body (a) and (b). Div (b) has a negative top
margin so it sits on top of div (a).
Everything's fine except the content's of div (b) are stuck a the bottom,
below div (a) as it would appear the css properties of their parent have
not affected them.
Here's the html:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Website</title>
<script src="js/jquery-1.9.1.min.js"></script>
<link href="css/carousel.css" rel="stylesheet" type="text/css" />
<link href="css/style.css" rel="stylesheet" type="text/css">
</head>
<body>
<div class="top-menu">
<div class="container">
<div class="logo"><img src="img/logo.png" alt="logo"></div>
<ul class="nav">
<li>who we are</li>
<li>what we do</li>
</ul>
<input type="text" placeholder="login/register" class="header-login">
<button type="submit" class="header-btn"></button>
<span class="za"><img src="img/south-africa.png"></span>
<span class="sng"><img src="img/singapore.png"></span>
</div>
</div>
<div class="carousel-main">
<div id="myCarousel" class="carousel slide">
<div class="container">
<ol class="carousel-indicators">
<li data-target="#myCarousel" data-slide-to="0"
class="active"></li>
<li data-target="#myCarousel" data-slide-to="1"></li>
<li data-target="#myCarousel" data-slide-to="2"></li>
</ol>
</div>
<div class="carousel-inner home-carousel">
<div class="item active">
<img src="img/1.jpg">
<div class="container">
<div class="carousel-caption">
<h3>Risk Management and<br>
Business Finance made simple. </h3>
</div>
</div>
</div>
<div class="item">
<img src="img/2.jpg">
<div class="container">
<div class="carousel-caption">
<h3>Manage my company.</h3>
</div>
</div>
</div>
<div class="item">
<img src="img/3.jpg">
<div class="container">
<div class="carousel-caption">
<h3>Investing my money.</h3>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="sub-menu">
<ul>
<li>finance</li>
<li>Manage</li>
<li>invest</li>
</ul>
</div>
<script src="js/bootstrap.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$('#myCarousel').carousel({
interval: 9000
});
$('#myCarousel').carousel('pause');
});
</script>
</body>
</html>
Here's the style.css
@charset "utf-8";
/* CSS Document */
/* http://meyerweb.com/eric/tools/css/reset/
v2.0 | 20110126
License: none (public domain)
*/
@import
url(http://fonts.googleapis.com/css?family=Source+Sans+Pro:400,700,900);
html, body
{
width:100%;
height:100%;
font-family: 'Source Sans Pro', sans-serif !importantsa;
}
html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed,
figure, figcaption, footer, header, hgroup,
menu, nav, output, ruby, section, summary,
time, mark, audio, video {
margin: 0;
padding: 0;
border: 0;
font-size: 100%;
font: inherit;
}
/* HTML5 display-role reset for older browsers */
article, aside, details, figcaption, figure,
footer, header, hgroup, menu, nav, section {
display: block;
}
body {
line-height: 1;
}
ol, ul {
list-style: none;
}
blockquote, q {
quotes: none;
}
blockquote:before, blockquote:after,
q:before, q:after {
content: '';
content: none;
}
table {
border-collapse: collapse;
border-spacing: 0;
}
.top-menu
{
height:70px;
width:100%;
}
.logo
{
height:100%;
width:277px;
float:left;
}
.logo img
{
height:100%;
}
.container
{
width:960px;
margin:0 auto;
position:relative;
}
.top-menu .nav
{
float:left;
}
.top-menu ul li
{
display:inline-block;
padding:30px 10px;
text-transform:uppercase;
font-family: 'Source Sans Pro', sans-serif;
color:#808184;
}
.header-login
{
font-family: 'Source Sans Pro', sans-serif;
margin:25px;
padding-left:10px;
font-size:17px;
text-transform:uppercase;
background-color:#ededed;
border:none;
max-width:140px;
float:left;
}
.header-btn
{
height:30px;
width:30px;
background-image:url(../img/login.png);
background-color:transparent;
border:none;
margin-top:22px;
margin-left:-20px;
margin-right:30px;
float:left;
}
.top-menu span
{
margin-top:27px;
float:left;
margin-left:10px;
}
.sub-menu
{
width:100%;
height:170px;
margin-top:-280px;
background-color:rgba(247,148,30,0.6);
z-index:2;
}
.sub-menu ul
{
margin:0 auto;
width:600px;
height:100%;
}
.sub-menu ul li
{
display:inline-block;
height:200px;
width:190px;
text-transform:uppercase;
color:#fff;
}
Here's the carousel.css:
@charset "UTF-8";
/* CSS Document */
.carousel {
margin-bottom: 20px;
line-height: 1;
float:left;
z-index:-1;
}
.carousel-inner {
position: relative;
width: 100%;
height:700px;
overflow: hidden;
z-index:-1;
}
.carousel-inner > .item {
position: relative;
display: none;
overflow: hidden;
-webkit-transition: 0.6s ease-in-out left;
-moz-transition: 0.6s ease-in-out left;
-o-transition: 0.6s ease-in-out left;
transition: 0.6s ease-in-out left;
height:100%;
}
.carousel-inner > .item > img,
.carousel-inner > .item > a > img {
display: block;
line-height: 1;
}
.carousel-inner > .active,
.carousel-inner > .next,
.carousel-inner > .prev {
display: block;
}
.carousel-inner > .active {
left: 0;
}
.carousel-inner > .next,
.carousel-inner > .prev {
position: absolute;
top: 0;
width: 100%;
}
.carousel-inner > .next {
left: 100%;
}
.carousel-inner > .prev {
left: -100%;
}
.carousel-inner > .next.left,
.carousel-inner > .prev.right {
left: 0;
}
.carousel-inner > .active.left {
left: -100%;
}
.carousel-inner > .active.right {
left: 100%;
}
.carousel-indicators {
position: absolute;
top:600px;
right:0;
z-index: 5;
margin: 0 auto;
list-style: none;
}
.carousel-indicators li {
display: block;
float: left;
width: 20px;
height: 20px;
margin-left: 5px;
text-indent: -999px;
background-image:url(../img/indicator.png);
background-repeat:no-repeat;
opacity:0.6;
}
.carousel-indicators .active {
opacity:1;
}
.slider
{
height:700px;
width:800px;
margin: 0 auto;
margin-bottom:20px;
}
.slider img
{
width:100%;
}
.carousel-main
{
height:700px;
background-color: transparent;
margin: 0 auto;
width:100%;
}
.home-carousel > .item > img, .home-carousel > .item > a > img {
display: block;
line-height: 1;
min-height:100%;
width:100%;
max-height:100%;
}
.inner-carousel > .item > img, .inner-carousel > .item > a > img {
display: block;
line-height: 1;
height:350px;
width:800px;
}
.carousel-caption {
position: absolute;
top: -400px;
font-family: 'Source Sans Pro', sans-serif;
}
.carousel-caption h3 {
font-weight:900;
font-size:45px;
line-height:44px;
letter-spacing:-1px;
color:#fff;
text-shadow: rgba(0,0,0, 0.5) 1px 1px 2px;
}
.carousel-caption p {
font-weight:100;
font-size:18px;
line-height:38px;
margin-top:-30px;
}
.carousel-main #myCarousel
{
width:100%;
height:700px;
margin: 0 auto;
margin-bottom:-200px;
}
.carousel-control {
position: absolute;
top: 400px;
left: 0px;
width: 60px;
height: 60px;
margin-top: -20px;
font-size: 60px;
font-weight: 100;
line-height: 30px;
color: #ffffff;
text-align: center;
background-image:url(../img/leftarrow.png);
background-size:cover;
background-color:transparent;
border: 0px solid rgb(255, 255, 255);
border-radius: 100px;
opacity: 1;
filter: alpha(opacity=50);
transition: all 2s ease-in-out;
-webkit-transition: all .6s ease-in-out; /** Chrome & Safari **/
-moz-transition: all .6s ease-in-out; /** Firefox **/
-o-transition: all .6s ease-in-out;
}
.carousel-control.right {
right:0;
left: auto;
background-image:url(../img/rightarrow.png);
}
.carousel-control:hover {
color: rgb(255, 255, 255);
opacity:.6;
text-decoration: none;
}
.carousel-control:focus {
background-color:none;
text-decoration: none;
opacity: 0.9;
}
.home-carousel .carousel-caption h4 {
font-weight:500;
font-size:29px;
color:#F7F4ED;
line-height:35px;
margin: 20px 0 20px;
text-align:center;
}
.home-carousel .carousel-caption .introduction {
font-weight:300;
font-size:13px;
line-height:19px;
text-align:center;
margin:0 auto;
color:#F7F4ED;
height:200px;
width:250px;
}
@media (max-width: 1030px) {
.carousel-control {
position: absolute;
bottom:0;
left: 0px;
margin-top:225px;
width: 60px;
height: 60px;
font-size: 60px;
font-weight: 100;
line-height: 30px;
color: #ffffff;
text-align: center;
background-image:url(../img/leftarrow.png);
background-size:cover;
background-color:#474C71;
border: 0px solid rgb(255, 255, 255);
border-radius: 0px;
opacity: 1;
filter: alpha(opacity=50);
transition: all 2s ease-in-out;
-webkit-transition: all .6s ease-in-out; /** Chrome & Safari **/
-moz-transition: all .6s ease-in-out; /** Firefox **/
-o-transition: all .6s ease-in-out;
}
.carousel-control.right {
left: 61px;
background-image:url(../img/rightarrow.png);
}
}
Here's a working version of the same:
http://deeptest.co.za/apexpeak/
Please help and thank you
javascript two variables with same name co-exist in same object?
javascript two variables with same name co-exist in same object?
I'm trying my best to understand javascript. Here is a simple experiment
in Chrome console which gets me very confused:
var foo=function(){this.p=1;}
foo.prototype.p=2;
var bar=new foo();
//foo{p:1,p:2} <- this is the output of Chrome console, from the last
command above
Does this mean bar has 2 p??? What is the reasoning behind this?
I'm trying my best to understand javascript. Here is a simple experiment
in Chrome console which gets me very confused:
var foo=function(){this.p=1;}
foo.prototype.p=2;
var bar=new foo();
//foo{p:1,p:2} <- this is the output of Chrome console, from the last
command above
Does this mean bar has 2 p??? What is the reasoning behind this?
Asp physical and virtual path
Asp physical and virtual path
This is the first time I make an asp site. This code is working fine on my
pc but after deployment some feature which need a path is not working
anymore. I get no errors, simply does not work. I have tried many sort of
path combination but I am not getting it right. Moreover, I would like to
find a solution that makes the code working on both pc, during
development, and hosting server without having to change the code.
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
{
if (e.Item is GridEditableItem && e.Item.IsInEditMode )
{
try
{
//check if directory exist and if not create directory
GridEditableItem editedItem = e.Item as GridEditableItem;
string recordIDcreateDir =
editedItem.GetDataKeyValue("TransazioneID").ToString();
string subPath = "Allegati\\" + recordIDcreateDir;
bool isExists =
System.IO.Directory.Exists(Server.MapPath(subPath));
if (!isExists)
System.IO.Directory.CreateDirectory(Server.MapPath(subPath));
//loop in the directory to search for files
GridEditableItem edit = (GridEditableItem)e.Item;
DirectoryInfo dir = new
DirectoryInfo(@"C:\Users\blablabla\Test1_managDoc\Test1_managDoc\Allegati\"
+ recordIDcreateDir);// path of the target folder where your
files are stored
DirectoryInfo[] subDirs = dir.GetDirectories();
FileInfo[] files = dir.GetFiles(); //Getting the files inside
the Directory
foreach (FileInfo fi in files) //To loop through all files for
setting each file as HyperLink
{
HyperLink lktest = new HyperLink(); //Add HyperLink Column
lktest.ID = "lnk" + Guid.NewGuid(); //Setting Unique IDs
lktest.Text = fi.Name.ToString(); //Get the File name
lktest.NavigateUrl = "#";
lktest.Attributes.Add("Onclick", "ViewCheck('" +
recordIDcreateDir + "/" + fi.Name + "')"); // Calling the
JS event
//Adding the HyperLink to EditForm
edit["columnAllegati"].Controls.Add(lktest);
edit["columnAllegati"].Controls.Add(new
LiteralControl("<br>"));
}
}
catch (Exception)
{ }
}
}
How should I change the physical path and the virtual path to get the code
working on both, pc and hosting server?
This is the first time I make an asp site. This code is working fine on my
pc but after deployment some feature which need a path is not working
anymore. I get no errors, simply does not work. I have tried many sort of
path combination but I am not getting it right. Moreover, I would like to
find a solution that makes the code working on both pc, during
development, and hosting server without having to change the code.
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
{
if (e.Item is GridEditableItem && e.Item.IsInEditMode )
{
try
{
//check if directory exist and if not create directory
GridEditableItem editedItem = e.Item as GridEditableItem;
string recordIDcreateDir =
editedItem.GetDataKeyValue("TransazioneID").ToString();
string subPath = "Allegati\\" + recordIDcreateDir;
bool isExists =
System.IO.Directory.Exists(Server.MapPath(subPath));
if (!isExists)
System.IO.Directory.CreateDirectory(Server.MapPath(subPath));
//loop in the directory to search for files
GridEditableItem edit = (GridEditableItem)e.Item;
DirectoryInfo dir = new
DirectoryInfo(@"C:\Users\blablabla\Test1_managDoc\Test1_managDoc\Allegati\"
+ recordIDcreateDir);// path of the target folder where your
files are stored
DirectoryInfo[] subDirs = dir.GetDirectories();
FileInfo[] files = dir.GetFiles(); //Getting the files inside
the Directory
foreach (FileInfo fi in files) //To loop through all files for
setting each file as HyperLink
{
HyperLink lktest = new HyperLink(); //Add HyperLink Column
lktest.ID = "lnk" + Guid.NewGuid(); //Setting Unique IDs
lktest.Text = fi.Name.ToString(); //Get the File name
lktest.NavigateUrl = "#";
lktest.Attributes.Add("Onclick", "ViewCheck('" +
recordIDcreateDir + "/" + fi.Name + "')"); // Calling the
JS event
//Adding the HyperLink to EditForm
edit["columnAllegati"].Controls.Add(lktest);
edit["columnAllegati"].Controls.Add(new
LiteralControl("<br>"));
}
}
catch (Exception)
{ }
}
}
How should I change the physical path and the virtual path to get the code
working on both, pc and hosting server?
Subscribe to:
Comments (Atom)