Sign up Login
home | you | technology | web 2.0 | podcasts | entertainment | photos | comics | videos
 

Webware 2.0 [view: normal]

deck | river | normal
 

Is Mashable Owning TechCrunch in Terms of Traffic? 12.11 21:02

A long while ago, I noticed that Mashable seemed to have faster growth than TechCrunch. Here’s what the latest Compete traffic comparison graph looks like:

techcrunchvsmashable

It seems like Mashable is actually doing better than TechCrunch now in terms of traffic. Looking at the two sites and what they do, I would guess the difference is due to the fact that Mashable appeals to a much larger audience (ordinary folk)...

Referring to DOM Elements in Firefox and Safari 12.11 20:53

Came across this annoying little difference between Firefox and Safari today. Let’s say we have an image:

one

This uses the following html code:

one

Notice how there’s a name=”one” attribute on the image. Now, we can change the image using some text that we mouseover. Here’s an example that you can hover over:

Hover over this text

This uses the following HTML:


Hover over this text

Now, the problem ...

The Disk You Inserted Was Not Readable by this Computer 10.11 02:15

This post comes at the end of a day’s worth of technical troubleshooting after I ran into a pretty devastating problem today. I’ll start from the beginning:

My fellow youth group staff and I use a program called CovenantEyes for Internet accountability. It’s a terrific program that works very well, except for one annoying issue on my MacBook Pro: It regularly causes kernel panics, which means my s...

Getting the Text Between HTML Tags in PHP 09.10 03:28

Suppose you’re automatically parsing a webpage, and you come across the following kind of thing:

blah blah
some starting text
some useful content
some ending text
blah blah

We want to parse out the useful content from among the non-useful stuff, and we know there’s some starting text and some ending text that wraps the useful content.

A better example:

I like chicken

     I don't like to eat fish...

Scramblizer – Scrambling Your Text to Confuse Your Friends 07.10 07:38

scramblizerWas chatting with some youth groupers this evening when one of them started typing in text that was upside down. When we asked how did he it, he linked us to this page.

I tried fooling around with the app a little, and decided to confuse the youth groupers even more by only flipping every other word. This paragraph would end up looking like this:

i pǝıɹʇ fooling punoɹɐ with ǝɥʇ app ɐ little, puɐ d...

Invalid Authenticity Token Error in Rails 19.09 23:29

Got the following error today when trying to submit a form in Ruby on Rails:

ActionController::InvalidAuthenticityToken

The solution turned out to be as easy as inserting

into my form.

...

Twitter’s New Link Tracking is No Good 04.09 18:42

TwitterTwitter changed how links work recently, so now when you click a link the first thing that actually loads is something like:

http://twitter.com/link_click_count?url=STUFF

I don’t like it.

First off, it’s messier. Instead of clicking through normal links now we’re getting redirected for internal links. That’s weird.

Second, it puts another level of failure and slowness between users and the places they’re trying to reach via the links. It looks like the redirection/tracking is only happening for internal links, so if twitter is down then the link would probably be down anyway, but I feel like things are a little slower anyway with the intermediate step.

Hmm…

...

Spam, Noise, and the Utility of eBay 03.09 08:11

eBayI think of the the big reasons I’ve used eBay less and less over the years is because of how much noise there is now in the service.

In the early days when Yahoo Auctions and eBay were both fighting for the online auction market, online auctions were great in that it was easy to find something that another person was personally putting up for sale.

Nowadays, eBay is teeming with online retailers a...

Working with Hex Colors in PHP 02.09 20:56

I was tinkering with a devotion schedule application this morning, and needed to have an automatically handled font color so that a series of lines would be a gradient.

Here’s how to work with automatic gradients (or colors in general) in PHP.

First off, we’re working with hex. The functions you’ll find useful are hexdec() and dechex(). hexdec takes a hex number and converts it to decimal, while ...

Header Location Redirect Not Working in PHP? 01.09 09:39

Ran into a bug this evening when I was trying to redirect to a different page in PHP. I was trying to do the following:

if(blah blah blah) {

   echo "some text here";

   header("Location: http://www.example.com/");
}

The problem was that it wasn’t doing anything, even when the if condition was satisfied. It was printing out what ever I was echoing, but wasn’t redirecting.

Finally found out the problem after a bit of tinkering. In fact, it’s something I’ve learned a few times already in the past but keep forgetting.

