Posts

repeated-string

 https://www.hackerrank.com/challenges/repeated-string/forum <?php function repeatedString ( $s , $n ) { // Length of the original string $s_len = strlen( $s ); // Count 'a' occurrences in the original string $a_in_s = 0 ; for ( $i = 0 ; $i < $s_len ; $i ++) { if ( $s [ $i ] == 'a' ) { $a_in_s ++; } } // Calculate full string repetitions $whole_repetitions = floor( $n / $s_len ); // Count 'a' in full repetitions $total_a = $a_in_s * $whole_repetitions ; // Handle the remainder $remainder = $n % $s_len ; // Count 'a' in the remainder for ( $i = 0 ; $i < $remainder ; $i ++) { if ( $s [ $i ] == 'a' ) { $total_a ++; } } return $total_a ; } // Read input (replace with actual input mechanism) $s = fgets(STDIN); $n = ( int )fgets(STDIN); // Call the function and print the result $result = repeatedString(trim( $s ), $n ); echo $result ; ?>

Câu hỏi phỏng vấn - Technical

Image
 1 - Kiến trúc phần mềm - Architecture 1.1 n tier layer 1.2 event driven 1.3 Object oriented  1.4 Micro service 1.5 Plugin (extensions) Browser 2 - Design Pattern 2.1 Singleton Pattern - Không dùng new để khởi tạo object, thay vào đó sẽ có 1 hàm dạng như static getInstance  - 1 lớp chỉ có 1 đối tượng - Các object có cùng 1 state 2.2 Prototype Pattern - Copy one object to another without creating new object - Đối tượng ban đầu được gọi là prototype 2.3 Builder Pattern https://laraveldaily.com/post/design-patterns-laravel-builder-example - Dùng các setter để thay đổi value của property của 1 object - Không cần khai báo new object với đầy đủ param ở constructor, khi cần chỉ cần dùng setter để set giá trị cho các param 2.4 Repository Pattern 3 - ORM là gì - Object relation mapping - 1 table = 1 object - manage data in that table by object (ORM) 4 - agile engineering practices 4.1 Continuous Integration 4.2 Automated Unit Testing 4.3 Automated Acceptance T...

Git: What's the best practice to "git clone" into an existing folder?

  git clone https://myrepo.com/git.git temp mv temp/.git code/.git rm -rf temp

Câu hỏi pv php + mysql

Image
PHP  1) What will be the output of those code? var_dump(0123 == 123); var_dump( '0123' == 123); var_dump( '0123' === 123); 2) Multiple inheritance là gì? PHP có support ko? class A extends class B, class C PHP ko support. 3) trait php là gì 4) yield 5)  How can I measure the speed of code written in PHP --> $before = microtime( true ); for ( $i = 0 ; $i < 100000 ; $i ++) { serialize( $list ); } $after = microtime( true ); echo ( $after - $before )/ $i . " sec/serialize\n" ; 7) How to check how much memory your PHP scripts use memory_get_usage 8) what is difference between: $resp = json_decode(file_get_contents($url), TRUE); $resp = json_decode(@file_get_contents($url), TRUE); -> php suppression error (error control operator) 9) Trong Laravel xem log ở đâu, đã từng dùng third party nào để check log? 10) khai báo shallow() trong route. Shallow Nesting Route? https://laravel.com/docs/8.x/controllers#shallow-nesting 11) authenticate with OA...

Notifiable trait trong Laravel

Image
khi 1 class sử dụng Notifiable , tức là class đó có thể gọi method  notify Ví dụ như sau :  use App\Notifications\ InvoicePaid ;   $user -> notify ( new InvoicePaid ( $invoice )); Trong ví dụ trên InvoicePaid là 1 class được khai báo ở App\Notifications Trong Laravel, notification có thể gửi dưới dạng Channel gồm Mail Slack Database Telegram ....