Mitchell McKenna - imported from stackoverflow.com http://mitchmckenna.com/feed en-us http://blogs.law.harvard.edu/tech/rss LifePress mitchellmckenna@gmail.com Comment by Mitchell McKenna on Git reset current rebase http://mitchmckenna.com/post/19102/comment-by-mitchell-mckenna-on-git-reset-current-rebase

This basically allows you to restart the current rebase stage, awesome!

]]>
Wed, 21 Apr 2021 20:30:00 -0400 http://mitchmckenna.com/post/19102/comment-by-mitchell-mckenna-on-git-reset-current-rebase/comment-by-mitchell-mckenna-on-git-reset-current-rebase
Comment by Mitchell McKenna on Running a single testsuite by default in PHPUnit http://mitchmckenna.com/post/19089/comment-by-mitchell-mckenna-on-running-a-single-testsuite-by-default-in-phpunit

@jdp Please mark this as correct answer.

]]>
Fri, 19 Mar 2021 00:47:00 -0400 http://mitchmckenna.com/post/19089/comment-by-mitchell-mckenna-on-running-a-single-testsuite-by-default-in-phpunit/comment-by-mitchell-mckenna-on-running-a-single-testsuite-by-default-in-phpunit
Comment by Mitchell McKenna on Get the first element of an array http://mitchmckenna.com/post/18830/comment-by-mitchell-mckenna-on-get-the-first-element-of-an-array

Shorten with null-coalescing operator, usually null is default so: $first_value = $my_array[array_key_first($my_array)] ?? null;

]]>
Wed, 01 Apr 2020 12:37:00 -0400 http://mitchmckenna.com/post/18830/comment-by-mitchell-mckenna-on-get-the-first-element-of-an-array/comment-by-mitchell-mckenna-on-get-the-first-element-of-an-array
Answer by Mitchell McKenna for How to detect default avatar on facebook? http://mitchmckenna.com/post/16969/answer-by-mitchell-mckenna-for-how-to-detect-default-avatar-on-facebook

If you are already making a call to the Graph API to get user data like the avatar, just include picture in the fields param when you make your first call to Graph API, then the response will include the is_silhouette offset, if it's set to true the user has the default avatar.

Request:

https://graph.facebook.com/v2.7/me?access_token=[token]&fields=name,picture

Response:

{
    "id": "100103095474350",
    "name": "John Smith",
    "picture": {
        "data": {
            "is_silhouette": true,
            "url": "https://scontent.xx.fbcdn.net/v/...jpg"
        }
    }
}
]]>
Wed, 03 Aug 2016 21:37:00 -0400 http://mitchmckenna.com/post/16969/answer-by-mitchell-mckenna-for-how-to-detect-default-avatar-on-facebook/answer-by-mitchell-mckenna-for-how-to-detect-default-avatar-on-facebook
Answer by Mitchell McKenna for Getting Facebook profile pic from user (via Graph) - detect if it's a blank (i.e. default) image? http://mitchmckenna.com/post/16970/answer-by-mitchell-mckenna-for-getting-facebook-profile-pic-from-user-via-graph-detect-if-its-a-blank-ie-default-image

If you are already making a call to the Graph API to get user data like the avatar, don't make an additional API call to /picture like suggested above.

Just include picture in the fields param when you make your first call to Graph API, then the response will include the is_silhouette offset, if it's set to true the user has the default avatar.

Request:

https://graph.facebook.com/v2.7/me?access_token=[token]&fields=name,picture

Response:

{
    "id": "100103095474350",
    "name": "John Smith",
    "picture": {
        "data": {
            "is_silhouette": true,
            "url": "https://scontent.xx.fbcdn.net/v/...jpg"
        }
    }
}
]]>
Wed, 03 Aug 2016 21:36:00 -0400 http://mitchmckenna.com/post/16970/answer-by-mitchell-mckenna-for-getting-facebook-profile-pic-from-user-via-graph-detect-if-its-a-blank-ie-default-image/answer-by-mitchell-mckenna-for-getting-facebook-profile-pic-from-user-via-graph-detect-if-its-a-blank-ie-default-image
Answer by Mitchell McKenna for Getting a thumbnail from a Bing News result using Bing News Search API http://mitchmckenna.com/post/16722/answer-by-mitchell-mckenna-for-getting-a-thumbnail-from-a-bing-news-result-using-bing-news-search-api

