php - is isset way is faster than array_search?

Theory speaking, looking into hashmap (isset) is faster than array_search or in_array. But, let’s see how it work in php in practice. Look at this code block: function detectGender($keyword) { $gender = 0; $genderKeywords = [ 'MY' => [ 1 => 'men,male', 2 => 'women,female', ], 'SG' => [ 1 => 'men,male', 2 => 'women,female', ], 'HK' => [ 1 => 'men,male', 2 => 'women,female', ], 'PH' => [ 1 => 'men,male', 2 => 'women,female', ], 'TH' => [ 1 => 'ชาย,ผชาย', 2 => 'หญง,ผหญง', ], 'VN' => [ 1 => 'nam', 2 => 'nu', ], 'ID' => [ 1 => 'pria', 2 => 'wanita', ], ]; foreach ($genderKeywords['VN'] as $key => $keywords) { if (array_search($keyword, explode(',', $keywords)) !...

March 13, 2018 · 3 min · longka

Mockery exception: could not load mock class already exists

Mockery\Exception\RuntimeException: Could not load mock , class already exists When working with those spaghetti legacy code base, sometimes, it is fucking hard to write the test along with refactoring. We may face with some situation that need to mock the public static function call. class Foo { public function bar() { Utils::staticFunction(); // do another thing } } And the test class: use \Mockery as m; use Foo; class FooTest { public function testBar() { $out = new Foo(); $utils = m::mock('alias:Utils'); $util->shouldReceive('staticFunction')->withAnyArgs(); $out->bar(); // do another mock and test } } We use mockery to mock the static function call, run the test with single function, it’s green....

July 5, 2017 · 1 min · longka

SEO Bot baiting from idea to practice

What the hell is BOT: * Those big giant search engine has there own bot for scrapping all the data of the website everyday * Understanding how the search engine bot works will help us a lot when doing SEO Bot Bating concept: Main idea: injecting those page with high google search volume (GSV), but low google crawling frequency (GCF) INTO those pages have high GCF Google search volume (GSV) https://support....

July 4, 2017 · 1 min · longka

Don't make things complicated

This is the email I received from Edmond (blog) - author of The Effective Engineer book. I think it’s good to re-share here on my blog. – “It’ll only take me a few hours to implement the feature,” we sometimes say. But after finishing, we find that every few weeks, we’re either fixing a bug with the feature, explaining it to another engineer, or helping answer a question from customer support about how it works....

June 7, 2017 · 9 min · longka