Whathuh Twitter Command Line Tool
Microblogging, development March 7th, 2009
I was shown a Win32 CLI for Twitter, and I didn’t like how it was done, so I made one.
Pretty simple to use.
Vista: Extract the two files to your home directory
XP: Extract the two files to your Windows directory, or another directory in your system’s PATH variable
Win98: Extract to a directory in your system’s PATH variable
Edit the twit.bat file and replace “yourusername” with your username, and “yourpassword” with your password.
Quick Twit: Start-Run (Windows Key + R), type twit followed by your message. No quotes required
Example: twit I just twitted from the command line… because I can. I like useless tools.
Disclaimer: If you don’t know how to edit a batch file, don’t know what a batch file is, or feel like you shouldn’t be putting your username and password into a batch file, don’t know what a PATH variable is, please move on. This is not for you, at all, and I wouldn’t want to make anybody uncomfortable.
Download Twit CLI 1.0 for Win32 (includes curl-7.19.4-win32-nossl)
MD5: 73FAF016EE43C5C556B6A8313E74BDD9
PHP if statement alternatives
development, php September 7th, 2008
Did you know there are actually 3 different ways to use the if…else…elseif control in PHP? They each have their uses, and hopefully I can help decode them a little bit for those who aren’t familiar with them. Here is your standard if statement:
if ($islocal) {
$user = "localhost";
} else {
$user = $logged_in_user;
}
if ($isadmin) {
$ip = "192.168.0.1";
} else {
$ip = "localhost";
}
Now, there is nothing wrong with that, but if you’re looking for something a bit cleaner, you could try it this way:
$user = ($islocal) ? "localhost" : $logged_in_user; $ip = ($isadmin) ? "192.168.0.1" : "localhost";
Less code. Less mess. Less parsing time. Very nice. Now, what about dynamically generating html pages? I’ll use a short example of the standard way, but in practice they get quite a bit more complicated and tough to read. Here’s an example of a form the standard way:
<?php
if ($isloggedin) {
echo "<form name = 'myform' action = 'submit.php' method = 'post'>";
echo "<input name = 'firstname' value = '{$user['firstname']}'
type = 'text' />";
echo "<input name = 'lastname' value = '{$user['lastname']}'
type = 'text' />";
echo "</form>";
} else {
echo "<div class = 'errormessage'>You are not logged in.</div>";
echo "<div class = 'infotext'><p>Please <a href = 'login.php'>login
</a> or <a href = 'register.php'>register</a> before attempting
to edit your profile</p></div>";
}
?>
Now like I said, this one isn’t so bad. but imagine if you needed to display much more website content, and had to do it that way. Also, this has the caveat of being very unfriendly with any sort of visual editor like Dreamweaver. Here’s a better way:
<?php if ($isloggedin) : ?>
<form name = 'myform' action = 'submit.php' method = 'post'>
<input name = 'firstname' value = '<?php echo $user['firstname'] ?>'
type = 'text' />
<input name = 'lastname' value = '<?php echo $user['lastname']} ?>'
type = 'text' />
</form>
<?php else: ?>
<div class = 'errormessage'>You are not logged in.</div>
<div class = 'infotext'><p>Please <a href = 'login.php'>login</a> or
<a href = 'register.php'>register</a> before attempting to edit your
profile</p></div>
<?php endif; ?>
Now, this doesn’t save a whole lot of code space, but it does make everything a bit more readable. It also allows you to see exactly what you’re working with in something like dreamweaver, and copy and paste large amounts of code without having to scroll down line by line and copy/paste/copy/paste…
Hopefully these will help save some of you some time. Good luck, and happy coding!
Tags: code, coding, development, else, endif, if, php, then, tips
Simplified PHP $_POST data handling
development, php May 7th, 2008
When posting data from a form to a page, the $_POST variable gets set to an array similar to this:
Array ([name] => "daniel", [state] => "illinois", [phone] => "630-618-9588")
Now, one way to process this is to know in advance (which, normally you will), what the values will be, and set them to more usable variables. For example:
$newclient["name"] = $_POST["name"]; $newclient["state"] = $_POST["state"]; $newclient["phone"] = $_POST["phone"];
Now, for a simple form that only has one or two values, that’s fine. The code is clean, easy to read, and it gets the job done. Now, if you have a more complex form, the array may look more like this:
Array ( [lastname] => costalis [firstname] => daniel [MI] => g [lastnameguardian] => kolar [firstnameguardian] => maureen [MIguardian] => p [Month] => 10 [Day] => 05 [Year] => 1983 [Age] => [address1] => 445 n ardmore ave #k [address2] => [city] => villa park [state] => IL [zip] => 60181 [phone1] => 6306189588 [phone2] => [phone3] => 6306189588 [email] => costalis.dan@gmail.com [feet] => 5 [inches] => 10 [pounds] => 165 [hair] => Brown [eyes] => Green [union] => Yes [experience] => None [skills] => Jumping [notes] => Great Guy [submit] => Add Client )
You can copy and paste 31 times, and edit all the values if you want… or, write something that will do it for you. (read: copy and paste my code and edit it to your needs) This particular set of code is designed to update a mysql database, but can be modified to your liking. the “safedata” function is to prevent hacking of your database.
function safedata( $string ) {
return "'" . mysql_real_escape_string( $string ) . "'"; //add needed slashes,
enclose data in quotes.
}
foreach ($_POST as $field => $value) //Count through each post item
{
$fields[] = $field; //add current field name to fields array
$values[] = $value;//add current field value to value array. Will have same index
as its field name
}
$query = "INSERT INTO `SomeTable` ("; //Start of MySql query
foreach ($fields as $fieldname) //for each field name
$query .= "`" . $fieldname . "`,"; //add field to list in query. safedata not
needed... you supplied the names
$query = rtrim($query,","); //trim off extra comma after final value
$query .= ") VALUES("; //close off field names, begin listing values
foreach ($values as $valuename) //for each value corresponding to its field
$query .= safedata($valuename) . ","; //add value to list
$query = rtrim($query,","); //again, we have an extra comma
$query .= ") ;"; //end query string
$result = mysql_query($query); //excecute query
// created by : http://www.whathuhstudios.com/press : attribution may be removed and
is not required
You could easily use this to assign the values to an array of your liking, or whatever you like. Either way, this is a nice easy way to deal with large form submissions without the use of a PHP framework. Do what you want with this code, and if you happen to include a link to my site on your site, or leave me a comment… then so be it. Hope this helps someone.
