Monday, 9 September 2013

Apache's Alias directive is not working as expected

Apache's Alias directive is not working as expected

I am trying to integrate my portal with my website.
My website :
http://example.com
and My portal :
http://portal.com
Now I want to see my portal from :
http://example.com/portal
Part of my core apache config file :
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName example.com
DocumentRoot /home/example/WebSite2.0/WebContent
DirectoryIndex index.php index.html
<Directory /home/example/WebSite2.0/WebContent>
Options +IncludesNOEXEC
AllowOverride None
Order allow,deny
allow from all
XBitHack On
AddType text/html .html
AddHandler server-parsed .html
</Directory>
Alias /portal /home/example/portal/CodeIgniter_2.1.0
<Directory /home/example/portal/CodeIgniter_2.1.0>
DirectoryIndex "index.php"
allow from all
Options +Indexes
#Options FollowSymLinks MultiViews
Order allow,deny
RewriteEngine On
RewriteBase /portal
#RewriteRule ^test\.html$ test.php
RewriteCond $1 !^(index\.php|css|images|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]
RewriteCond $1 ^(css|images|js)
RewriteRule ^(.*)$ $1
</Directory>
</VirtualHost>
As you see my portal functions on top of CodeIgniter; Hence -
RewriteCond $1 !^(index\.php|css|images|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]
Now the real problem is when I open http://example.com/portal the browser
is looking for the images in the DocumentRoot and not in Alias.
e.g. for image from portal,
<img src="/images/example.png" style="margin-left:30px;height:50px;">
apache error log says -
File does not exist: /home/example/WebSite2.0/WebContent/images/example.png
I would hate to make changes to my code. I just want to get this thing
working from the apache config file itself. Please help me do this.

Rails 3.2 has-and-belongs-to-many update association unit test

Rails 3.2 has-and-belongs-to-many update association unit test

In my 'notification' model I have a method (notification and contact
models both has and belongs to many):
def self.update_contact_association(contact, notification) unless contact
== nil notification.contacts.clear c = Contact.find(contact)
notification.contacts << c end end
that updates the association between a specific notification and contact.
It takes a notification object(row) and a list of contact ids. The method
works fine, given a single contact id 1 and a notification with the id of
4 updates the table should and will look like this:
notification_id contact_id 4 1
The problem comes in when trying to write a unit test to properly test
this method. So far I have:
test 'update_contact_association' do notification = Notification.find(4)
contact = Contact.find(1)
Notification.update_contact_association([contact.id], notification) end
Running the test method causes no errors, but the test database is not
updated to look like the above example, it is just blank. I'm pretty sure
I need to use a save or update method to mimic what the controller is
doing, but I'm not sure how. I just need the unit test to properly update
the table so I can go ahead and write my assertions. Any ideas would be
greatly appreciated for I need to test several methods that are very
similar/the same as this one.
Thank you!

Creating array of object in loop in C#?

Creating array of object in loop in C#?

So when i create an object of deck, an exception is shown >
"indexoutofrangeexception was unhandled"
Please help ####
deck.cs >>
public class Deck {
Card[] card = new Card[52];
const int NumOfCards = 52;
public Deck()
{
string[] symbol = { "Diamonds", "Clubs", "Hearts", "Spades"};
string[] rank = { "Ace", "Two", "Three", "Four", "Five", "Six",
"Seven", "Eight", "Nine", "Jack", "Queen", "King"};
for (int i = 0; i < card.Length; ++i)
{
card[i] = new Card(symbol[i / 13], rank[i % 13]); /// this is
the line with problem shown in debug
}
Console.WriteLine(card.Length);
}
public void PrintDeck() {
foreach (Card c in card)
Console.WriteLine(c);
}
}

Convert Decimals to Integers Before Adding, Subtracting, Multiplying or Dividing Them

Convert Decimals to Integers Before Adding, Subtracting, Multiplying or
Dividing Them

I put together a basic calculator where the user can type their equation
into a text box and click solve. Any equation that includes addition,
subtraction, multiplication and/or division can be entered example:
1*2+18/2+(7+2)
The problem is when decimals are used. I've found that there's no simple
solution in JavaScript or jQuery to handle them in the context of a
calculator. Every single JavaScript calculator tutorial doesn't work
correctly with decimals.
I think the best way to handle them is to convert them to integers? I
thought about multiplying the decimals by 100000, doing the math, then
dividing by 100000 but this only works with addition and subtraction. What
method would work to convert decimals to integers when the equation
contains mixed operations such as 1*2+18/2+(1.2 + 0.64) then convert it
back?
Fiddle: http://jsfiddle.net/4F27z/
HTML
<input type="text" id="userProblem" size="100">
<input type="submit" id="solveButton" value="Solve">
<div id="answerDiv"></div>
JavaScript
solveButton.onclick = function () {
var answer = eval(userProblem.value);
answerDiv.innerHTML = answer;
};

Join XML strings pulled from the web using python

Join XML strings pulled from the web using python

I'm trying to join two xml files I'm pulling from the web. I just need the
second XML file to be added at the end of the first. To this this I've
tried to pull the XML from the web, convert them to strings, join them
then create a new tree from the conjoined string.
urls = 'http://www.w3schools.com/xml/guestbook.asp',
'http://www.w3schools.com/xml/guestbook.asp'
for url in urls:
url = url[0]
XML = requests.get(url)
XML_str = XML.content + XML_str
XML_data = ET.fromstring(XML_str)
tree = ET.ElementTree(XML_data)
However when I do this I get the following error.
Error: lxml.etree.XMLSyntaxError: XML declaration allowed only at the
start of the document, line 1, column 326
The XML string looks fine to me and I think the error is realted to there
being two declaratoin lines form each feed (e.g. )
does anyone know a better way to join two XML files being pulled from the
web without writing to disk....?

OpenCV: Memory leak when writing video from webcam using cvWriteFrame

OpenCV: Memory leak when writing video from webcam using cvWriteFrame

I want to record video from webcam using opencv.
I put the following code inside a timer event handler function, which is
called each 50 ms
IplImage *image = cvQueryFrame(camera);
IplImage *resizeImage = cvCreateImage( size, 8, 3);
cvResize(image, resizeImage);
cvWriteFrame(writer, resizeImage );
With writer is created using cvCreateVideoWriter, and the video is created
when I call cvReleaseVideoWriter(&writer)
The problem is I can not release memory allocated by cvWriteFrame until
cvReleaseVideoWriter is called. That makes a big issue when I need record
a long time video.
How can I handle this situation?

mysql - Find page of result record in pagination

mysql - Find page of result record in pagination

imagine that we use pagination to split and display a mysql result like
this, sorted on auto inceremental ID and date:
SELECT name FROM members ORDER BY id DESC, date DESC LIMIT $start, $len
we display that result and page navigation links below it using php.
how we can find that record ID number x is in which page of that result so
we set page number to that page and display that page and end-user do not
need to click navigation and find it?