I have a node.js application in which I'm using pdfkit to generate pdf documents. I want to be able to include images from a url in the pdf. I cant save the image to the file system because my runtime environment is read only and pdf kit seems to find the images to embed from a file system directory. Is there a way I can use an url in pdf kit to embed an image?
Thursday, April 12, 2012
How is exponentiation by squaring faster?
Suppose you want to calculate 5^65537 instead of multiplying 5 65537 times, it is recommended to do ((5^2)^16)*5. This results in 16 times squaring and one multiplication.
But my question is aren't you not compensating the the number of squaring times by squaring very large numbers? how is this faster when you go down to the basic bit multiplication in computers.
Bison token value overwritten - c memory issues?
Okay I have the following code in Bison .l file. By the way I am new to c.
exp: TK_SLIT // TK_SLIT is a string literal token
/* assigns the type to the nonterminal exp */
$$ ->type = (char *) malloc (strlen ("string") + 1); /* allocates space */
strcpy ($$->type,"string"); /* puts value in there */
printf ("%s\n",$$->type);
printf ("The value of TK_SLIT is - %s\n",$1);
I have figured out that the "assigns type" block of code (4 lines including comment) OVERWRITES the value of TK_SLIT ($1) in memory. The value of TK_SLIT was grabbed from my scanner, FLEX.
I know that the block of code is causing the problem because if I comment out the "assigns type" block of code, then my TK_SLIT token value prints just fine. Otherwise it becomes garbled characters.
Is there something wrong with my malloc? Why is it overwriting my token value? Is this a bison issue where it's not protecting my token values in memory?
"No unexpired provisioning profiles found that contain any of the keychain's signing certificates" Horror
I have seen a few other questions that addressed this topic but none like mine. Yesterday I innocently added a device to the list of devices. I am under the impression that once you add a device, it will now be linked to the provisioning profile. However, I believe it was not linked to one of my distribution profiles. So I went into edit the profile, clicked the checkmark next to the device, and hit submit. This is where the problems began. I notice two things: I recently renewed my certificate/provisioning profiles about a week ago. Now, it thinks I renewed my provisioning profile yesterday ( or at least it says so in the organizer ). Also, when I try to build any project I get the awful "No unexpired provisioning profiles found that contain any of the keychain's signing certificates". In the build settings my signing identity shows up under Identities without provisioning profiles. I have read horror stories of people having to tear everything down and rebuild and I hope I don't have to do that here..
Array of unknown size base on the input file
This is a beginner C++ homework problem, I know about vector, but it is not allowed to use in this assigment. I searched around and I found how to make an array[] of unknown size too. But it is slightly trickly (sort of). The example I read are all along the lines of: get an input, then create the array base on that input (size n).
I have created this student class, but now I need an array to store them. I do not know in advance how many students there are going to be. I only have an input of text file with each student on one line. The format is below, the sample is about 5, but I don't know how many the teacher will use to test my program.
Input file like this:
George Chan Computer_Science New York 23
Johnny Chan Computer_Science New Jersery 22
....
But the problem is I don't know how many students are there until I finish reading the whole text tile (or I don't know if there are other way to do it). My current approach is to read it line by line, increment a counter studentCounter, until I finish, then I create my Student* myRoster = Student[studentCounter]. But then when I have to start reading the file again. And go line by line to parse the information and create a Student object and let a myRoster[x] points to it. I feel like I am sort of doing the work twice just to have the right size. Are there some tricks or things I am missing?
Thank you.
INSERT or UPDATE using IF-ELSE php MYSQL
DONOR
donor-nic----username-----status
111----------ali----------available
222---------usman--------notavailable
another is
DONATION
donation_id------donor_nic-----date---
1----------------111----------2012/03/04
2---------------111-----------2012/06/07
3----------------111---------2012/07/08
4----------------222---------2012/03/03
now i want to update the date if it is already exits corresponding to donor_nic
if date does not exists i want to insert that new date,.
i am using this query to fetching all dates according to corresponding donor_nic
SELECT donor.donor_nic, donation.lastdonationdate
FROM donor
JOIN donation ON donor.donor_nic = donation.donor_nic
WHERE username = 'ali'
GROUP BY donation.lastdonationdate
now this query works in phpmyadmin.. but when i use this in my page.. it does not match date.. i am matching date like this
$sql= SELECT donor.donor_nic, donation.lastdonationdate
FROM donor
JOIN donation ON donor.donor_nic = donation.donor_nic
WHERE username = 'ali'
GROUP BY donation.lastdonationdate
$res=mysql_query($sql, $con);
if($res == $date)
{
echo "update";
}
else
{
echo "insert";
}
but this thing didnt work.. may be i am making mistake in conditional (if-else) statment.. plz help me what should i do..
thanks in advance
How to update a table column based on it's relation to another table?
I have a table called "profiles". There was a column in this table called "user_id" which I have changed the name to "username" and the type from INT(11) to Varchar(255) . However the contents of this column are still numeric ids.
These ids correspond to another table called "users". That table has fields called "user_id" and "username". For each row on the "profiles" table I need to first check to see what the username field has for the id and do a look up on the users table to get the username that correcponds to that id and then update the profile table's username value for with the proper username.
Profiles table:
username | blah blah...
------------------------
1 | ...
Users table:
user_id | username
------------------------
1 | Joe
I need the value for the username field on the profiles table to be updated to "Joe".
I came up with this php script but it stops working after updating just 4 records for some reason:
$sql = 'SELECT username FROM profiles';
$query = mysql_query($sql);
while($row = mysql_fetch_assoc($query)) {
$id = $row['username'];
$sql = 'SELECT username FROM users WHERE user_id = '. $id;
$query = mysql_query($sql);
while($row = mysql_fetch_assoc($query)) {
$sql = "UPDATE profiles SET username = '".$row['username']."' WHERE username = $id";
$query = mysql_query($sql);
if(!$query) {
echo 'error!';
}
}
}
My script isn't all that efficient to begin with, although that's not that big an issue since the table has just 50k records. Anyway what would be a way to do this directly from mysql?