How to Works with files in different format like csv, xlsx,json,google
docs using Node.js
I am new in Node.js development and i don't know how to import files in
different file formats like: csv, json, excel, google doc from different
sources like url,google docs, local drive using Node.js. Any help related
to this will be appreciated Thanks.
Thursday, 3 October 2013
Wednesday, 2 October 2013
What is the great advantage in "migrations" used by many PHP frameworks?
What is the great advantage in "migrations" used by many PHP frameworks?
Many PHP frameworks (becoming from Ruby) have the ability to use
"migrations" and "seeding".
An example is Laravel Framework that have a documentation about that.
But I can't figure out how can it be useful.
Many PHP frameworks (becoming from Ruby) have the ability to use
"migrations" and "seeding".
An example is Laravel Framework that have a documentation about that.
But I can't figure out how can it be useful.
junit: another pattern to test exception
junit: another pattern to test exception
I work on a project with many "BusinessException" that embedded errorCode.
In every unit test for exception, I have to test these error code
repeating this kind of pattern :
@Test
public void
zipFileReaderCtorShouldThrowAnExceptionWithInexistingArchive() {
try {
zfr = new ZipFileReader("unexpected/path/to/file");
fail("'BusinessZipException' not throwed");
} catch (BusinessZipException e) {
assertThat("Unexpected error code", e.getErrorCode(),
is(ErrorCode.FILE_NOT_FOUND));
} catch (Exception e) {
fail("Unexpected Exception: '" + e + "', expected:
'BusinessZipException'");
}
}
(use of junit annotation is impossible due to error code testing)
I was boring to do this, particularly because I had to copy/paste
exception name in fail()'s error message.
So, I wrote a Util class. I use an abstract class to handle exception
assert testing.
public abstract class TestExceptionUtil {
public void runAndExpectException(Class expectedException, String
expectedErrorCode) {
String failUnexpectedExceptionMessage = "Unexpected exception.
Expected is: '%s', but got: '%s'";
try {
codeToExecute();
fail("'" + expectedException.getName() + "' not throwed");
} catch (BusinessException e) {
if (e.getClass().equals(expectedException)) {
assertThat("Exception error code not expected",
e.getErrorCode(), is(expectedErrorCode));
} else {
fail(String.format(failUnexpectedExceptionMessage,
expectedException.getName(), e));
}
} catch (Exception e) {
fail(String.format(failUnexpectedExceptionMessage,
expectedException.getName(), e));
}
}
abstract public void codeToExecute();
}
Then, client use it in this way :
@Test
public void
zipFileReaderCtorShouldThrowAnExceptionWithInexistingArchive() {
new TestExceptionUtil() {
@Override
public void codeToExecute() {
zfr = new ZipFileReader("unexpected/path/to/file");
}
}.runAndExpectException(BusinessTechnicalException.class,
ErrorCode.FILE_NOT_FOUND);
}
Do you think it's "clean" ? Do you think it can be ameliorated ? Do you
think it's too heavy and/or useless ? My primary objective is to
uniformize testing exception in our dev team. (and of course factorize
code)
Thanks for reading !
I work on a project with many "BusinessException" that embedded errorCode.
In every unit test for exception, I have to test these error code
repeating this kind of pattern :
@Test
public void
zipFileReaderCtorShouldThrowAnExceptionWithInexistingArchive() {
try {
zfr = new ZipFileReader("unexpected/path/to/file");
fail("'BusinessZipException' not throwed");
} catch (BusinessZipException e) {
assertThat("Unexpected error code", e.getErrorCode(),
is(ErrorCode.FILE_NOT_FOUND));
} catch (Exception e) {
fail("Unexpected Exception: '" + e + "', expected:
'BusinessZipException'");
}
}
(use of junit annotation is impossible due to error code testing)
I was boring to do this, particularly because I had to copy/paste
exception name in fail()'s error message.
So, I wrote a Util class. I use an abstract class to handle exception
assert testing.
public abstract class TestExceptionUtil {
public void runAndExpectException(Class expectedException, String
expectedErrorCode) {
String failUnexpectedExceptionMessage = "Unexpected exception.
Expected is: '%s', but got: '%s'";
try {
codeToExecute();
fail("'" + expectedException.getName() + "' not throwed");
} catch (BusinessException e) {
if (e.getClass().equals(expectedException)) {
assertThat("Exception error code not expected",
e.getErrorCode(), is(expectedErrorCode));
} else {
fail(String.format(failUnexpectedExceptionMessage,
expectedException.getName(), e));
}
} catch (Exception e) {
fail(String.format(failUnexpectedExceptionMessage,
expectedException.getName(), e));
}
}
abstract public void codeToExecute();
}
Then, client use it in this way :
@Test
public void
zipFileReaderCtorShouldThrowAnExceptionWithInexistingArchive() {
new TestExceptionUtil() {
@Override
public void codeToExecute() {
zfr = new ZipFileReader("unexpected/path/to/file");
}
}.runAndExpectException(BusinessTechnicalException.class,
ErrorCode.FILE_NOT_FOUND);
}
Do you think it's "clean" ? Do you think it can be ameliorated ? Do you
think it's too heavy and/or useless ? My primary objective is to
uniformize testing exception in our dev team. (and of course factorize
code)
Thanks for reading !
Does knockout perform model binding asynchronously? if so, how do I prevent it?
Does knockout perform model binding asynchronously? if so, how do I
prevent it?
In the following code I am updating my knockout model property
SearchResults, and then I am recomputing the size of all the columns in my
html. I know the _resizeColumns function works correctly. However it is
being run before the DOM has been updated with the search results. I have
verified that _resizeColumns is being called by updating the
background-color on all divs with yellow. The divs that existed prior to
the model update are getting set to yellow, but the search results are
not.
$.ajax({
type: 'POST',
url: 'foo.com',
data: postData,
contentType: 'application/json; charset=utf-8',
dataType: 'json',
processData: true,
success: function(data) {
model.SearchResults(data.d); // updates the DOM with the search
results via knockout.js
_resizeColumns(); // does not resize the columns because
they haven't been added to the DOM yet
},
error: function() { alert('error'); }
});
The search results do get added to the DOM, it is just after my call to
_resizeColumns
prevent it?
In the following code I am updating my knockout model property
SearchResults, and then I am recomputing the size of all the columns in my
html. I know the _resizeColumns function works correctly. However it is
being run before the DOM has been updated with the search results. I have
verified that _resizeColumns is being called by updating the
background-color on all divs with yellow. The divs that existed prior to
the model update are getting set to yellow, but the search results are
not.
$.ajax({
type: 'POST',
url: 'foo.com',
data: postData,
contentType: 'application/json; charset=utf-8',
dataType: 'json',
processData: true,
success: function(data) {
model.SearchResults(data.d); // updates the DOM with the search
results via knockout.js
_resizeColumns(); // does not resize the columns because
they haven't been added to the DOM yet
},
error: function() { alert('error'); }
});
The search results do get added to the DOM, it is just after my call to
_resizeColumns
Java: I can't override toString() properly to print an arraylist when there's different classes involved
Java: I can't override toString() properly to print an arraylist when
there's different classes involved
This is hard to describe well but I'll do the best I can. I have an
arraylist of objects. Inside those objects are attributes. Instead of
everything inside one class, they are all separate classes. This is the
first time I'm working with stuff like this and I'm not sure if I got the
syntax right. I'm trying to make println print out the stuff inside the
arraylist and not bytecode.
//main.java
public class Main {
public static void main(String[] args) {
world w = new world();
}
}
//world.java
public class world {
ArrayList<object> list = new ArrayList<>;
public void makeObjectA{
list.add(new ObjectA())
}
public void makeObjectB{
list.add(new ObjectB())
}
@Override public String toString () {
ObjectA obja = new ObjectA();
ObjectB objb = new ObjectB();
return "A: " + obja.getattra() + ", B: " + objb.getattrb();
}
System.out.println(list);
}
//ObjectA.java
public class ObjectA extends world {
private int attra = 10;
public int getattra() {
return attra;
}
public void setattra(int attra) {
this.attra = attra;
}
}
//ObjectB.java
public class ObjectB extends world {
private String attrab = "Ten";
public String getattrb() {
return attrb;
}
public void setattrb(String attrb) {
this.attrb = attrb;
}
}
The output prints out bytecode. I'm not sure what I'm doing wrong
(probably the syntax everywhere). Help please?
there's different classes involved
This is hard to describe well but I'll do the best I can. I have an
arraylist of objects. Inside those objects are attributes. Instead of
everything inside one class, they are all separate classes. This is the
first time I'm working with stuff like this and I'm not sure if I got the
syntax right. I'm trying to make println print out the stuff inside the
arraylist and not bytecode.
//main.java
public class Main {
public static void main(String[] args) {
world w = new world();
}
}
//world.java
public class world {
ArrayList<object> list = new ArrayList<>;
public void makeObjectA{
list.add(new ObjectA())
}
public void makeObjectB{
list.add(new ObjectB())
}
@Override public String toString () {
ObjectA obja = new ObjectA();
ObjectB objb = new ObjectB();
return "A: " + obja.getattra() + ", B: " + objb.getattrb();
}
System.out.println(list);
}
//ObjectA.java
public class ObjectA extends world {
private int attra = 10;
public int getattra() {
return attra;
}
public void setattra(int attra) {
this.attra = attra;
}
}
//ObjectB.java
public class ObjectB extends world {
private String attrab = "Ten";
public String getattrb() {
return attrb;
}
public void setattrb(String attrb) {
this.attrb = attrb;
}
}
The output prints out bytecode. I'm not sure what I'm doing wrong
(probably the syntax everywhere). Help please?
Tuesday, 1 October 2013
Connection with PDO using Bind Value not working
Connection with PDO using Bind Value not working
I have the following connection which was working fine, but I want to
include userID column from the table in a new variable:
public function userLogin()
{
$success = false;
try {
$con = new PDO( DB_DSN, DB_USERNAME, DB_PASSWORD );
$con->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
$sql = "SELECT * FROM users WHERE username = :username AND
password = :password LIMIT 1";
$stmt = $con->prepare( $sql );
$stmt->bindValue( "username", $this->username, PDO::PARAM_STR );
$stmt->bindValue( "password", hash("sha256", $this->password .
$this->salt), PDO::PARAM_STR );
$stmt->bindValue( "UserID", $this->userID, PDO::PARAM_STR );
$stmt->execute();
$valid = $stmt->fetchColumn();
if( $valid ) {
$success = true;
}
$con = null;
return $success;
when I added my new line $stmt->bindValue( "UserID", $this->userID,
PDO::PARAM_STR );
it says error: SQLSTATE[HY093]: Invalid parameter number: number of bound
variables does not match number of tokens
where might be the problem ?
I have the following connection which was working fine, but I want to
include userID column from the table in a new variable:
public function userLogin()
{
$success = false;
try {
$con = new PDO( DB_DSN, DB_USERNAME, DB_PASSWORD );
$con->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
$sql = "SELECT * FROM users WHERE username = :username AND
password = :password LIMIT 1";
$stmt = $con->prepare( $sql );
$stmt->bindValue( "username", $this->username, PDO::PARAM_STR );
$stmt->bindValue( "password", hash("sha256", $this->password .
$this->salt), PDO::PARAM_STR );
$stmt->bindValue( "UserID", $this->userID, PDO::PARAM_STR );
$stmt->execute();
$valid = $stmt->fetchColumn();
if( $valid ) {
$success = true;
}
$con = null;
return $success;
when I added my new line $stmt->bindValue( "UserID", $this->userID,
PDO::PARAM_STR );
it says error: SQLSTATE[HY093]: Invalid parameter number: number of bound
variables does not match number of tokens
where might be the problem ?
Matching specific Apache VirtualHost with regex
Matching specific Apache VirtualHost with regex
I am currently attempting to match a single Apache VirtualHost entry
within an apache config file by the ServerName of the VirtualHost. I am
doing this with python, using the re module.
Here's an example of the type of file that I am working with:
<VirtualHost *:8000>
DocumentRoot "/path/to/dir1"
ServerName eg1.dev
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/path/to/docroot"
ServerName desired.dev
</VirtualHost>
<VirtualHost *:8080>
DocumentRoot "/path/to/dir3"
ServerName eg2.dev
</VirtualHost>
I want to match the VirtualHost with a ServerName of desired.dev. So the
match I am aiming for is:
<VirtualHost *:80>
DocumentRoot "/path/to/docroot"
ServerName desired.dev
</VirtualHost>
I assumed this would be fairly simple with a regex but I can't figure out
how to do it. I currently have:
<VirtualHost \*:[0-9]*>.*?ServerName +desired.dev.*?</VirtualHost>
But the issue with this being that it matches the very first
<VirtualHost..., matches the ServerName and stops matching at the end of
the closing tag of the desired VirtualHost.
I'm aware that there are probably python modules for parsing Apache config
files but I do not wish to use anything from outside of the standard
library. If attempting this with regex is a terrible idea, are there any
alternatives?
I am currently attempting to match a single Apache VirtualHost entry
within an apache config file by the ServerName of the VirtualHost. I am
doing this with python, using the re module.
Here's an example of the type of file that I am working with:
<VirtualHost *:8000>
DocumentRoot "/path/to/dir1"
ServerName eg1.dev
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/path/to/docroot"
ServerName desired.dev
</VirtualHost>
<VirtualHost *:8080>
DocumentRoot "/path/to/dir3"
ServerName eg2.dev
</VirtualHost>
I want to match the VirtualHost with a ServerName of desired.dev. So the
match I am aiming for is:
<VirtualHost *:80>
DocumentRoot "/path/to/docroot"
ServerName desired.dev
</VirtualHost>
I assumed this would be fairly simple with a regex but I can't figure out
how to do it. I currently have:
<VirtualHost \*:[0-9]*>.*?ServerName +desired.dev.*?</VirtualHost>
But the issue with this being that it matches the very first
<VirtualHost..., matches the ServerName and stops matching at the end of
the closing tag of the desired VirtualHost.
I'm aware that there are probably python modules for parsing Apache config
files but I do not wish to use anything from outside of the standard
library. If attempting this with regex is a terrible idea, are there any
alternatives?
Ubuntu kernel question
Ubuntu kernel question
Since Ubuntu is officially supported on Nexus, does it use the Nexus
kernel or does Ubuntu use its own (or modified) kernel? I am a dev and am
looking to port this to my low end phone. Thx
Since Ubuntu is officially supported on Nexus, does it use the Nexus
kernel or does Ubuntu use its own (or modified) kernel? I am a dev and am
looking to port this to my low end phone. Thx
Why did Christopher Columbus think he had arrived near Japan=?iso-8859-1?Q?=3F_=96_history.stackexchange.com?=
Why did Christopher Columbus think he had arrived near Japan? –
history.stackexchange.com
This question came to our mind as a long discussion in chat between some
users over ELU including me and we thought to post the question here.
Wikipedia states he thought he had arrived Japan. In …
history.stackexchange.com
This question came to our mind as a long discussion in chat between some
users over ELU including me and we thought to post the question here.
Wikipedia states he thought he had arrived Japan. In …
Subscribe to:
Posts (Atom)