Cute is also cool, when combined with some manliness

OK, I figured out that people aren’t as interested in my programming problems as much they are in sweet animals and music, movies, videos and cars. Well, to be honest, there’s pretty much everything else that more interesting. So, to test how people really react to different content, I’m going to make posts of different nature here and see how they react.

Feel free to enjoy.

In this post’s case, it’s a cuteness gallery. This bunch is from a pinterest album dedicated to exactly that – cuteness. And I actually like it and have repinned some of them on my own pinterest account. Let me see then…

Reading server outgoing data (php & curl)?

I’ve been trying to accomplish what I described as a very cool tumblr api library, and have been stumbling on multiple issues all along. Not that I expected it to be any different… That’s the whole fun about programming, right?

OK, some parts of this process were quite hard on my nerves, but some good things came out of that, too… One of them being new knowledge – how to sniff server outgoing data, when it’s sent via php cURL.

One obvious way to do so would be to use proxy and log data that goes through it, but since I’m already using proxy for my requests, this task could be even more troublesome than problem I’m trying to solve. That’s why I did a little digging and found this cutie: tcpdump. If you have a server which runs centos or some similar distro, it will help you catch the packets that are flying around :) . I used it and it worked perfectly. Exact syntax was:

tcpdump -vv -s0 tcp port 80 -w /tmp/apache_outgoing.pcap

After successful execution, I was able to observe contents of apache_outgoing.pcap with vi which provided valuable info. It gave me clues that finally put into my head that tumblr api (actually it’s due to OAuth) doesn’t seem to like multipart/form-data, but actually prefers x-form-urlencoded.

I still din’t fix issues in my library, but I’m one step closer to it. Hopefully, this post will help someone.

The command itself was found here: http://serverfault.com/questions/307626/how-to-log-outgoing-http-requests-from-php-curl

Good luck :)

Tumblr killed v1 api. What now?

Hi. In order to find myself something interesting to do, I often visit internet marketing forums. They represent a great pool of different ideas and also requests for things that people find useful and/or interesting. They also represent a great idea pool, because one can learn from other people’s needs and act on them – ending up with products that people find useful.

One such product would be proxy enabled tumblr api oauth library. From what I learned on such forums, many people use bots for accessing tumblr. While this isn’t very cool, since they are, basically, spamming the thing, it’s also a very interesting project. People can’t use their bots because tumblr effectively cut their v1 api (that didn’t request oauth), leaving people with oauth as only mean of api communication to their service. The worst thing related to this change is the fact that most accepted libraries and examples don’t show people how to use proxy servers with those calls, basically disabling them to use one script for multiple accounts (which is the only good way to make money, right?).

This is why I’m going to make a library that will give users all the functionality they’d expect from a “tumblr php SDK”, while also allowing them to use proxy servers.

My goal isn’t to support spammers in any way. It’s a science project with goal to provide better functionality to php SDKs that are available right now. I hope no one will use it to bad purpose. Anyway, it’s still not ready ;)

using curl with 3rd party apis

Have you ever been trying to work with 3rd party APIs? If you love to work with code and also have an affinity to big and important names like twittergoogletumblr etc, you probably took some time to dig a decent library and work with it towards accomplishing some cool goal. A nice example would be building a plugin for wordpress that would bring some of your brightness to twitter and tumblr, simultaneously, without need for clicking around. Even better, you could use it to do some neat data mining, working on your own version of trending algorithms. Doesn’t really matter – if you tried to work with APIs, you probably used some libraries, and if you did that, you probably got pisses of couple of times, getting strange (or none) results from API provider.

I’ve been doing just that in my free time recently, only to find out myself how horribly irritating it is. The moment you come to the point where you think everything is working as expected is the moment you’ll start seeing some strange results. I found a pretty cool way of avoiding this, putting some more ‘certainty’ into the process: use cURL, use exceptions and give your app several opportunities to fix things. It was always a dream for me – to have an app (even better, a robot) that would be able to adapt to different situations. And while  different might be a bit of a problem – too wide to deal with - some situations might actually be pretty handle-able.

Consider the following code snippet:

