Because this was annoying to sort out, I’m going to post it here.
I’m sure this has been done many times before, but I wanted something to turn a date time string like ‘2 days and 9 hours ago’ to give the last deployment time on a little git deploy tool I’m working on in my spare time.
Here’s the code…
Now I don’t know for sure (and never will be unless someone wants to keep a browser open for 26 days), but a bit of cross-browser testing tells me 2147483647 is the maximum number supported across browsers.
Even though you’re definitely not interested, its probably because this is the upper limit on a 32-bit signed integer.
This releases address the issue where it would not run unless as an administrator. The problem is it modifies the system registry, and places files for communicator to find which require elevated privileges.
If you had User Access Control (UAC) enabled on Vista or 7, the program wouldn’t work as expected. Now it’s fixed, so permission is requested properly.
Also, I threw together a portable version of Office Communicator Custom Status Editor so an installer is no longer needed. This weighs in at less than 35kb.
Hope it helps another couple of thousand people have custom status or custom presences on Microsoft Office Communicator 2007 R2.
On Ubuntu, its really simple.
# adduser jak sudo
and you’re done!
On CentOS, theres a couple more steps.
As root, run
# /usr/sbin/usermod -aG wheel jak
then edit the /etc/sudoers file
# nano /etc/sudoers
go down and find this…
## Allows people in group wheel to run all commands
# %wheel ALL=(ALL) ALL
and remove the hash in front of %wheel so it looks like…
## Allows people in group wheel to run all commands
%wheel ALL=(ALL) ALL
Once that’s done, your user “jak” is part of the wheel group, who are allowed to use sudo.
Use prepared statements. These are SQL statements that sent to and parsed by the database server separately from any parameters.
If you use PDO you can work with prepared statements like this:$preparedStatement = $db->prepare('SELECT * FROM employees WHERE name = :name');$preparedStatement->execute(array(':name' => $name));$rows = $preparedStatement->fetchAll();
$dbis a PDO object, see the PDO documentation)
What happens is that the SQL statement you pass to
prepareis parsed and compiled by the database server. By specifying parameters (either a
?or a named parameter like
:namein the example above) you tell the database engine where you want to filter on. Then when you call
executethe prepared statement is combined with the parameter values you specify.
The important thing here is that the parameter values are combined with the compiled statement, not a SQL string. SQL injection works by tricking the script into including malicious strings when it creates SQL to send to the database. So by sending the actual SQL separately from the parameters you limit the risk of ending up with something you didn’t intend. Any parameters you send when using a prepared statement will just be treated as strings (although the database engine may do some optimization so parameters may end up as numbers too, of course). In the example above, if the
'Sarah'; DELETE * FROM employeesthe result would simply be a search for the string “‘Sarah’; DELETE * FROM employees”, and you will not end up with an empty table.
Another benefit with using prepared statements is that if you execute the same statement many times in the same session it will only be parsed and compiled once, giving you some speed gains.
Oh, and since you asked about how to do it for an insert, here’s an example:$preparedStatement = $db->prepare('INSERT INTO table (column) VALUES (:column)');$preparedStatement->execute(array(':column' => $unsafeValue));
Backup your fstab file
cp /etc/fstab /etc/fstab.bak
Creating tmpmnt partition file (Around 1Gb in size)
cd /vardd if=/dev/zero of=tmpMnt bs=1024 count=1048576
Format the new partition
mkfs.ext3 -j /var/tmpMnt
Press Y when asked
Making backup of old /tmp
cp -Rp /tmp /tmp_backup
Mount the tmp filesystem
mount -o loop,noexec,nosuid,rw /var/tmpMnt /tmp
Set the right permissions
chmod 0777 /tmp
Copy the files back to new tmp folder
cp -Rp /tmp_backup/* /tmp/
Adding new /tmp filesystem to fstab
echo "/var/tmpMnt /tmp ext3 loop,rw,noexec,nosuid,nodev 0 0" >> /etc/fstab
No need for 2 tmp filesystems, so we symlink /var/tmp to /tmp
rm -rf /var/tmp/ln -s /tmp/ /var/tmp
So you can send a lot of stuff over web services, mostly primitive types, but what if you want to send pictures?
I’m not talking about sending the URL to a picture, but sending the actual image data over a web service, so that the client can display it. It’s really very simple, but also a fun addition. On the Web Service side, you need to take the image and encode it into a primitive type that can be handled through SOAP. To do this, I load the image, then convert its contents into a Base64 encoded string. I can then send this string back to the client.
Very simple! Now on the client side, we simply reverse the process.
Here is a synchronous example, for a better asynchronous example, have a look at my Visual Studio solution. This example is for a Windows form application, with a PictureBox object.
If you encounter errors, regarding the max length of strings, simply update the properties: maxBufferSize maxRecievedMessageSize and maxStringContentLength in the app.config file, and set the value to which 2048000 should be big enough!
You can download a solution folder, with a fully working example here: http://www.jak.cx/downloads/PicturesOverWebServiceTest.zip