If you read the documentation for header() carefully, you’ll find that it says:

Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP. It is a very common error to read code with include(), or require(), functions, or another file access function, and have spaces or empty lines that are output before header() is called. The same problem exists when using a single PHP/HTML file.

This means that your header has to be executed before ANY output from the PHP file hits the browser. In my case, I was echoing “some text here” to the browser before trying to execute the header function, causing the redirect not to work.

Removing the echo will fix the problem. Some people come across this problem in an even more annoying case, where they’re not even echoing anything. For example, if you copy and paste the following into a PHP file, it will not work:

 

Why won’t it work, even though you’re not echoing anything? Because there’s a single space before the

...

Fatal error: Call to undefined function: file_put_contents() 01.09 00:09

Two functions that I’ve found invaluable recently have been file_get_contents() and file_put_contents(). When used along with serialize(), these have allowed me to maintain very simple “databases” using files in the directory, rather than having to store data in specially made MySQL tables.

One of the interesting things I discovered when trying to use these functions on a different machine today, ...

Target of a DDoS? No Offense… 27.08 20:58

Taking a graduate course on network security right now, and reading a paper on inferring DDoS activity on the Internet. One of the things I’ve learned is how innocent third-parties are often involved in DDoS attacks.

Basically, one method for launching a DDoS involves reflecting packets off a third-party and towards the victim. The packet is sent as if it were coming from the victim, so the third-...

Original Flickr Page from Static Image URL 18.08 03:38

If you have a static Flickr URL and want to find the original Flickr page it was posted to, here’s how to do it.

First, here’s what a static URL looks like:

http://farm4.static.flickr.com/3632/3811569661_f801d1837f.jpg

Notice how the filename is two identifying strings concatenated with an underscore.

http://farm4.static.flickr.com/3632/3811569661_f801d1837f.jpg

Take the first part of this, filename, or

http://farm4.static.flickr.com/3632/3811569661_f801d1837f.jpg

and append it to this URL:

http://flickr.com/photo.gne?id=

The final URL you end up with is:

http://flickr.com/photo.gne?id=3811569661

Voila!

[via bram.us]

Flickr URL Generator

For those who are absurdly lazy, I whipped together a really simple application just now called Findr. All you need to do is enter the static Flickr photo url and it will automatically teleport you to the original page. Give it a whirl!

...

Divide by Zero Errors in Postgresql 18.08 01:57

Let’s say you’re working with Postgresql (applicable to other DBMSs as well), and you come across the following error when trying to execute a select query involving division:

ERROR: division by zero

You would think Postgresql would play nice, and set all the invalid fields to NULL or 0, but instead it chooses to spit out an error and die.

The solution is to use the CASE conditional expression, w...

New Text Message Shortcut in Android 17.08 06:14

Here’s how to create a shortcut on your desktop to quickly get to the New Message screen of the Android messaging application. Normally you would have to enter the app and press “New Message”, or create a shortcut to directly message a certain contact.

  1. Download the Any Cut application from the market
  2. Press and hold the Home screen
  3. Shortcuts->Any Cut->Make your own
  4. Enter the following:

    Action: a...

Checking if the Twitter API is Up in PHP 15.08 19:18

Here’s a quick function that returns true if the Twitter API is up and responding, and false if otherwise:

function dieifnotup() {
   $tw = curl_init();
   curl_setopt($tw, CURLOPT_URL, "http://twitter.com/help/test.json");
   curl_setopt($tw, CURLOPT_RETURNTRANSFER, TRUE);
   curl_setopt($tw, CURLOPT_TIMEOUT, 5);
   $twi = curl_exec($tw);
   curl_close($tw);
   return (json_decode($twi) == "ok") ? true : false;
}

A practical use for this function would be to check if Twitter is up, and to call exit() if it’s not.


Update on August 16th, 2009: Include timeout to ensure the connection doesn’t hang. Thanks Eric!

...

Working With Tweet IDs in PHP 14.08 07:42

I was playing with the Twitter search API today when I came across a strange problem. I was storing the unique ID of a tweet in the database as a string, and after bringing it out was trying to convert it back to an integer. However, the following code:

// this was the string of the tweet ID
echo "Tweet ID: {$stringID}
"; // turning it into an integer $intID= (int) $stringID; echo "Tweet ID: {$intID}
";

produced this erroneous output:

Tweet ID: 3296646743
Tweet ID: 2147483647

