Skip to main content

Programming

Potentially Malicious Fake Advertiser using Wordpress Plugin (adv.zip)

It starts with an innocuous email:

Hi,

I am sorry I have to write you to e-mail from whois information of the domain. But I could not find contact e-mail or feedback form on your site.
We are looking for new advertisement platforms and we are interested in your site %DOMAIN%
Is it possible to place banner on your site on a fee basis?

Best regards,
Nicolas Gauthier

But it quickly turned strange:

Hi!

Thanks for reply to our proposal!
We like your price.We would like to place 160x600 banner.

To pass to the banner control system follow the link http://webmaster.burgoni.com
To enter use the following data:

login: %DOMAIN%
password: %PASSWORD%

Client Side Tweet Parser in JavaScript (jQuery)

Posted in

I just published a simple JavaScript that helps websites comply with Twitter's Display Guidelines. It helps you comply with issues 2,3,4.

It automatically links to urls, hashtags and mentioned usernames. You simply set the div class to 'tweet' (or whatever you change it to in the code) and link to twitter.js. Make sure you also have jQuery(Only tested 1.6.4) loaded before twitter.js. It is a dependency.

https://github.com/kevinohashi/TweetParserJS

Thanks go to Raphael Mudge who helped with some of the regular expressions.

Future improvements: this code isn't perfect by any means. One improvement would be merging the 3 primary functions into one and some conditions. I've also seen some very elegant server side solutions using almost entirely regular expressions from CodeIgniter (see code below).


function parse_tweet($tweet)
{
$search = array('|(http://[^ ]+)|', '/(^|[^a-z0-9_])@([a-z0-9_]+)/i', '/(^|[^a-z0-9_])#([a-z0-9_]+)/i');
$replace = array('$1', '$1@$2', '$1#$2');
$tweet = preg_replace($search, $replace, $tweet);

return $tweet;
}

How to Make Facebook Like Button on a Website Connect to a Facebook Page

I wanted a simple 'Like' button connected to my facebook fanpage. No stream, no faces, no counts, no nonsense. I couldn't find an easy and obvious way to do it.

I spent more time than I would care to admit trying to figure this out and it turns out to be trivial.

  1. Go to Like Button developer tool.
  2. Set 'URL to Like' to your facebook page (http://facebook.com/FacebookName)
  3. Set 'Width' to '50'
  4. Uncheck 'Send Button'
  5. Choose 'Button Count' for the Layout Style.
  6. Uncheck 'Show Faces'
  7. Get Code, choose iframe version.

The 50 width should cut off the like count box (you can make it bigger/smaller to make sure it works). Simple, easy, like button connected to facebook fanpage.

Screenshot below:

Firefox Inspector Bug (10.0.2)

Posted in

I wanted to report the bug to mozilla but it took me 15 minutes to even find their bugzilla and then it wanted too much of my time and to share my personal info (email address). So I will just post it here instead.

So basically the problem is if you double inspect, you can't escape the inspector and the close box (X) disappears.

Screen shots after the jump.

Click Tracking using JavaScript and Google Analytics - The Good and The Bad

Posted in

I ran into an interesting problem recently, I didn't want to change my links to some sort of URL forwarding script (facebook.com/l.php=http://kevinohashi.com) to track outbound clicks but I still wanted the outbound click data.

I thought it should be possible using JavaScript and the onClick() functionality. My first inclination was to just go to jquery and bind the click to a function that would simply make an ajax call to record the click data and then forward the user.

Upon further research I found out Google Analytics has this functionality and tracking already built in.

You simply include another javascript snippet:


<script type="text/javascript">
function recordOutboundLink(link, category, action) {
try {
var pageTracker=_gat._getTracker("UA-XXXXX-X");
pageTracker._trackEvent(category, action);
setTimeout('document.location = "' + link.href + '"', 100)
}catch(err){}
}
</script>

And then for any click you want to track you simply add:

onClick="recordOutboundLink(this, 'Outbound Links', 'example.com');return false;"

Outbound Links is the label for the link. It all shows up in the Event Tracking reports in Google Analytics. Simple.

Or so it seemed. I tried this method and some users complained that it broke things like middle click (open in new window) functionality. I am also not convinced it actually worked for every click, my click volume didn't seem to match on the links I did have access to stats on the outbound side for.

So I turned it off and canned the idea for now. I guess that's why facebook, twitter and everyone else seems to use link tracking scripts like l.php and t.co.

Photo Unshredder

Posted in

Instagram Engineering Challenge: The Unshredder
"Your challenge, if you choose to accept it, is to write a simple script that
takes a shredded image in as input and outputs an unshredded and reconstituted image."

So here's the sample image:

We're given the information that the slices are 32 pixels wide each, so I don't actually
address finding slices.

My Solution Process

Disclaimer: I've never really worked with images before and have little to no
knowledge of the research and techniques often used in this area.

The challenge appears to be figure out the best way to put pieces back together.

My first thought was I can sample X pixels from each edge of a slice, grab the RGB
value of each pixel and compare the difference.

The reasoning behind this was RGB is the easiest way I can think of to compare
differences in colors between pixels. Sampling would hopefully make it faster.

I made one critical mistake, instead of comparing pixel to pixel, I calculated
total R,G,B on an edge and compared the sum of an edge instead of a difference.

I didn't understand why that was wrong until the example of a checkerboard was
given. If you had a slice on a checkerboard they would actually be equal on
average but very different on a pixel to pixel comparison.

So, I had to revise my solution to compare pixel to pixel on each slice against
its opposing slices. So left side of slice 1 was compared against right side of
all the other slices in the image. The logic being that the slices with the
least amount of difference between them probably fit together.

Almost. Something is wrong here. The striped building seems to throwing it off.
The striped building has the highest difference value of any left-right pairs.
So my algorithm kept putting it on the side.

How can I make the striped building fit together? I tried cheating and seeded the
proper right end image (slice 10) and the image constructed itself perfectly.

Well, the only solution I came up with was somewhat brute force in nature. What
if I try compiling the image with every slice as an edge and see what the total
computed difference of the image is?

Voila! The only way I could think to overcome this was proving the whole image turned
out better despite the high difference pair.

My code is publicly available on Github

I apologize if you actually read the code, it's a mess, there is a lot of testing going on, commented out code and things that aren't used in the final version. I thought it would be a good way to learn about ImageMagick and PHP's Imagick class (which is the worst documented thing I've seen on PHP.NET)