// give cURL ~5s for connect
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
// give cURL ~10s for each call
curl_setopt($ch, CURLOPT_TIMEOUT, 10);

$callOK = false;
$cntDwn = 5; // we'll try to succeed 5 times!
while (!$callOK && $cntDwn > 0) {
   try {
      $cntDwn--;
      $cntDwn = curl_exec(/*something fancy*/); // you probably want to do api call here
   } catch (Exception $e) {
      $cntDwn--;
}

if (!$callOK) { //
   ; // write to database and try again later...
} else {
   echo "I'm coolest!";
}

This helped me quite a bit. I hope it’ll do you good to. It’s just a basic idea, but not a bad one…

Programming Books

I’ve been looking for some great books on programming lately. Not the kind that teach you algorithms, but the one that teaches you how to do things uniformly, how to use your time more efficiently and how to avoid usual dead ends and / or bottlenecks people in my profession usually stuck.

Obviously, the best way to search for things is to use the big G, and so I did – what it gave me after some searching and reading were the following two books:

       

I downloaded both books to my kindle and am now looking forward to reading them. Time, however, is not a resource I’m rich with. Recently, all my free time is filled with playing a really cool FPS game which I’m not going to name, playing with some php scripts and sharing them with people around the globe AND heavy drinking :) . (See now why exactly am I trying to get some organizational books).

It just came to me that linking above titles to amazon books might be a nice touch, if someone wants to get these books as well. Additionally, any comment regarding these books is more than welcome.

Good night folks.

UPDATE: adding links with images sounds even better ;)

PHP cURL tip or two

I submitted a script of mine few days ago to a forum where people share these things and in return get a thank you or some other nice word. Or a bad word, depending on how well your script is documented. Since I always try to be on a safe side with comments in code, there were quite a few smiles actually. It made me all happy, of course.

What made me even more happy was the fact that one of the members asked me how to add some options to cURL in order to achieve certain things. Getting feedback that contains a question is usually a sign that someone actually wants to really use your scripts, and is in fact trying to modify it a little bit. Sweet.

Now, the question was about cURL and few options that this guy needed. More precisely, he asked me how to:

  • set cURL use a proxy server for accessing pages
  • set value of user agent

Now, setting a proxy is probably rather clear – some sites serve different content depending on country you’re coming from – it requires some kind of masking of IP value of the server script is being executed on. cURL, luckily enough, supports this option. Similarly, some sites are requiring from you to have a specific user agent in order to access their content. Think of a mobile site – they might want to redirect you to a different site / page if you’re not usign mobile phone while browsing. What happens if you really really want to open it from your script? Your script probably isn’t a mobile phone (actually, it would be a miracle if your script was a mobile phone – the same kind of a miracle that rich people giving money to poor people represents), and it would be redirected, leaving you empty handed.

Obviosly, you need to have cURL as an option in your PHP – i.e. it has to actually be compiled with cURL. To check if cURL is supported, simply create a test script and include something like this:

if (in_array('curl', get_loaded_extensions()))
   echo 'Yay! cURL is here!';
else
   echo 'Duh, no cURL here :( ';

OK, now that we have cURL covered, let’s include those sweet lines that will let us use proxy server with cURL and also set some sweet agent, i.e. Opera mini for mobile phones.

// ok, let's first init the curl
$ch = curl_init(); // wasn't so hard, right?

curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1);
curl_setopt($ch, CURLOPT_PROXY, '192.168.1.1');
// in addition, you can set other proxy options
curl_setopt($ch, CURLOPT_PROXYPORT, '8080');
curl_setopt($ch, CURLOPT_PROXYUSERPWD, 'user:pass');

// and here we'll add user agent: 
// we'll use opera mini I googled for
curl_setopt($ch, CURLOPT_USERAGENT, "Opera/9.50 (J2ME/MIDP;"
                                    " Opera Mini/4.0.10031/298; U; en)");

And that’s it! Drop a comment if you need more tips with this. See you!

Building a house? Why don’t use fake iPads instead of bricks?

Not so much about science, programming or math, but I guess this might go as humor. Well, at least to people who didn’t buy them. Namely, it appears that some poor folks bought iPads 2 made out of clay :) .

