JDO mapped by: NullPointerException when I tried to add object into a list
of another class before makePersistent
I have File and TaggedDetail classes. One-to-many relationship
File.java
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Key key;
@Persistent
private BlobKey blobKey;
@Persistent(mappedBy = "file")
private List<TaggedDetail> tags;
TaggedDetail.java
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Key key;
@Persistent
private File file;
@Persistent
private String tag;
My code for adding tag to file
PersistenceManager pm = PMF.get().getPersistenceManager();
//get file object by blobKey
File file = FileDatastoreUtils.getFileByBlobKey(blobKey);
//create taggedDetail object
TaggedDetail taggedDetail = new TaggedDetail(tag, file);
file.getTags().add(taggedDetail); //this part gave me problem
try {
pm.makePersistent(file);
isSuccess = true;
} finally {
pm.close();
}
The error I got is NullPointerException at file.getTags().add(taggedDetail);
I found out that NullPointerException is thrown because the specified
element is null and this list does not permit null elements.
So I tried "System.out.println(taggedDetail == null);" which gave me
false. That means taggedDetail object is not null.
Did I code the adding tag to file part wrongly? or Is it other problems?
Thursday, 3 October 2013
Wednesday, 2 October 2013
Bessel functions and Kelvin function with complex argument
Bessel functions and Kelvin function with complex argument
I am trying to understand the theory behind a model published in a past
paper and implement the model in Matlab. In short: I don't understand how
a Kelvin function decomposition of a Bessel function with a complex
argument is completed and I don't know if, for implementation in a
computer code, will be numerically equivalent.
Here is the pertinent information:
Equation :
I am trying to understand the theory behind a model published in a past
paper and implement the model in Matlab. In short: I don't understand how
a Kelvin function decomposition of a Bessel function with a complex
argument is completed and I don't know if, for implementation in a
computer code, will be numerically equivalent.
Here is the pertinent information:
Equation :
intersection of sets in C++
intersection of sets in C++
i am trying to do simple sets intersection , it works correctly , but when
output comes , it shows only memory address or garbage random value , help
me ,i applied breakpoints , but it's not working . actually i am new in
C++
#include<iostream>
using namespace std;
class set
{
private:
int size;
int *elem;
public:
set(){size=0;elem=NULL;}
set (int s);
~set();
set(set &s);
set intersection(set A,int z);
void inputset();
void outputset();
};
set::set(int s)
{
size = s;
elem = new int[s];
}
void set::inputset()
{
int i;
cout<<"Enter the set Element"<< endl;
for(i=0 ; i<size ; i++)
cin>>elem[i];
}
set set::intersection(set A,int z)
{
int i,j,k=0;
set R(z);
for(i=0;i<size;i++)
{
for(j=0;j<A.size;j++)
{
if(elem[i]==A.elem[j])
{
R.elem[k]=A.elem[j];
k++;
break;
}
}
}
return R;
}
set::~set()
{
delete []elem;
}
set::set(set &s)
{
int i;
if(size>0)
{
delete []elem;
}
size = s.size;
elem = new int[size];
for(i=0;i<size;i++)
{
elem[i]= s.elem[i];
}
}
void set::outputset()
{
int i;
cout<<"The elements of new set is : "<<endl;
for(i=0;i<size;i++)
{
cout<<elem[i]<<endl;
}
cout<<endl;
}
int main()
{
int x,y,z;
char choice;
cout<<"Enter sizeof set A"<<endl;
cin>>x;
set S1(x);
S1.inputset();
S1.outputset();
cout<<"Enter sizeof set B"<<endl;
cin>>y;
set S2(y);
S2.inputset();
S2.outputset();
z=x+y;
set S3(z);
cout<<"Enter I for intersection"<<endl<<"Enter U for union"<<endl<<"Enter
D for difference"<<endl;
cin>>choice;
switch(choice)
{
case'I':
S3=S1.intersection(S2,z);
S3.outputset();
break;
default:
cout<<"Invalid entry";
}
return 0;
}
i am trying to do simple sets intersection , it works correctly , but when
output comes , it shows only memory address or garbage random value , help
me ,i applied breakpoints , but it's not working . actually i am new in
C++
#include<iostream>
using namespace std;
class set
{
private:
int size;
int *elem;
public:
set(){size=0;elem=NULL;}
set (int s);
~set();
set(set &s);
set intersection(set A,int z);
void inputset();
void outputset();
};
set::set(int s)
{
size = s;
elem = new int[s];
}
void set::inputset()
{
int i;
cout<<"Enter the set Element"<< endl;
for(i=0 ; i<size ; i++)
cin>>elem[i];
}
set set::intersection(set A,int z)
{
int i,j,k=0;
set R(z);
for(i=0;i<size;i++)
{
for(j=0;j<A.size;j++)
{
if(elem[i]==A.elem[j])
{
R.elem[k]=A.elem[j];
k++;
break;
}
}
}
return R;
}
set::~set()
{
delete []elem;
}
set::set(set &s)
{
int i;
if(size>0)
{
delete []elem;
}
size = s.size;
elem = new int[size];
for(i=0;i<size;i++)
{
elem[i]= s.elem[i];
}
}
void set::outputset()
{
int i;
cout<<"The elements of new set is : "<<endl;
for(i=0;i<size;i++)
{
cout<<elem[i]<<endl;
}
cout<<endl;
}
int main()
{
int x,y,z;
char choice;
cout<<"Enter sizeof set A"<<endl;
cin>>x;
set S1(x);
S1.inputset();
S1.outputset();
cout<<"Enter sizeof set B"<<endl;
cin>>y;
set S2(y);
S2.inputset();
S2.outputset();
z=x+y;
set S3(z);
cout<<"Enter I for intersection"<<endl<<"Enter U for union"<<endl<<"Enter
D for difference"<<endl;
cin>>choice;
switch(choice)
{
case'I':
S3=S1.intersection(S2,z);
S3.outputset();
break;
default:
cout<<"Invalid entry";
}
return 0;
}
WORDPRESS - Plugin Analytics360
WORDPRESS - Plugin Analytics360
I recontre a problem when I try to link my google analytics to a website
which is on worpress. (the plugin is utlise is Analytics360)
The trouble is that I get to give good access to the site but this one
appears right after me:
Hmm. Went something wrong with your Google authentication! The error
messages was: 403: Forbidden. If you're having trouble getting up and
running, you might try one of the Following resources
Do you have a solution? Or if someone has already fallen on this problem? :-)
I recontre a problem when I try to link my google analytics to a website
which is on worpress. (the plugin is utlise is Analytics360)
The trouble is that I get to give good access to the site but this one
appears right after me:
Hmm. Went something wrong with your Google authentication! The error
messages was: 403: Forbidden. If you're having trouble getting up and
running, you might try one of the Following resources
Do you have a solution? Or if someone has already fallen on this problem? :-)
Tuesday, 1 October 2013
How to put dynamic content in YUI gallery-tooltip for bootstrap
How to put dynamic content in YUI gallery-tooltip for bootstrap
bootstrap-tooltip" from
http://jshirley.github.com/bootstrap/javascript.html#tooltips and I want
to dynamically put content when someone enters some incorrect input in the
input field.
This is how I am trying it:
<script>
var v=new Y.Bootstrap.Tooltip({ selector :
'*[rel=tooltip]',trigger:'focus',placement:'right' }).render();
</script>
My html part:
<input type="text" class="form-control" placeholder="First Name"
required="" id="firstNameId" rel="tooltip"/>
Now how can I put the content in the tooltip dynamically.
bootstrap-tooltip" from
http://jshirley.github.com/bootstrap/javascript.html#tooltips and I want
to dynamically put content when someone enters some incorrect input in the
input field.
This is how I am trying it:
<script>
var v=new Y.Bootstrap.Tooltip({ selector :
'*[rel=tooltip]',trigger:'focus',placement:'right' }).render();
</script>
My html part:
<input type="text" class="form-control" placeholder="First Name"
required="" id="firstNameId" rel="tooltip"/>
Now how can I put the content in the tooltip dynamically.
Saving checked box value as 0 or 1 in the database from Ajax POST
Saving checked box value as 0 or 1 in the database from Ajax POST
So I have a few columns in the database which I have configured as
TINYINT. I have the same number of check boxes as well on the front end.
Here's my HTML,
<script type="text/x-handlebars" id="project">
<div class="row">
<div class="span6">
<div class="well well-small">
<p style="text-align: center">
You can create a new Project by filling this simple form.
</p>
<p style="text-align: center"> Project Name should be
minimum 10 characters & There's no limit on
Project Description.
</p>
</div>
<form class="form-horizontal">
<div class="control-group">
<label class="control-label" for="projectname">Project
Name: </label>
<div class="controls">
<input type="text" name="projectname"
id="projectname" required
title="Project Name is Required!"
pattern="[A-z ]{10,}"
placeholder="Enter Project Name"/>
</div>
</div>
<div class="control-group">
<label class="control-label" for="projectdesc">Project
Description:</label>
<div class="controls">
<textarea rows="3" id="projectdesc"
name="projectdesc" placeholder="Enter Project
Desc"
required="Description Required"></textarea>
</div>
</div>
<div class="control-group">
<label class="control-label">Roles:</label>
<div class="controls">
<label class="checkbox">
<input type="checkbox" name="roles"
id="script" value="false"> Script
</label>
<label class="checkbox">
<input type="checkbox" name="roles"
id="design" value="false"> Design
</label>
<label class="checkbox">
<input type="checkbox" name="roles"
id="writer" value="false"> Writer
</label>
<label class="checkbox">
<input type="checkbox" name="roles"
id="storyboard" value="false"> Storyboard
</label>
<label class="checkbox">
<input type="checkbox" name="roles"
id="workbook" value="false"> Workbook
</label>
<br>
<button class="btn"
>Add Project</button>
</div>
</div>
</form>
</div>
</div>
</script>
And here's what I am doing,
function(event) {
$(":text, input[type='checkbox'], textarea").each(function() {
if ($(this).val() === "") {
alert("Empty Fields!");
event.preventDefault();
} else {
App.Project.createNew();
alert("Project Created");
event.preventDefault();
}
});
}
And the Ajax POST,
dataString = {
'projectname' : $("#projectname").val(),
'projectdesc' : $("#projectdesc").val(),
'script' : $('input.roles[type="checkbox"]:checked', this).val()
};
console.log('check');
$.ajax({
type : "POST",
url : "http://ankur.local/users/createNewProject",
data : dataString,
dataType : "json",
success : function(data) {
console.log('success');
alert('');
}
});
return false;
You can see from my code that I am trying to grab the checked value of the
textbox which I want to store in the database as 0 or 1 or True or False
perhaps? Moreover I want to have a condition that out of the given
checkboxes, at least one should be checked.
'script' : $('input.roles[type="checkbox"]:checked', this).val()
How can I achieve my objective?
So I have a few columns in the database which I have configured as
TINYINT. I have the same number of check boxes as well on the front end.
Here's my HTML,
<script type="text/x-handlebars" id="project">
<div class="row">
<div class="span6">
<div class="well well-small">
<p style="text-align: center">
You can create a new Project by filling this simple form.
</p>
<p style="text-align: center"> Project Name should be
minimum 10 characters & There's no limit on
Project Description.
</p>
</div>
<form class="form-horizontal">
<div class="control-group">
<label class="control-label" for="projectname">Project
Name: </label>
<div class="controls">
<input type="text" name="projectname"
id="projectname" required
title="Project Name is Required!"
pattern="[A-z ]{10,}"
placeholder="Enter Project Name"/>
</div>
</div>
<div class="control-group">
<label class="control-label" for="projectdesc">Project
Description:</label>
<div class="controls">
<textarea rows="3" id="projectdesc"
name="projectdesc" placeholder="Enter Project
Desc"
required="Description Required"></textarea>
</div>
</div>
<div class="control-group">
<label class="control-label">Roles:</label>
<div class="controls">
<label class="checkbox">
<input type="checkbox" name="roles"
id="script" value="false"> Script
</label>
<label class="checkbox">
<input type="checkbox" name="roles"
id="design" value="false"> Design
</label>
<label class="checkbox">
<input type="checkbox" name="roles"
id="writer" value="false"> Writer
</label>
<label class="checkbox">
<input type="checkbox" name="roles"
id="storyboard" value="false"> Storyboard
</label>
<label class="checkbox">
<input type="checkbox" name="roles"
id="workbook" value="false"> Workbook
</label>
<br>
<button class="btn"
>Add Project</button>
</div>
</div>
</form>
</div>
</div>
</script>
And here's what I am doing,
function(event) {
$(":text, input[type='checkbox'], textarea").each(function() {
if ($(this).val() === "") {
alert("Empty Fields!");
event.preventDefault();
} else {
App.Project.createNew();
alert("Project Created");
event.preventDefault();
}
});
}
And the Ajax POST,
dataString = {
'projectname' : $("#projectname").val(),
'projectdesc' : $("#projectdesc").val(),
'script' : $('input.roles[type="checkbox"]:checked', this).val()
};
console.log('check');
$.ajax({
type : "POST",
url : "http://ankur.local/users/createNewProject",
data : dataString,
dataType : "json",
success : function(data) {
console.log('success');
alert('');
}
});
return false;
You can see from my code that I am trying to grab the checked value of the
textbox which I want to store in the database as 0 or 1 or True or False
perhaps? Moreover I want to have a condition that out of the given
checkboxes, at least one should be checked.
'script' : $('input.roles[type="checkbox"]:checked', this).val()
How can I achieve my objective?
Prove that any subset of $\mathbb{R}^2$ which is $D$-open is also $D_1$-open.
Prove that any subset of $\mathbb{R}^2$ which is $D$-open is also $D_1$-open.
Prove that any subset of $\mathbb{R}^2$ which is $D$-open is $D_1$-open
and, conversely, that any subset of the plane which is $D_1$-open is
$D$-open.
Let $D$ be $D(x_1,y_1)=\sqrt{(x_1-x_2)^2+(y_1-y_2)^2}$. Let $D_1$ be
$D((x_1,y_1)(x_2,y_2))=\lvert x_1 - x_2 \rvert + \lvert y_1-y_2 \rvert$.
Attempt:
Consider the metric space $(X,D)$. Let $U\subset X$. Then, for any point
$(x,y)\in U$ there exists $p>0$ where $N_p(x,y)\subset U$.
Consider the metric space $(X,D_1)$. Let $V\subset X$. Then, for any point
$(x_1,y_1)\in V$ there exists $q>0$ where $N_q(x_1,y_1)\subset V$.
Given $p$, let $q=p/\sqrt{2}$. Then for any $(x',y')\in N_q(x)\subset V$,
$(x',y')\in N_p(x)\subset U$. Hence, if $X$ is $D$-open, then it must also
be $D_1$-open.
Any help fixing this proof is appreciated.
Prove that any subset of $\mathbb{R}^2$ which is $D$-open is $D_1$-open
and, conversely, that any subset of the plane which is $D_1$-open is
$D$-open.
Let $D$ be $D(x_1,y_1)=\sqrt{(x_1-x_2)^2+(y_1-y_2)^2}$. Let $D_1$ be
$D((x_1,y_1)(x_2,y_2))=\lvert x_1 - x_2 \rvert + \lvert y_1-y_2 \rvert$.
Attempt:
Consider the metric space $(X,D)$. Let $U\subset X$. Then, for any point
$(x,y)\in U$ there exists $p>0$ where $N_p(x,y)\subset U$.
Consider the metric space $(X,D_1)$. Let $V\subset X$. Then, for any point
$(x_1,y_1)\in V$ there exists $q>0$ where $N_q(x_1,y_1)\subset V$.
Given $p$, let $q=p/\sqrt{2}$. Then for any $(x',y')\in N_q(x)\subset V$,
$(x',y')\in N_p(x)\subset U$. Hence, if $X$ is $D$-open, then it must also
be $D_1$-open.
Any help fixing this proof is appreciated.
Pontual Estimation (bayes estimator)
Pontual Estimation (bayes estimator)
pAn urn countain 5 balls, $ \theta$ white and $ 5 - \theta $ green. The
experiment consists in grab 2 balls from the urn and register the pair $
(x_1, x_2) $, where $x_i $= 1 if the ith ball chosen is white and $x_i =
0$ otherwise. Calculate de Bayes estimator for $ \theta$ if the squares
error loss function is used./p pI calculate the probability of each pair $
(x_1, x_2) $ and I am trying to find the posterior distribution. But I
don't get what I need to do now. /p pWe have that the loss function is $
l(\theta, \theta* ) = ( \theta - \theta* )^2 $ and the decision space is $
D= [{ 0,1,2,3,4,5}] $ . So, what should I do? Should I calculate the risk
for each $ \theta $ and find the one that minimize my risk ? I cant think
what I need to do with the ordered pair except calculate it's
probability/p
pAn urn countain 5 balls, $ \theta$ white and $ 5 - \theta $ green. The
experiment consists in grab 2 balls from the urn and register the pair $
(x_1, x_2) $, where $x_i $= 1 if the ith ball chosen is white and $x_i =
0$ otherwise. Calculate de Bayes estimator for $ \theta$ if the squares
error loss function is used./p pI calculate the probability of each pair $
(x_1, x_2) $ and I am trying to find the posterior distribution. But I
don't get what I need to do now. /p pWe have that the loss function is $
l(\theta, \theta* ) = ( \theta - \theta* )^2 $ and the decision space is $
D= [{ 0,1,2,3,4,5}] $ . So, what should I do? Should I calculate the risk
for each $ \theta $ and find the one that minimize my risk ? I cant think
what I need to do with the ordered pair except calculate it's
probability/p
Monday, 30 September 2013
Moving encrypted home folder to a new hard drive
Moving encrypted home folder to a new hard drive
Recently I bought a new hard drive. I'd like to turn this hard drive into
the /home. During original install I set my home directory up as
encrypted. At this point I dont know how to move the home folder to the
new hard drive. Also I dont know how to get it to automatically mount the
encrypted home folder.
Recently I bought a new hard drive. I'd like to turn this hard drive into
the /home. During original install I set my home directory up as
encrypted. At this point I dont know how to move the home folder to the
new hard drive. Also I dont know how to get it to automatically mount the
encrypted home folder.
Euclid for polynomials
Euclid for polynomials
I have a question bout euclid polynomials.
If $C(x) =x^4−1$ and $D(x) =x^3+x^2
How do I find a polynomials $A(x)$ and $B(x)$ such that $A(x)C(x)
+B(x)D(x) =x+1$ for all $x$?
I have a question bout euclid polynomials.
If $C(x) =x^4−1$ and $D(x) =x^3+x^2
How do I find a polynomials $A(x)$ and $B(x)$ such that $A(x)C(x)
+B(x)D(x) =x+1$ for all $x$?
SharePoint IF Function Close Survey Option
SharePoint IF Function Close Survey Option
Hi I wondered if this query was within the remit of SharePoint Server 2013
or if someone can point out something quite obvious that i'm missing.
I wanted to create a Survey and offer different Questions based on the
answers to those questions. I have tried building something similar in
info path and it doesn't seem to meet my requirements and workflows on
surveys are proving to be extremely frustrating.
Basically what I need is when someone answers "Yes" or "Maybe" to the
first question it proceeds to the other questions and records the results
in a viewable format (this works fine)
However when a person answers "No" to the same question I want it to end
the survey saving the results (of how many people answered No) and offer
some sort of message. I only administor the site collection and familiar
with but not confident enough to play around with script
I thought Branching might be my solution but it only offers the option for
another question. I had hope in an IF statement after looking at the
required syntax but nothing seems to fit.
Any help is much appreciated.
Thanks
Hi I wondered if this query was within the remit of SharePoint Server 2013
or if someone can point out something quite obvious that i'm missing.
I wanted to create a Survey and offer different Questions based on the
answers to those questions. I have tried building something similar in
info path and it doesn't seem to meet my requirements and workflows on
surveys are proving to be extremely frustrating.
Basically what I need is when someone answers "Yes" or "Maybe" to the
first question it proceeds to the other questions and records the results
in a viewable format (this works fine)
However when a person answers "No" to the same question I want it to end
the survey saving the results (of how many people answered No) and offer
some sort of message. I only administor the site collection and familiar
with but not confident enough to play around with script
I thought Branching might be my solution but it only offers the option for
another question. I had hope in an IF statement after looking at the
required syntax but nothing seems to fit.
Any help is much appreciated.
Thanks
Getting the rmtp with wireshark
Getting the rmtp with wireshark
In the last tow days I've been trying to get the rtmp of a TV channel and
I'm using wireshark but I'm facing some problems:
when i try to get the rtmp of this channel http://rt.com/on-air :
I get handshake c2 , I follow the tcp and find the rtmp easily.
but when I try to get the rtmp of this channel
http://www.top-al.com/film-aksion.html:
I get handshake c2 , I follow the tcp and didn't find any thing and I get
unknown (0x0)
tried rtmpdump and didn't find any thing too.
any one can help me?
In the last tow days I've been trying to get the rtmp of a TV channel and
I'm using wireshark but I'm facing some problems:
when i try to get the rtmp of this channel http://rt.com/on-air :
I get handshake c2 , I follow the tcp and find the rtmp easily.
but when I try to get the rtmp of this channel
http://www.top-al.com/film-aksion.html:
I get handshake c2 , I follow the tcp and didn't find any thing and I get
unknown (0x0)
tried rtmpdump and didn't find any thing too.
any one can help me?
Sunday, 29 September 2013
Changing the background color of a page
Changing the background color of a page
I am trying to make a command line, where when you type a command, such as
'bg green', the background turns green. Everything works okay except for
when you type 'bg green', and press enter, nothing happens. The background
stays black. This is my code:
<html>
<body style="background-color:black" id="a">
<div style="width:100%;bottom:0px;height:30px;position:absolute;"></div>
<div id="commandline" onkeydown="if (event.keyCode == 13) command(); "
style="-webkit-transform:rotate(0deg);font-family: 'Kelly Slab',
cursive;z-index:2;background-color:black;height:36px;width:100%;bottom:0px;position:absolute;color:white;left:0px;font-size:20px;">
>
<input style="font-family:'Kelly
Slab';color:white;height:100%;width:100%;background-color:black;border:none;position:absolute;font-size:30px;left:20px;top:0px;"
id="cmdinput"></input>
<div id="commands"
style="z-index:1;background-color:black;height:100%;width:100%;bottom:36px;position:absolute;left:0px;"></div>
</body>
</html>
<script type="text/javascript">
function command(){
if(document.getElementById('cmdinput').value.substring(0,9) == "bg green"{
document.getElementById('a').style.backgroundColor = 'green';
}
}
</script>
I think the issue is with the javascript, but I'm not sure. Does anyone
know what the issue is?
I am trying to make a command line, where when you type a command, such as
'bg green', the background turns green. Everything works okay except for
when you type 'bg green', and press enter, nothing happens. The background
stays black. This is my code:
<html>
<body style="background-color:black" id="a">
<div style="width:100%;bottom:0px;height:30px;position:absolute;"></div>
<div id="commandline" onkeydown="if (event.keyCode == 13) command(); "
style="-webkit-transform:rotate(0deg);font-family: 'Kelly Slab',
cursive;z-index:2;background-color:black;height:36px;width:100%;bottom:0px;position:absolute;color:white;left:0px;font-size:20px;">
>
<input style="font-family:'Kelly
Slab';color:white;height:100%;width:100%;background-color:black;border:none;position:absolute;font-size:30px;left:20px;top:0px;"
id="cmdinput"></input>
<div id="commands"
style="z-index:1;background-color:black;height:100%;width:100%;bottom:36px;position:absolute;left:0px;"></div>
</body>
</html>
<script type="text/javascript">
function command(){
if(document.getElementById('cmdinput').value.substring(0,9) == "bg green"{
document.getElementById('a').style.backgroundColor = 'green';
}
}
</script>
I think the issue is with the javascript, but I'm not sure. Does anyone
know what the issue is?
Using XPath in bash with not()
Using XPath in bash with not()
This is follow-up to a previous question about using XPath in bash.
I have a set of XML files, most of which encode relations to other files:
<file>
<fileId>xyz123</fileId>
<fileContents>Blah blah Blah</fileContents>
<relatedFiles>
<otherFile
href='http://sub.domain.abc.edu/directory/index.php?p=collections/pageview&id=123​4'>
<title>Some resource</title>
</otherFile>
<otherFile
href='http://sub.domain.abc.edu/directory/index.php?p=collections/pageview&id=4321'>
<title>Some other resource</title>
</otherFile>
</relatedFiles>
</file>
The answer to the previous question helped me process the majority of
these files successfully. However, there are some files in the set that do
not include any relatedFiles/otherFile elements. I want to be able to
process those files separately and move them into an "other" folder. I
thought I could do this with an XPath not() function, but I get a "command
not found" error for that line when I run the script.
#!/bin/bash
mkdir other
for f in *.xml; do
fid=$(xpath -e '//fileId/text()' "$f" 2>/dev/null)
for uid in $(xpath -e '//otherFile/@href' "$f" 2>/dev/null | awk -F=
'{gsub(/"/,"",$0); print $4}'); do
echo "Moving $f to ${fid:3}_${uid}.xml"
cp "$f" "${fid:3}_${uid}.xml"
done
if $(xpath -e 'not(//otherFile)' "$f" 2>/dev/null); then
echo "Moving $f to other/${fid:3}.xml"
cp "$f" "other/${fid:3}.xml"
fi
rm "$f"
done
How can I filter out files that do not contain certain elements using
XPath in bash? Thanks in advance.
This is follow-up to a previous question about using XPath in bash.
I have a set of XML files, most of which encode relations to other files:
<file>
<fileId>xyz123</fileId>
<fileContents>Blah blah Blah</fileContents>
<relatedFiles>
<otherFile
href='http://sub.domain.abc.edu/directory/index.php?p=collections/pageview&id=123​4'>
<title>Some resource</title>
</otherFile>
<otherFile
href='http://sub.domain.abc.edu/directory/index.php?p=collections/pageview&id=4321'>
<title>Some other resource</title>
</otherFile>
</relatedFiles>
</file>
The answer to the previous question helped me process the majority of
these files successfully. However, there are some files in the set that do
not include any relatedFiles/otherFile elements. I want to be able to
process those files separately and move them into an "other" folder. I
thought I could do this with an XPath not() function, but I get a "command
not found" error for that line when I run the script.
#!/bin/bash
mkdir other
for f in *.xml; do
fid=$(xpath -e '//fileId/text()' "$f" 2>/dev/null)
for uid in $(xpath -e '//otherFile/@href' "$f" 2>/dev/null | awk -F=
'{gsub(/"/,"",$0); print $4}'); do
echo "Moving $f to ${fid:3}_${uid}.xml"
cp "$f" "${fid:3}_${uid}.xml"
done
if $(xpath -e 'not(//otherFile)' "$f" 2>/dev/null); then
echo "Moving $f to other/${fid:3}.xml"
cp "$f" "other/${fid:3}.xml"
fi
rm "$f"
done
How can I filter out files that do not contain certain elements using
XPath in bash? Thanks in advance.
How can i calculate the max value in a polygon?
How can i calculate the max value in a polygon?
I have an image and i used the impoly function to draw a polygon. I would
like to calculate the max value in that polygon and also to receive the
indices of where the value is. It sounds easy but i can't find a function
that does it.
I have an image and i used the impoly function to draw a polygon. I would
like to calculate the max value in that polygon and also to receive the
indices of where the value is. It sounds easy but i can't find a function
that does it.
iOS - How to keep state of View Controller A after switching to View Controller B?
iOS - How to keep state of View Controller A after switching to View
Controller B?
I'm making an application in which I need the map of View Controller A to
be in the same state after switching to View Controller B. However, I do
not know how to switch the view to see the same state? Meaning when I
switch back to View Controller A from View Controller B, I'm under the
impression that I'm required to make a new instance of View Controller A,
and then push that View Controller. However, this means that I lose all of
my instance data from the first time it loads. How do I keep the data from
the first time I'm in that view?
Controller B?
I'm making an application in which I need the map of View Controller A to
be in the same state after switching to View Controller B. However, I do
not know how to switch the view to see the same state? Meaning when I
switch back to View Controller A from View Controller B, I'm under the
impression that I'm required to make a new instance of View Controller A,
and then push that View Controller. However, this means that I lose all of
my instance data from the first time it loads. How do I keep the data from
the first time I'm in that view?
Saturday, 28 September 2013
g++ cannot find my library
g++ cannot find my library
I'm trying to write a makefile that links my objects. It successfully has
made a dynamic library lib/libunittest.so - It's class name was
UnitTest.cpp. When I try to link my mainDriver.o with it it complains:
g++ -fPIC -o bin/mainDriver obj/mainDriver.o -Llib -lunittest
Error: cannot find -lunittest
Note: I'm doing this on cygwin. Can someone please help me with this?
I'm trying to write a makefile that links my objects. It successfully has
made a dynamic library lib/libunittest.so - It's class name was
UnitTest.cpp. When I try to link my mainDriver.o with it it complains:
g++ -fPIC -o bin/mainDriver obj/mainDriver.o -Llib -lunittest
Error: cannot find -lunittest
Note: I'm doing this on cygwin. Can someone please help me with this?
Combobox SelectedValue is not accepted, stubborn error
Combobox SelectedValue is not accepted, stubborn error
I have list of Employees table on SQL side, and on C# I have
Add/Update/Remove buttons.
I want to populate combobox with items AND with their values coming from
EmployeeID (SQL side), so I can update/delete them with
combobox.SelectedValue , no matter what the order in combobox is. However
it gives error all the time, and the error comes when I populate combobox
with text and value.
InvalidArgument=Value of '1' is not valid for 'index'.
This is the full code below. Please tell me codes to replace, and not
opinion or feedback.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
using System.Data.SqlClient;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
string path;
SqlConnection cnn = new SqlConnection("Initial
Catalog=randomcompany;Data Source=localhost;Integrated
Security=SSPI;");
public Form1()
{
InitializeComponent();
}
void temizle()
{
textBox1.Text = "";
textBox2.Text = "";
pictureBox1.Image = null;
comboBox1.SelectedIndex = -1;
comboBox1.Items.Clear();
button1.Enabled = true;
button4.Enabled = false;
cnn.Open();
SqlCommand cmd = new SqlCommand("SELECT
EmployeeID,EmployeeFirstName,EmployeeLastName FROM Employees",
cnn);
SqlDataReader dr = cmd.ExecuteReader();
if (dr.HasRows)
{
while (dr.Read())
{
comboBox1.Items.Insert(dr.GetInt32(0), dr.GetString(1)
+ dr.GetString(2) );
}
}
cnn.Close();
}
private void Form1_Load(object sender, EventArgs e)
{
temizle();
}
private void button3_Click_2(object sender, EventArgs e)
{
temizle();
}
private void button2_Click(object sender, EventArgs e) //Browse
button
{
try
{
OpenFileDialog dlg = new OpenFileDialog();
dlg.Filter = "Images
(*.BMP;*.JPG;*.GIF)|*.BMP;*.JPG;*.GIF|" + "All files
(*.*)|*.*";
dlg.Title = "Select Employee Picture";
if (dlg.ShowDialog() == DialogResult.OK)
{
pictureBox1.Image =
System.Drawing.Image.FromFile(dlg.FileName);
pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
path = dlg.FileName;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void button1_Click(object sender, EventArgs e) //insert item
{
try
{
cnn.Open();
Byte[] imagedata = File.ReadAllBytes(path);
SqlCommand cmd = new SqlCommand("INSERT INTO Employees
(EmployeeFirstname, EmployeeLastname, EmployeePhoto)
VALUES (@item1,@item2,@img)", cnn);
cmd.Parameters.AddWithValue("@item1", textBox1.Text);
cmd.Parameters.AddWithValue("@item2", textBox2.Text);
cmd.Parameters.AddWithValue("@img", imagedata);
cmd.ExecuteNonQuery();
cnn.Close();
MessageBox.Show("Success!!");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
temizle();
}
private void comboBox1_SelectedIndexChanged(object sender,
EventArgs e) //when combobox item is selected
{
button1.Enabled = false;
button4.Enabled = true;
try
{
cnn.Open();
SqlCommand cmd = new SqlCommand("SELECT
EmployeeFirstName,EmployeeLastName,EmployeePhoto FROM
Employees WHERE EmployeeID = @myvalue", cnn);
cmd.Parameters.AddWithValue("@myvalue",
(comboBox1.SelectedValue));
SqlDataReader dr = cmd.ExecuteReader();
if (dr.HasRows)
{
while (dr.Read())
{
textBox1.Text = dr.GetString(0);
textBox2.Text = dr.GetString(1);
byte[] img = (byte[])(dr[2]);
if (img == null)
{
pictureBox1.Image = null;
}
else
{
MemoryStream ms = new MemoryStream(img);
pictureBox1.Image = Image.FromStream(ms);
pictureBox1.SizeMode =
PictureBoxSizeMode.StretchImage;
}
}
}
cnn.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void button4_Click(object sender, EventArgs e) //update item
{
try
{
cnn.Open();
SqlCommand cmd = new SqlCommand("UPDATE Employees SET
EmployeeFirstName = @item1,EmployeeLastName = @item2 WHERE
EmployeeID = @myvalue", cnn);
cmd.Parameters.AddWithValue("@myvalue",
comboBox1.SelectedValue);
cmd.Parameters.AddWithValue("@item1", textBox1.Text);
cmd.Parameters.AddWithValue("@item2", textBox2.Text);
cmd.ExecuteNonQuery();
cnn.Close();
MessageBox.Show("Successfully updated");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
temizle();
}
private void button3_Click(object sender, EventArgs e)
{
}
private void button3_Click_1(object sender, EventArgs e)
{
}
private void button5_Click(object sender, EventArgs e)
{
}
}
}
I have list of Employees table on SQL side, and on C# I have
Add/Update/Remove buttons.
I want to populate combobox with items AND with their values coming from
EmployeeID (SQL side), so I can update/delete them with
combobox.SelectedValue , no matter what the order in combobox is. However
it gives error all the time, and the error comes when I populate combobox
with text and value.
InvalidArgument=Value of '1' is not valid for 'index'.
This is the full code below. Please tell me codes to replace, and not
opinion or feedback.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
using System.Data.SqlClient;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
string path;
SqlConnection cnn = new SqlConnection("Initial
Catalog=randomcompany;Data Source=localhost;Integrated
Security=SSPI;");
public Form1()
{
InitializeComponent();
}
void temizle()
{
textBox1.Text = "";
textBox2.Text = "";
pictureBox1.Image = null;
comboBox1.SelectedIndex = -1;
comboBox1.Items.Clear();
button1.Enabled = true;
button4.Enabled = false;
cnn.Open();
SqlCommand cmd = new SqlCommand("SELECT
EmployeeID,EmployeeFirstName,EmployeeLastName FROM Employees",
cnn);
SqlDataReader dr = cmd.ExecuteReader();
if (dr.HasRows)
{
while (dr.Read())
{
comboBox1.Items.Insert(dr.GetInt32(0), dr.GetString(1)
+ dr.GetString(2) );
}
}
cnn.Close();
}
private void Form1_Load(object sender, EventArgs e)
{
temizle();
}
private void button3_Click_2(object sender, EventArgs e)
{
temizle();
}
private void button2_Click(object sender, EventArgs e) //Browse
button
{
try
{
OpenFileDialog dlg = new OpenFileDialog();
dlg.Filter = "Images
(*.BMP;*.JPG;*.GIF)|*.BMP;*.JPG;*.GIF|" + "All files
(*.*)|*.*";
dlg.Title = "Select Employee Picture";
if (dlg.ShowDialog() == DialogResult.OK)
{
pictureBox1.Image =
System.Drawing.Image.FromFile(dlg.FileName);
pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
path = dlg.FileName;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void button1_Click(object sender, EventArgs e) //insert item
{
try
{
cnn.Open();
Byte[] imagedata = File.ReadAllBytes(path);
SqlCommand cmd = new SqlCommand("INSERT INTO Employees
(EmployeeFirstname, EmployeeLastname, EmployeePhoto)
VALUES (@item1,@item2,@img)", cnn);
cmd.Parameters.AddWithValue("@item1", textBox1.Text);
cmd.Parameters.AddWithValue("@item2", textBox2.Text);
cmd.Parameters.AddWithValue("@img", imagedata);
cmd.ExecuteNonQuery();
cnn.Close();
MessageBox.Show("Success!!");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
temizle();
}
private void comboBox1_SelectedIndexChanged(object sender,
EventArgs e) //when combobox item is selected
{
button1.Enabled = false;
button4.Enabled = true;
try
{
cnn.Open();
SqlCommand cmd = new SqlCommand("SELECT
EmployeeFirstName,EmployeeLastName,EmployeePhoto FROM
Employees WHERE EmployeeID = @myvalue", cnn);
cmd.Parameters.AddWithValue("@myvalue",
(comboBox1.SelectedValue));
SqlDataReader dr = cmd.ExecuteReader();
if (dr.HasRows)
{
while (dr.Read())
{
textBox1.Text = dr.GetString(0);
textBox2.Text = dr.GetString(1);
byte[] img = (byte[])(dr[2]);
if (img == null)
{
pictureBox1.Image = null;
}
else
{
MemoryStream ms = new MemoryStream(img);
pictureBox1.Image = Image.FromStream(ms);
pictureBox1.SizeMode =
PictureBoxSizeMode.StretchImage;
}
}
}
cnn.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void button4_Click(object sender, EventArgs e) //update item
{
try
{
cnn.Open();
SqlCommand cmd = new SqlCommand("UPDATE Employees SET
EmployeeFirstName = @item1,EmployeeLastName = @item2 WHERE
EmployeeID = @myvalue", cnn);
cmd.Parameters.AddWithValue("@myvalue",
comboBox1.SelectedValue);
cmd.Parameters.AddWithValue("@item1", textBox1.Text);
cmd.Parameters.AddWithValue("@item2", textBox2.Text);
cmd.ExecuteNonQuery();
cnn.Close();
MessageBox.Show("Successfully updated");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
temizle();
}
private void button3_Click(object sender, EventArgs e)
{
}
private void button3_Click_1(object sender, EventArgs e)
{
}
private void button5_Click(object sender, EventArgs e)
{
}
}
}
how to define multiple languages in html 4
how to define multiple languages in html 4
I want to build my website in Hebrew lang.
When I write
<meta charset="utf-8">
in the title the labels are looks good but the letters from the DB are all
question mark - "????"
When I write
<meta charset="windows-1255">
letters from DB are OK but all labels are "???".
BTW - I'm also use this code after connecting to the DB:
mysql_query("SET NAMES 'hebrew'");
setlocale(LC_ALL, 'he');
how can I fix that?
I want to build my website in Hebrew lang.
When I write
<meta charset="utf-8">
in the title the labels are looks good but the letters from the DB are all
question mark - "????"
When I write
<meta charset="windows-1255">
letters from DB are OK but all labels are "???".
BTW - I'm also use this code after connecting to the DB:
mysql_query("SET NAMES 'hebrew'");
setlocale(LC_ALL, 'he');
how can I fix that?
The pattern value under Rules in Yii, why stars with "/" and ends with "/u"?
The pattern value under Rules in Yii, why stars with "/" and ends with "/u"?
I am analyzing some regex concepts basics, we all know '^' symbol used in
beginning of expression starts with some value and '$' used in the end for
expression ends with certain value and if they are used together '^exp$'
it can be matched only by exp. But in Yii while declaring rules like
For allowing only numbers we give
public function rules()
{ array('value', 'match', 'pattern' =>
'/^[0-9-]+$/u','message' => "Incorrect symbols (A-z) ."), }
I just want to know why we are using that trailing "/u" and "/" leading in
our rules. Thanks friends.
I am analyzing some regex concepts basics, we all know '^' symbol used in
beginning of expression starts with some value and '$' used in the end for
expression ends with certain value and if they are used together '^exp$'
it can be matched only by exp. But in Yii while declaring rules like
For allowing only numbers we give
public function rules()
{ array('value', 'match', 'pattern' =>
'/^[0-9-]+$/u','message' => "Incorrect symbols (A-z) ."), }
I just want to know why we are using that trailing "/u" and "/" leading in
our rules. Thanks friends.
Subscribe to:
Posts (Atom)