How to get user info from mongodb in node.js
Totally new to mongo, I've been checking examples for hours, Trying to
check if a user exists in this collection:
{ "name" : "chrispy", "pass" : "xxxx", "_id" :
ObjectId("5221b29b69f9e9b11a000001") }
But cannot match name and get the results, ive tried numerous examples,
and no luck. onRegister is called and data.name and data.password are
filled. Once I can match the name, I'll match the password. but cant even
get as far as matching the user name. console.log doesn't get called
either. Help = 1000 thankyou's!
function onRegister(data) {
var name,pass;
name = data.name;
pass = data.pass;
Mongo.connect('mongodb://127.0.0.1:27017/main', function(err, db) {
if(err) throw err;
var collection = db.collection('users');
// check if user exists
var doc = collection.findOne({'name' : name}, function(err,doc){
if(err) throw err;
if(doc) {
var myName = doc.name;
console.log("doc.name "+tojson(myName)+ " name "+name); //
never called even when name is correct
if(tojson(myName) == name) {
// now check password, but runtime never gets here
}
} else {
// runtime never gets here either
}
});
}
Saturday, 31 August 2013
How to protect intellectual property while writing software in Python
How to protect intellectual property while writing software in Python
If I use C/C++ to write a piece of proprietary software, then I compile
the sources and I only distribute the binaries and/or libraries.
However Python is a interpreted language and thus you run the software
directly from source. How can I protect intellectual property while
writing software in Python?
If I use C/C++ to write a piece of proprietary software, then I compile
the sources and I only distribute the binaries and/or libraries.
However Python is a interpreted language and thus you run the software
directly from source. How can I protect intellectual property while
writing software in Python?
Friday, 30 August 2013
How do I create a prepared statement?
How do I create a prepared statement?
I cannot find any documentation that adequately explains how to use them.
How to you retrieve variables from a query and use them and what do the
parameters mean to the queries? I want to make my website safe from sql
injection and I don't have a clue how to get the following code optimized
for safety. I understand how sql injection works, I just don't know how to
create the prepared statements or retrieve queries.
<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
$tempProf = $_POST["professor"];
$tempProfArray = explode("=",$tempProf);
$prof = $tempProfArray[1];
$tempName = $_POST["name"];
$tempNameArray = explode("=",$tempName);
$name = $tempNameArray[1];
$tempNum = $_POST["number"];
$tempNumArray = explode("=",$tempNum);
$num = $tempNumArray[1];
$tempSec = $_POST["section"];
$tempSecArray = explode("=",$tempSec);
$section = $tempSecArray[1];
$tempCat = $_POST["category"];
$tempCatArray = explode("=",$tempCat);
$category = $tempCatArray[1];
$con=mysqli_connect("localhost","root","ashlyn","studyBuddy");
$result = mysqli_query($con,"SELECT * FROM professors where id='$prof'");
$row = mysqli_fetch_array($result);
if(empty($prof) || empty($name) || empty($num) || empty($section) ||
empty($category))
{
echo "emptyField";
}
elseif(!is_numeric($num) || !is_numeric($section))
{
echo "NaN";
}
elseif(empty($row))
{
mysqli_query($con,"INSERT INTO classes (className, classNumber,
section, classCategory)
VALUES ('$name','$num','$section','$category')");
$classTemp = mysqli_query($con,"SELECT id FROM classes where
className='$name' and classNumber='$num' and section ='$section'");
$classTempArray = mysqli_fetch_array($classTemp);
$classId = $classTempArray['id'];
mysqli_query($con,"INSERT INTO professors (name, classes) VALUES
('$prof','$classId')");
$profTemp = mysqli_query($con,"SELECT id FROM professors where
name='$prof'");
$profTempArray = mysqli_fetch_array($profTemp);
$profId = $profTempArray['id'];
mysqli_query($con,"UPDATE classes SET professor = '$profId' WHERE id =
'$classId'");
echo "success";
}
else
{
$profName = $row['id'];
mysqli_query($con,"INSERT INTO classes (professor, className,
classNumber, section, classCategory)
VALUES ('$prof', '$name','$num','$section','$category')");
echo "success";
}
?>
I cannot find any documentation that adequately explains how to use them.
How to you retrieve variables from a query and use them and what do the
parameters mean to the queries? I want to make my website safe from sql
injection and I don't have a clue how to get the following code optimized
for safety. I understand how sql injection works, I just don't know how to
create the prepared statements or retrieve queries.
<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
$tempProf = $_POST["professor"];
$tempProfArray = explode("=",$tempProf);
$prof = $tempProfArray[1];
$tempName = $_POST["name"];
$tempNameArray = explode("=",$tempName);
$name = $tempNameArray[1];
$tempNum = $_POST["number"];
$tempNumArray = explode("=",$tempNum);
$num = $tempNumArray[1];
$tempSec = $_POST["section"];
$tempSecArray = explode("=",$tempSec);
$section = $tempSecArray[1];
$tempCat = $_POST["category"];
$tempCatArray = explode("=",$tempCat);
$category = $tempCatArray[1];
$con=mysqli_connect("localhost","root","ashlyn","studyBuddy");
$result = mysqli_query($con,"SELECT * FROM professors where id='$prof'");
$row = mysqli_fetch_array($result);
if(empty($prof) || empty($name) || empty($num) || empty($section) ||
empty($category))
{
echo "emptyField";
}
elseif(!is_numeric($num) || !is_numeric($section))
{
echo "NaN";
}
elseif(empty($row))
{
mysqli_query($con,"INSERT INTO classes (className, classNumber,
section, classCategory)
VALUES ('$name','$num','$section','$category')");
$classTemp = mysqli_query($con,"SELECT id FROM classes where
className='$name' and classNumber='$num' and section ='$section'");
$classTempArray = mysqli_fetch_array($classTemp);
$classId = $classTempArray['id'];
mysqli_query($con,"INSERT INTO professors (name, classes) VALUES
('$prof','$classId')");
$profTemp = mysqli_query($con,"SELECT id FROM professors where
name='$prof'");
$profTempArray = mysqli_fetch_array($profTemp);
$profId = $profTempArray['id'];
mysqli_query($con,"UPDATE classes SET professor = '$profId' WHERE id =
'$classId'");
echo "success";
}
else
{
$profName = $row['id'];
mysqli_query($con,"INSERT INTO classes (professor, className,
classNumber, section, classCategory)
VALUES ('$prof', '$name','$num','$section','$category')");
echo "success";
}
?>
Thursday, 29 August 2013
Is Object memory freed when we explicitly call finalize() on it?
Is Object memory freed when we explicitly call finalize() on it?
As far as my understanding goes finalize() and GC are two different
aspects. GC uses finalize() method to free Object memory. We cannot state
when GC will occur(even if we explicitly call System.gc()). But we can
explicitly call finalize() on an Object.
Will the function be executed immediately(memory freed) or it waits till GC
occurs like System.gc() call?
Also as per the docs the finalize method is never invoked more than once
by a Java virtual machine for any given object.
So what happens when we call finalize() first and GC happens at a later
point of time.
If object memory is not freed on explicit call to object.finalize() then
would't
it being called again in the GC process violate the calling only once rule?
As far as my understanding goes finalize() and GC are two different
aspects. GC uses finalize() method to free Object memory. We cannot state
when GC will occur(even if we explicitly call System.gc()). But we can
explicitly call finalize() on an Object.
Will the function be executed immediately(memory freed) or it waits till GC
occurs like System.gc() call?
Also as per the docs the finalize method is never invoked more than once
by a Java virtual machine for any given object.
So what happens when we call finalize() first and GC happens at a later
point of time.
If object memory is not freed on explicit call to object.finalize() then
would't
it being called again in the GC process violate the calling only once rule?
Wednesday, 28 August 2013
Unconfigure Exchange from accepting mail for multiple domains
Unconfigure Exchange from accepting mail for multiple domains
For some time my company (A) hosted the email (Exchange 2010) for another
company (B).
Company B has moved their email to another hosted solution. That went
smooth. They are getting their email on the new system. Their mailboxes
are still on our server but mail isn't being delivered there so those
mailboxes are just sitting there. (until I do something with them)
However whenever I try to send an email from A.com to B.com it is being
delivered to the mailbox hosted on my Exchange server and not the new
server they're using. I've removed B.com as an Accepted Domain and the
associated E-mail Address Policies for B.com. What am I missing? Have I
done something wrong?
How do I make it so I can send mail from A.com to B.com and it arrive in
B.com's users' mailbox on their new setup? Thanks.
For some time my company (A) hosted the email (Exchange 2010) for another
company (B).
Company B has moved their email to another hosted solution. That went
smooth. They are getting their email on the new system. Their mailboxes
are still on our server but mail isn't being delivered there so those
mailboxes are just sitting there. (until I do something with them)
However whenever I try to send an email from A.com to B.com it is being
delivered to the mailbox hosted on my Exchange server and not the new
server they're using. I've removed B.com as an Accepted Domain and the
associated E-mail Address Policies for B.com. What am I missing? Have I
done something wrong?
How do I make it so I can send mail from A.com to B.com and it arrive in
B.com's users' mailbox on their new setup? Thanks.
Flask import error (python)
Flask import error (python)
Trying to import flask but I get the error:
ImportError: No module named Flask
after:
import Flask
I just installed it using terminal (Mac OS X):
JoeDangers-MacBookPro:~ joedanger$ $sudo easy_install Flask
Searching for Flask
Best match: Flask 0.10.1
Processing Flask-0.10.1-py2.7.egg
Flask 0.10.1 is already the active version in easy-install.pth
Any thoughts as to why this is not working?
Trying to import flask but I get the error:
ImportError: No module named Flask
after:
import Flask
I just installed it using terminal (Mac OS X):
JoeDangers-MacBookPro:~ joedanger$ $sudo easy_install Flask
Searching for Flask
Best match: Flask 0.10.1
Processing Flask-0.10.1-py2.7.egg
Flask 0.10.1 is already the active version in easy-install.pth
Any thoughts as to why this is not working?
Data object with different language options. Javascript implementation
Data object with different language options. Javascript implementation
I have this weird case when I have to manage a few small texts depending
on page language using javascript. Just imagine you need to replace some
parts of the template depending on html lang attribute. So I created
multidimensional data object and decided to go with the following way
around it. Everything works fine but I feel like it is not the best
practice and maybe I could avoid using switch:
jsbin version: http://jsbin.com/EvEciVa/2/
$(function(){
var lang = $('html').attr('lang'),
text;
var obj = {
'en' : {
'title' : 'Title english',
'url' : 'en.html'
},
'fr' : {
'title' : 'Title french',
'url' : 'fr.html',
}
};
switch(lang){
case'fr':
text = [obj.fr.title,obj.fr.url];
break;
default:
text = [obj.en.title,obj.en.url];
}
$('body').prepend('<a href="'+text[1]+'">'+text[0]+'</a>');
});
The question is: As far as I have the lang attribute value (the language),
maybe I could avoid using switch and duplicate cases, instead I could
implement the lang value as variable to access data object, something like
this [obj.lang.title,obj.lang.url]; Of course it wont work in my case.
I would appreciate any opinion. Thank you.
I have this weird case when I have to manage a few small texts depending
on page language using javascript. Just imagine you need to replace some
parts of the template depending on html lang attribute. So I created
multidimensional data object and decided to go with the following way
around it. Everything works fine but I feel like it is not the best
practice and maybe I could avoid using switch:
jsbin version: http://jsbin.com/EvEciVa/2/
$(function(){
var lang = $('html').attr('lang'),
text;
var obj = {
'en' : {
'title' : 'Title english',
'url' : 'en.html'
},
'fr' : {
'title' : 'Title french',
'url' : 'fr.html',
}
};
switch(lang){
case'fr':
text = [obj.fr.title,obj.fr.url];
break;
default:
text = [obj.en.title,obj.en.url];
}
$('body').prepend('<a href="'+text[1]+'">'+text[0]+'</a>');
});
The question is: As far as I have the lang attribute value (the language),
maybe I could avoid using switch and duplicate cases, instead I could
implement the lang value as variable to access data object, something like
this [obj.lang.title,obj.lang.url]; Of course it wont work in my case.
I would appreciate any opinion. Thank you.
Subscribe to:
Posts (Atom)