Writing Clean Code

Posted in

Great video about writing clean code (which sadly cannot be embedded): http://vimeo.com/12643301

I thought I was doing an ok job but it really shined light on some things I could do to improve my code.

Funny thing is, I could have gone there but didn't think I would be writing that much code in the future at the time. It was 15 minutes away in Malmo!

Natural Language Processing (Comic)

A stressful day trying to work with NLP leads to things like this.

Natural Language Processing Comic by Kevin Ohashi

Dear Afternic

You are still emailing me lost passwords in plaintext. This just isn't acceptable.

I contacted you, worked my way through your support team until the manager I spoke to who was supposed to be connected to the dev team asked me what email client I used and said maybe it was outlook that was revealing my password. My email client (oh, I don't even use outlook) was allegedly cracking the passwords or something. I am not even sure what they were trying to say or imply. Whatever it was, it's ridiculous.

I only noticed this because I reactivated an old account because I thought listing with you guys would be a good idea to complement listing on sedo since you were also free now. I want to be your customer. I also want you to treat my information with respect and keeping my password secure is something I simply cannot compromise on. Please fix this issue so we can get back to selling domain names, because I simply won't do business with you until you do.

Open Sourcing DomainToad.com Domain Name News Aggregator

If 500 people subscribe to the DomainToad newsletter by April 1, 2011.

Oh look, a catch! Shocking!

Why would I do that? Because I spent a fair amount of time and some money to create the website and I would like to see that people at least try it. Releasing the code publicly will also take some more of my time to clean it up a bit and package it. If nobody cares enough or finds it useful enough to use, then I won't bother spending my time to release it to everyone for free.

I've released a lot of software I've written over the years for free or provided access to them publicly for free. Most probably never got used by anyone but me, if people are genuinely interested in having a copy of the code I wrote for Domain Toad they will subscribe for the newsletter and get their friends to subscribe as well. It's free and provides headlines from major domain blogs in your email daily. Other websites charge for that 'luxury.'

If the newsletter gets 500 subscribers before April 1, 2011 I will release the code with the open source MIT license. How will people be notified? I will post on my blog and email the newsletter subscribers a notice if it has 500 subscribers by April 1, 2011.

If someone is really that desperate to buy it, I will sell copies for $250 as is with 1 hour of support to get started with a non-exclusive license to use/modify it but not distribute unless it becomes open source. Contact me.

Syndicate content