Category Archives: Tweak

[Unsolved] Got “Peer certificate cannot be authenticated with known CA certificates” while using Twitter OAuth with PHP PECL_OAuth

Here is a dump for $oauth->debugInfo. ($oauth is an OAuth class from PECL_OAuth) array(2) { ["sbs"]=> string(240) “POST&https%3A%2F%2Fapi.twitter.com%2Foauth%2Frequest_token&oauth_consumer_key%3***%26oauth_nonce%3D16905507154beeed8c5ce2d0.02323759%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1273949580%26oauth_version%3D1.0″ ["info"]=> string(537) “About to connect() to api.twitter.com port 443 (#0) Trying 128.242.245.125… connected Connected to api.twitter.com (128.242.245.125) port 443 (#0) SSLv3, TLS handshake, Client hello (1): SSLv3, TLS handshake, Server hello (2): SSLv3, TLS handshake, CERT (11): [...]

Posted in Tweak | 1 Comment

How to Make an Autobot on Twitter with OAuth, not Basic Authentication

Twitter will be shutting off basic authentication on their API on June 30. Tweeting with basic auth was pretty easy in PHP: $context = stream_context_create(array( ‘http’ => array( ‘method’ => ‘POST’, ‘header’ => ‘Content-type: application/x-www-form-urlencoded’, ‘content’ => http_build_query(array(’status’ => $status)), ), )); $response = file_get_contents("http://$username:$password@twitter.com/statuses/update.xml", false, $context); After shut off basic auth, how can we [...]

Posted in Tweak | Tagged , , , | 2 Comments

Compiling PHP5.3.2 on MAMP

It was not easy to compile PHP5.3.2 on MAMP. First of all, you need to download httpd2.0.63 and PHP5.3.2. (I’m using MAMP 1.8.2 and Mac OSX 10.5.8) MAMP is in /Application/MAMP already. You may want to backup that directory. You may need to edit srclib/apr/include/apr.h like “#define APR_HAS_SENDFILE 0″ after run configure because get an [...]

Posted in Tweak | Tagged , , | 3 Comments

jQuery validation: required and minlength for dynamic fields

This is not a smart way though, but I tried to code for a bit complexed form. Demo. Code snippet: $(’form input[type=button]‘).click(function(){ $(’ul’).show().append(’<li><input class="hidden" type="checkbox" name="list[]" value="1" checked="checked" />’ + $(’select[name=item_name] option:selected’).html() + ‘&nbsp;’ + $(’select[name=price] option:selected’).html() + ‘&nbsp;<a>remove</a></li>’); $(’ul li a’).click(function(){ $(this).parent().fadeOut(’slow’, function(){ $(this).remove(); }); }); }); var validator = $(’form’).validate({ rules: { ‘list[]‘: [...]

Posted in Tweak | Tagged , | Leave a comment

Sending git notifications via Gmail SMTP server

Hosting SMTP server like sendmail/postfix by yourself is a bit high cost and emails easily go to spam folder if you don’t setup DNS stuff. Instead, let’s use Gmail SMTP server to send notification emails from git. You need to edit post-receive-email a bit. send_mail() { # if [ -n "$envelopesender" ]; then # /usr/sbin/sendmail [...]

Posted in Tweak | Leave a comment

Get error message “G is null” or “a is null” on jQuery

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js"></script> <script> $(document).ready(function(){ var obj = null; // …maybe there are long lines… $.each(obj, function(){ }); }); </script> Will get an error message “a is null”. When using jquery.min.js, it might be hard to recognize what kind of error it is. On version 1.3.2 the message says “G is null”. You can’t pass null [...]

Posted in Tweak | Tagged , | 1 Comment

Convert multiple object to array in PHP

For simple object, just use cast syntax should be fine. $array = (array)$object; However, this way doesn’t work for complexed object (or array+object combination) like this: array(2) { [0]=> object(stdClass)#1 (1) { ["id"]=> int(0) } [1]=> object(stdClass)#2 (1) { ["id"]=> int(1) } } Then, simply this one liner works well. $multipleArray = array_map(’get_object_vars’, $complexedObject); Since [...]

Posted in Tweak | Tagged | Leave a comment

Compiling mongo php driver on pecl for MAMP

MAMP 1.8.2 includes pecl but actually it doesn’t work. When trying to “pecl install mongo”, there will be an error. grep: /Applications/MAMP/bin/php5/include/php/main/php.h: No such file or directory So, I downloaded source tar ball of PHP 5.2.10 (same version as MAMP’s PHP) and configure && make && make install. Then $prefix/include directory will be created. Just [...]

Posted in Tweak | Tagged , , | 1 Comment

Load remote CSS file dynamically with jQuery

The below code loads a CSS file dynamically. It’s relatively easy to load all CSS files from the beginning, or just append a link element (ref. Switch stylesheets with jQuery). But it rarely needs to load a file dynamically and wait until those new CSS properties are ready to render new HTML elements. test.html: <html> [...]

Posted in Tweak | Tagged , , | 4 Comments

Call a method of object with string in JavaScript

var call_user_func = function(obj, method) { return eval(’obj.’ + method).apply(obj, Array.prototype.slice.call(arguments, 2)); } var test1 = { method1: function(arg1, arg2, arg3) { return alert(arg1 + arg2 + arg3); } } call_user_func(test1, ‘method1′, 1, 2, 3); It works on Firefox3, Safari4, IE6.

Posted in Tweak | Leave a comment