Here’s the entire news: Fake iPad 2s made of clay sold at B.C. stores

That’s it… Cry or laugh, depending on what you like more :)

To be OR not to be

I was thinking of this one when creating this blog. I mean – it’s not like blogging, math, programming is a matter of to be or not to be, but xor really is about this. In the last few days I’m trying to create a squidoo page that will explain a little bit more about xor operation. Most people coming here probably know enough about it. Still, I’m searching around in my head for things to do here. One day it came to me that I should create a blog that deals with what I do, what I don’t do and what exactly do I do when I’m not doing what I do and not doing what I don’t do. Also, it should be about fun.

Let’s take it easy for now. I love seeing Google, Baidu and Yahoo! footprints around here. I love spying on them as much as they spy on everyone else. It’s fun. And I’m not ashamed to say so! Yeah, that’s me – guy who’s not ashamed.

More about me soon, where soon is rather stretchy.

wordpress hacking and a smile or two

well, not really hacking. i’m simply trying to see what exactly is going on with this blog of mine. at the moment, i’m using dodo template created by Rajveer Singh Rathore and, while rather grateful about his efforts in creating the template, i’m going to remove link to his site. still didn’t check the license part of his template, but will do so, and if possible, i’ll remove the link. i would like to keep the control over my outbound links. i’m an ass, i know.

i was especially pissed of by author’s decision to automatically enable blog roll. i’ve been using wp for quite some time now, but have never programmed for it and it might be somewhat of a customary thing – to hard code blog roll in wp templates. i’m not happy about it, and below i’ll list a short howto on removing the blog roll from this template. i’ll also explain my motives :)

i replaced the following code in root/wp-content/themes/dodo/sidebar.php:

 

<h2>Blogroll</h2>
<ul>
   <?php wp_list_bookmarks('categorize=0&title_li='); ?>
</ul>

with this:

<!-- Hiding blog roll. Uncomment both html and php if 
     we should show blog roll at some point.
    
<h2>Blogroll</h2>
<ul>
   <?php /*wp_list_bookmarks('categorize=0&title_li=');*/ ?>
</ul>
//-->

for this task i used following software: ultra edit (very useful text editor) and filezilla (ftp client).

please note that i added php comments around php code calling wp_list_bookmarks. the reason for this is the possibility that php code outputs html comments, which would break our commented html code, and probably screw up the layout of the sidebar and possible the whole blog. in addition, even if output html code contains no html comments, it would take some processing time and also end html file representing my blog would be bigger in size. practically killed a few birds with one stone.

i also didn’t remove the whole part of the code all together because i wanted to keep an easy way out if, at some point, i want to publish blog roll. i’m an ass, like i said.

i’m not going to give advice on how to remove the footer link to author’s site. that would be unethical. however, i’ll tell you where to look: root/wp-content/themes/dodo/footer.php ;)

what’s so special about xor?

back in the old days, when men were real men, women were real women and little pink creatures from venus were real little pink creatures from venus, i was in my high school days. it was a math class, and our professor was trying to explain how exactly logical and, or, not, implication and equivalence work.
to my surprise, it was a little bit hard to understand what in the world was the guy speaking. from this point, his example of logical or was so flawed that i simply had to stop listening. his example was something like this: if i say “i’m going to cinema or to a store”, it’s going to be true if i go to cinema, if i go to store or if i go to both cinema and store.
now, while this is mathematically correct, it’s a bad example. at least from a time point: if you only have one moment of time, you can only be at one place. not in two. not in a world. he should’ve used that example for xor.

and this stupid story is the reason i called this blog xor me. from that moment, i did my best to be at one place in each moment of time. i also did my best not to share my space with somebody else’s space at one moment of time. this was specially true if that somebody was actually a truck. i don’t have a driving license for a truck, and being in the same space and in the same time with a truck would probably mean i’m in the wrong place, in the wrong time. makes some sense, right?

anyways, this blog is going to be about some silly ideas of mine, some jokes, and some programming. more about me will be written on about me page, but it’s still non-existent at this point. this will change, however. until then, thank you for visiting!