Use the url Bing Search gives you back to make a curl call to the url and get the image from the page's OGP data. Several libraries are available in multiple programming languages to parse a webpage's OGP data.

]]>
Mon, 16 May 2016 20:07:00 -0400 http://mitchmckenna.com/post/16722/answer-by-mitchell-mckenna-for-getting-a-thumbnail-from-a-bing-news-result-using-bing-news-search-api/answer-by-mitchell-mckenna-for-getting-a-thumbnail-from-a-bing-news-result-using-bing-news-search-api
Answer by Mitchell McKenna for Replacement for Twitter RSS API? http://mitchmckenna.com/post/13063/answer-by-mitchell-mckenna-for-replacement-for-twitter-rss-api

Here's 2 options:

  1. Use Twitter RSS - Google Apps Script from github to convert Twitter API 1.1 to RSS. Using this option you can get search results, users' timelines, users’ favorites or even Twitter Lists.
  2. Use twitter-rss.com to get a user's timeline (might include ads in the timeline).
]]>
Sat, 22 Jun 2013 17:14:00 -0400 http://mitchmckenna.com/post/13063/answer-by-mitchell-mckenna-for-replacement-for-twitter-rss-api/answer-by-mitchell-mckenna-for-replacement-for-twitter-rss-api
Building a Multi-Site Platform on Node.js - The Pros/Cons http://mitchmckenna.com/post/13047/building-a-multi-site-platform-on-nodejs-the-proscons

We're building a highly scalable platform that will be serving multiple millions of hits per day and servicing potentially multiple thousands of concurrent user connections.

This platform will support many sites that differ in purpose and functionality. For this reason, individual sites should be decoupled from the main platform by using an API. We'll cache where we can, but a lot of the sites are going to be dynamic with notifications and streaming updates so we'd like to use Websockets to create a great experience for the end user.

We're currently a PHP (LAMP) house, and trying to decide if we should use Node.js to only power the APIs (maybe Express), or if we should build the entire platform on Node.js? How does Node.js perform with backend processes such as manipulating large amounts of images, or long-running job queues to send out emails, compared to say Python or PHP? We're also considering Python (eg. Tornado), as it can be a solid 2nd place to Node.js for reqs/second while also very strong with backend processes (or maybe HipHop so we could stay with PHP for the backend processing stuff).

Does anyone have experience with building a platform with this much traffic on Node.js? Or do you have any other ideas?

]]>
Thu, 20 Jun 2013 19:41:00 -0400 http://mitchmckenna.com/post/13047/building-a-multi-site-platform-on-nodejs-the-proscons/building-a-multi-site-platform-on-nodejs-the-proscons
Answer by Mitchell McKenna for Wildcard search issue sphinx http://mitchmckenna.com/post/11986/answer-by-mitchell-mckenna-for-wildcard-search-issue-sphinx

The issue is that star(*) for wildcard is also in your ignore_chars (U+002A).

Update it to:

ignore_chars = U+0021..U+0029,U+002B..U+002F,U+003A..U+003F,U+0060

]]>
Thu, 25 Oct 2012 20:12:00 -0400 http://mitchmckenna.com/post/11986/answer-by-mitchell-mckenna-for-wildcard-search-issue-sphinx/answer-by-mitchell-mckenna-for-wildcard-search-issue-sphinx
Answer by Mitchell McKenna for What is the most ideal, cross-language method of executing an A/B split? http://mitchmckenna.com/post/9800/answer-by-mitchell-mckenna-for-what-is-the-most-ideal-cross-language-method-of-executing-an-ab-split

You should use mt_rand() over rand(). It's 4x faster than rand() because it uses a Mersenne Twister over the libc random number generator (see php.net).

You can then get an equivalent to mt_rand() for javascript from the php.js library.

]]>
Sun, 10 Jul 2011 14:49:00 -0400 http://mitchmckenna.com/post/9800/answer-by-mitchell-mckenna-for-what-is-the-most-ideal-cross-language-method-of-executing-an-ab-split/answer-by-mitchell-mckenna-for-what-is-the-most-ideal-cross-language-method-of-executing-an-ab-split
Answer by Mitchell McKenna for Codeigniter basepath issue on xampp http://mitchmckenna.com/post/9731/answer-by-mitchell-mckenna-for-codeigniter-basepath-issue-on-xampp

In your hosts file (C:\WINDOWS\system32\drivers\etc\hosts) add

127.0.0.1 dev.mysite.com

In your virtual host file for that site check the DocumentRoot has 'mysite' in it c:\xampp\apache\conf\extra\mysite.com.conf

