Linux Bash: Append and Prepend Strings to Files

I want to append the string “BYE” to the file test.txt

echo “BYE” >> test.txt

Now, I want to prepend the string “HI” to the file test.txt

echo "HI"|cat - test.txt > /tmp/out && mv /tmp/out test.txt
Posted in Linux Command Line | Leave a comment

Free Icons

http://www.pinvoke.com/

http://www.famfamfam.com/lab/icons/silk/

Posted in Web Design | Leave a comment

POST Request with PHP and with HTTP Authorization

function POSTReqeustWithHTTPRequest($message, $username, $password)

{

$context = stream_context_create(array(

'http' => array(

'method'  => 'POST',

'header'  => sprintf("Authorization: Basic %s\r\n", base64_encode($username.':'.$password)).

"Content-type: application/x-www-form-urlencoded\r\n",

'content' => http_build_query(array('status' => $message)),

'timeout' => 5,

),

));

$ret = file_get_contents('http://example.com/update.xml', false, $context);
return $ret;

}
Posted in PHP | Leave a comment

Create Nice Web Buttons For Free

http://www.buttonator.com/

Posted in Web Design | Leave a comment

Very Easy SVN Server for Local Development

This is a very easy installation that lacks in security. That means do it on your personal laptop, no other users but you.

  • Install the subversion package (i.e. apt-get install subversion)
  • sudo mkdir -p /home/svn/
  • sudo svnadmin create /home/svn/project_name
  • sudo chmod -R 777 /home/svn/project_name
  • svn co file:///home/svn/project_name

That’s it. You are ready to import the initial files and then commit/update everything you want.

Posted in Web Development | Tagged | Leave a comment

37Signals Speech – Very Interesting

Jason Fried talks about momentum, why roadmaps, specifications and projections are evil, and many other topics.

Posted in Business | Leave a comment

Differences between Virtual Private Servers and Dedicated Servers

This article describes the differences between a Linux VPS and a Linux Dedicated Server from the perspective of Linux system administration and basic functionality. The information presented here is not all-inclusive, nor will the technology behind these differences be discussed.

Linux system administrators seeking a comprehensive guide to their virtualization platform of choice should consult the OpenVZ Documentation or Xen Documentation.

Contents

Fundamental Differences

The following differences can be noted on either the OpenVZ or Xen virtualization platforms:

Kernel and Hardware Differences

  • Modified kernels are not supported at VPSLink
  • All hardware is virtualized – Hardware clock may not be modified

Hardware clock workaround: VPSLink runs NTP on all hardware nodes to ensure server time is reported accurately. Setting the Linux System Timezone is a reliable way to synchronize your VPS time with your local time.

Network Interfaces and Hostname Reset on Reboot

  • Network interface changes are reset when the VPS is rebooted
  • Server hostname is reset when the VPS is rebooted

Configuration reset workaround: Add configuration commands to your /etc/rc.local file to reconfigure your VPS whenever it is booted.

OpenVZ Platform-Specific Differences

  • C libraries may not be modified on OpenVZ
  • Resolver nameservers are reset on reboot
  • Kernel modules may not be installed and installed kernel modules are not visible within the virtual environment (see VPSLink OpenVZ Installed Kernel Modules for details)

Any allocations in excess of your VPS memory limit (RAM) will result in processes being killed on OpenVZ – please see the Problem: Process or Daemon Dies article for more information on OpenVZ’s behavior and troubleshooting.

Xen Platform-Specific Differences

  • C libraries may not be modified on Xen unless the modification is performed on a non-thread local copy of the compiler

Source: http://wiki.vpslink.com/Differences_between_Virtual_Private_Servers_and_Dedicated_Servers#Fundamental_Differences

Posted in Misc | Leave a comment

Jokes For Web Developers

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

chmod a+x /bin/laden  -  allows anyone to execute Bin Laden

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Posted in Misc | Leave a comment

Rolling Back yum Packages – CentOS Roll Back After Installation

Rolling back yum packages:
http://dailypackage.fedorabook.com/index.php?/archives/17-Wednesday-Why-Repackaging-and-Rollbacks.html
http://www.vincentverhagen.nl/2007/12/10/how-to-roll-back-packages-on-centos-5-rhel-5/

When you’ve installed/updates packages with yum or rpm, you can quite easily roll back the updates/installations using rpm.
For this, yum and rpm need to save roll back information, which they do not do by default.
To enable the roll back feature, do the following:

Add tsflags=repackage to /etc/yum.conf.
Add %_repackage_all_erasures 1 to /etc/rpm/macros. If /etc/rpm/macros does not exist, just create it.

You can now install, erase and update packages with yum and/or rpm, and they will save roll back information.

When you want to roll back, use rpm to do so.
You do this by specifying the –rollback switch and a date/time, like the examples below:

rpm -Uhv –rollback ’19:00′
rpm -Uhv –rollback ’8 hours ago’
rpm -Uhv –rollback ‘december 31′
rpm -Uhv –rollback ‘yesterday’

Posted in Redhat / CentOS, System Maintenance | Leave a comment

Sympony – Propel – Get Connection Details

/**
* Returns an associative array with the details of the database connection
*
* @param string $application the name of a valid application (i.e.: frontend) – used to get a Propel connection
* @param string $environment the environment we want to apply the deltas to
* @return array(of strings) the keys are: name, host, user, password
*/
public static function getDatabaseConnectionDetails($application, $environment)

{
$databaseConnectionDetails = array();
$configuration = ProjectConfiguration::getApplicationConfiguration($application, $environment, true);
sfContext::createInstance($configuration);
$databaseManager = new sfDatabaseManager($configuration);
$databaseConfig = sfPropelDatabase::getConfiguration();
$databaseDsn = $databaseConfig['propel']['datasources']['propel']['connection']['dsn'];

if (preg_match(‘/dbname=([^;]+);/’, $databaseDsn, $matches))
{
$databaseConnectionDetails['name'] = $matches[1];
}
else
{
throw new sfException(sprintf(‘Unable to get the database name.’));
}

if (preg_match(‘/;host=(.+)/’, $databaseDsn, $matches))
{
$databaseConnectionDetails['host'] = $matches[1];
}
else
{
throw new sfException(sprintf(‘Unable to get the host for the database.’));
}

$user = $databaseConfig['propel']['datasources']['propel']['connection']['user'];
if ($user)
{
$databaseConnectionDetails['user'] = $user;
}
else
{
throw new sfException(sprintf(‘Unable to get the username for the database.’));
}

$password = $databaseConfig['propel']['datasources']['propel']['connection']['password'];
if ($password)
{
$databaseConnectionDetails['password'] = $password;
}
else
{
throw new sfException(sprintf(‘Unable to get the username for the database.’));
}
return $databaseConnectionDetails;
}

Posted in Symfony | Leave a comment