I finally realized that tweet IDs are too large to fit inside a simple integer data type. Doh!

The maximum value of an integer in PHP is 2147483647. It simply threw away all the high order bits. Haha.

To fix this issue, all you need to do is use a double data type instead.

// this was the string of the tweet ID
echo "Tweet ID: {$stringID}
"; // turning it into an integer $intID= (double) $stringID; echo "Tweet ID: {$intID}
";
...

A Hackish Way to Create Groups on Twitter 13.08 22:31

Twitter doesn’t currently have any feature that allows you to group the people you follow, which is pretty annoying if you follow more than a handful of people. While many Twitter clients allow you to do this, you can also hackishly accomplish “grouping” by using the search box and the “Save this search” feature.

Lets say you want to group three of your friends, all named Bob, and easily view only...

Setting Up Postgresql with Rails on Windows 13.08 20:31

Switching over to Postgresql for a Ruby on Rails application on a Windows machine is pretty simple.

  1. Download Postgresql and install it
  2. Install postgres-pr in the Ruby console with: gem install postgres-pr
  3. Add Postgresql’s /bin path to your PATH environment variable in Windows. Do this by going to:

    Start->Control Panel->System->Advanced->Environment Variables->Select PATH->Click Edit

    Add the full path to the Postgresql bin directory to the end. What you append should look something like

    ;C:\Program Files\PostgreSQL\8.4\bin

  4. Edit your /config/database.yml file to use the Postgresql database. It should look something like

    development:
    adapter: postgresql
    database: DATABASENAME
    username: YOURUSERNAME
    password: YOURPASSWORD
    host: localhost
    encoding: UTF8

  5. Run your migrations

    rake db:migrate

You’re done! Wasn’t so bad, was it?

[via Sensorial'Org]

...

Obtaining the HTML Title of a URL 01.07 22:25

Here’s a little code snippet that allows you to grab the Title tag if you have a URL in php:

$url = "http://www.folksonomy.org";
$page = file($url);
$page = implode("",$file);

if(preg_match("/

Internet Explorer Float Clear Padding Gap Glitch 13.01 21:31

Container: padding: 20px; Float Float Clear

If you have a container with floating elements and a clear at the bottom, Internet Explorer might include an extra gap between your elements and your clear if you assign a padding value to your container.

If you view the example to the left in Firefox or some other non-IE browser, it will look as intended, with no gap between the floats and the cle...

Changing Input Type from Text to Password in Internet Explorer Hack 13.01 01:49

signinformLet’s say you have a login form with the standard username and password input fields, but instead of labels, you want to have grayed out text inside the fields to act as labels. Since the label’s aren’t actual input, they shouldn’t be submitted as actual data if a user submits the form without entering anything, and they should disappear if the user clicks the field to enter text.

The problem is, ...

Debugging Apache and Mysql 07.01 00:04

If you’re getting too many MySQL threads or Apache connections, and you would like to debug them, here are two possible ways to get the info you need:

Apache

fullstatus - Displays a full status report from mod_status. For this to work, you need to have mod_status enabled on your server and a text-based browser such as lynx available on your system. The URL used to access the status report...

Private and Public SSH Keys for Capistrano on Windows 29.12 22:05

capistranosshkeysIf you’re deploying a Ruby on Rails application using Capistrano on Windows, and need SSH authentication, you might run into errors like:

connection failed for: xxx.xxx.xxx.xxx (OpenSSL::PKey::PKeyError: not a private key (C:\path\to\key))

or

connection failed for: xxx.xxx.xxx.xxx (OpenSSL::PKey::PKeyError: not a public key “C:\path\to\key.pub”)

This is because Capistrano (by default) does not li...

Formatting Strings for URLs 29.12 00:52

Here’s a quick Ruby snippet you can use to format a string to be used in a URL:

string.downcase.gsub(/[^a-z0-9]+/i, '_').chomp('_')

This turns something like

This is a Post URL!

into

this_is_a_post_url

which you can use in your archive URLs (like http://www.website.com/article/this_is_a_post_url)

The string is first converted to all lowercase letters with the downcase method of the String class.

Next, we use gsub to strip out everything that isn’t a letter or a number (including spaces) using regular expressions. We replace each of the gaps with a URL friendly separator, the ‘_‘ underscore character. You could also use some other character, like a hyphen, if you prefer.

Finally, since our formatted string could end with a separator character, we chomp that off the end.

...
embed