DocumentRoot C:/path_to_my_website/site/www/htdocs/mysite/

]]>
Sun, 19 Jun 2011 18:48:00 -0400 http://mitchmckenna.com/post/9731/answer-by-mitchell-mckenna-for-codeigniter-basepath-issue-on-xampp/answer-by-mitchell-mckenna-for-codeigniter-basepath-issue-on-xampp
Answer by Mitchell McKenna for codeigniter form prepopulation http://mitchmckenna.com/post/9702/answer-by-mitchell-mckenna-for-codeigniter-form-prepopulation

You can use CI's form helper function set_value() which uses the $_POST and may save you some code testing if the $_POST value is empty because you can specify a default value if not set. Should be using this anyway if your using CI's form validation.

]]>
Mon, 13 Jun 2011 20:20:00 -0400 http://mitchmckenna.com/post/9702/answer-by-mitchell-mckenna-for-codeigniter-form-prepopulation/answer-by-mitchell-mckenna-for-codeigniter-form-prepopulation
Answer by Mitchell McKenna for Codeigniter form validation http://mitchmckenna.com/post/9700/answer-by-mitchell-mckenna-for-codeigniter-form-validation

Iterate over each field and check using form_error(), add any invalid field names to a single error string:

if($this->form_validation->run() == FALSE){ $fields = array('email_address', 'password'); $invalid_fields = array(); //where we'll store invalid field names foreach($fields as $field){ if(form_error($field)){ $invalid_fields[] = $field; } } $data['error_message'] = 'The following fields are invalid: ' . implode(",", $invalid_fields);

$this->load->view('yourview', $data); //if !empty($error_message) in view echo it out

]]>
Mon, 13 Jun 2011 06:35:00 -0400 http://mitchmckenna.com/post/9700/answer-by-mitchell-mckenna-for-codeigniter-form-validation/answer-by-mitchell-mckenna-for-codeigniter-form-validation
Answer by Mitchell McKenna for Using HTML5 Boilerplate Build script with a PHP framework http://mitchmckenna.com/post/9698/answer-by-mitchell-mckenna-for-using-html5-boilerplate-build-script-with-a-php-framework

Since your using Git anyway, check out Serkan Sökmen's github branch where he's got CI and HTML5 Boilerplate working together: Codeigniter---HTML5-Boilerplate

]]>
Mon, 13 Jun 2011 05:39:00 -0400 http://mitchmckenna.com/post/9698/answer-by-mitchell-mckenna-for-using-html5-boilerplate-build-script-with-a-php-framework/answer-by-mitchell-mckenna-for-using-html5-boilerplate-build-script-with-a-php-framework
Answer by Mitchell McKenna for Code Igniter problem, Getting a simple SQL error, what am I doing wrong? http://mitchmckenna.com/post/9686/answer-by-mitchell-mckenna-for-code-igniter-problem-getting-a-simple-sql-error-what-am-i-doing-wrong

Fix your query bindings:

$result = $this->db->query($query_str, array($username, $sha1_password));

]]>
Sat, 11 Jun 2011 15:55:00 -0400 http://mitchmckenna.com/post/9686/answer-by-mitchell-mckenna-for-code-igniter-problem-getting-a-simple-sql-error-what-am-i-doing-wrong/answer-by-mitchell-mckenna-for-code-igniter-problem-getting-a-simple-sql-error-what-am-i-doing-wrong
Answer by Mitchell McKenna for Make form remember earlier submitted values with CodeIgniter http://mitchmckenna.com/post/8591/answer-by-mitchell-mckenna-for-make-form-remember-earlier-submitted-values-with-codeigniter

If you are submitting to the same controller, you can get the previously submitted variables through $_POST (or $_GET depending on which form method you chose).

//use $_POST('name') if set, else use 'Name*' <?=form_input('name', (!empty($_POST('name')) ? $_GET('name) : 'Name*');?>

]]>
Tue, 26 Oct 2010 00:08:00 -0400 http://mitchmckenna.com/post/8591/answer-by-mitchell-mckenna-for-make-form-remember-earlier-submitted-values-with-codeigniter/answer-by-mitchell-mckenna-for-make-form-remember-earlier-submitted-values-with-codeigniter
Answer by Mitchell McKenna for Code Igniter Load Database seem to stop process thread http://mitchmckenna.com/post/8579/answer-by-mitchell-mckenna-for-code-igniter-load-database-seem-to-stop-process-thread

You need to load the db in in model or in the auto-config (see Anzeo's post) Can't access model like $this->Account_model->userId = 'asd'; - need to call functions You can't insert $this (also unsafe) Change Enabled field in db to type BOOLEAN (TinyInt is unnecessary)

The following should get your started... The Controller:

class SignUp extends Controller { function SignUp(){ parent::Controller(); } function createUser(){ echo 'processing'; $this->load->model('Account_model'); $result = $this->Account_model->insert($userId = 'asd', $userName = 'test_user', $enabled = 'true', $startOfDay = time()); echo ($result == TRUE) ? 'insert successful' : 'insert failed'; } }

The Model:

class Account_model extends Model { function Account_model(){ parent::Model(); $this->db = $this->load->database('default', TRUE); } function add_user($userId, $userName, $requestToken = '', $accessToken = '', $enabled = 'false', $startOfDay = '', $endOfDay = '') { $user = array( 'UserId' => $userId, 'UserName' => $userName, 'requestToken' => $requestToken, 'accessToken' => $accessToken, 'Enabled' => $enabled, 'startOfDay' => $startOfDay, 'endOfDay' => $endOfDay ); $this->db->insert('accounts', $user); return ($this->db->affected_rows() > 0) ? TRUE : FALSE; } } }

]]>
Mon, 25 Oct 2010 06:03:00 -0400 http://mitchmckenna.com/post/8579/answer-by-mitchell-mckenna-for-code-igniter-load-database-seem-to-stop-process-thread/answer-by-mitchell-mckenna-for-code-igniter-load-database-seem-to-stop-process-thread
Answer by Mitchell McKenna for What CodeIgniter template library is best? http://mitchmckenna.com/post/8559/answer-by-mitchell-mckenna-for-what-codeigniter-template-library-is-best

I recommend Phil Sturgeon's CodeIgniter Template.

Features include setting:

Page title - will predict a default if nothing is set Breadcrumbs Meta-data Layout files - wrapper around the loaded view Themes Partials - load any number of views in the layout (sidebar, menu, extra footer, etc) Loading views in modules and more

It is used in PyroCMS; a popular CI modular CMS (which Phil also founded).

I recently asked Colin William and Phil Sturgeon the difference between their templates. Although William's has better documentation, William's said Phil's has a couple features he hasn't added to his yet such as "support for themes (setting a base directory) & it's more actively developed".

]]>
Mon, 18 Oct 2010 05:08:00 -0400 http://mitchmckenna.com/post/8559/answer-by-mitchell-mckenna-for-what-codeigniter-template-library-is-best/answer-by-mitchell-mckenna-for-what-codeigniter-template-library-is-best
Answer by Mitchell McKenna for is there any view page caching for codeigniter http://mitchmckenna.com/post/8492/answer-by-mitchell-mckenna-for-is-there-any-view-page-caching-for-codeigniter

Check out MP_Cache library for CI, it's a way to cache parts of pages.

Compared to DB caching:

Reusable. Some parts (like your site menu’s) is the same on every page and probably doesn't need to be cached for each individual page. You only have to delete it once after a change was made to any part of it and not all the cache for every page that uses the changed information.

Compared to output cache:

Caching portions of a page isn’t a problem. Different cache for different uses of a function aren’t a problem as you can add a variable in the cache “name”

You can read more about it on its CI Wiki Page.

Other libraries include: Fragment Caching Library and Sparks (un-supported).

]]>
Fri, 08 Oct 2010 13:46:00 -0400 http://mitchmckenna.com/post/8492/answer-by-mitchell-mckenna-for-is-there-any-view-page-caching-for-codeigniter/answer-by-mitchell-mckenna-for-is-there-any-view-page-caching-for-codeigniter
Answer by Mitchell McKenna for Codeigniter: Compare a MySql Datetime with Current Date http://mitchmckenna.com/post/8488/answer-by-mitchell-mckenna-for-codeigniter-compare-a-mysql-datetime-with-current-date

Check out the PHP date_diff() function, for example:

$datetime1 = date_create('2009-10-11'); $datetime2 = date_create('2009-10-13'); $interval = date_diff($datetime1, $datetime2); echo $interval->format('%R%d days');

The above example will output:

+2 days

You can get the current time using getdate().

]]>
Thu, 07 Oct 2010 20:35:00 -0400 http://mitchmckenna.com/post/8488/answer-by-mitchell-mckenna-for-codeigniter-compare-a-mysql-datetime-with-current-date/answer-by-mitchell-mckenna-for-codeigniter-compare-a-mysql-datetime-with-current-date