Skip to content

Instantly share code, notes, and snippets.

View HoangPV's full-sized avatar

Hoang Phan HoangPV

  • Ho Chi Minh City, Vietnam
View GitHub Profile
@HoangPV
HoangPV / MaxiLenDiff.php
Last active November 3, 2017 07:48
MaxiLenDiff.php
<?php
namespace CodeBundle\Functions;
/**
* Class MaxiLenDiff
* @package CodeBundle\Functions
* @see https://www.codewars.com/kata/maximum-length-difference/train/php
*/
class MaxiLenDiff
@HoangPV
HoangPV / session_example_config.php
Last active May 19, 2021 16:26
PHP MySQL Login System
<?php
define('DB_USERNAME', 'root');
define('DB_PASSWORD', 'Hoang123');
define('DB_NAME', 'session_example');
define('DB_SERVER', 'localhost');
/* Attempt to connect to MySQL database */
/** @var mysqli $mysqli */
$mysqli = new mysqli(DB_SERVER, DB_USERNAME, DB_PASSWORD, DB_NAME);
@HoangPV
HoangPV / password_hash_example.php
Created November 2, 2017 02:52 — forked from jeremykendall/password_hash_example.php
Example of password hashing and verification with password_hash and password_verify. This script is intended to be run from the command line like so: 'php -f password_hash_example.php'
<?php
/**
* Example of password hashing and verification with password_hash and
* password_verify
*
* This script is intended to be run from the command line
* like so: 'php -f password_hash_example.php'
*
* @see http://stackoverflow.com/a/20809916/1134565
@HoangPV
HoangPV / TicTacToeChecker.php
Created November 1, 2017 09:43
Tic-Tac-Toe Checker
<?php
$arr = array(
array( 1, 0, 0 ),
array( 2, 0, 0 ),
array( 1, 0, 0 ),
);
function is_solved( $arr ) {
@HoangPV
HoangPV / dashatize.php
Created September 25, 2017 08:43
Dashatize it
<?php
/**
* Dashatize it
*
* @author Phan Vu Hoang <[email protected]>
*/
require '../vendor/autoload.php';
@HoangPV
HoangPV / step.php
Created September 21, 2017 02:59
Steps in Primes
<?php
function step($g, $m, $n) {
$pairs = $primes = [];
if ($g >= 2 && $m >=2 && n >= 2) {
for ($i=$m; $i <=$n ; $i++) {
if (isPrime($i)) {
@HoangPV
HoangPV / is-prime.php
Created September 20, 2017 08:00
checks if a number is prime
<?php
/**
* checks if a number is prime
*
* @return bool
* @author Phan Vu Hoang <[email protected]>
*/
function la_snt( $n ) {
if($n < 2) return false;
@HoangPV
HoangPV / alphabet_position.php
Created September 18, 2017 06:25
Replace With Alphabet Position (alt solution)
<?php
function alphabet_position( $str ) {
$str = strtolower( $str );
$alphabetChars = 'abcdefghijklmnoqrstuvwxyz';
$report=[];
foreach (str_split($str) as $char) {
$g = (strpos($alphabetChars, $char) !== false) ? strpos($alphabetChars, $char) : '';
if ($g!=='') {
@HoangPV
HoangPV / replace-w-alphabet-position.php
Created September 18, 2017 03:18
Replace With Alphabet Position
<?php
/**
* Replace With Alphabet Position
*
* @author Phan Vu Hoang <[email protected]>
*/
function alphabet_position(string $str) {
$ar_pos = [];
@HoangPV
HoangPV / str_putcsv.php
Created September 13, 2017 08:41
Convert a multi-dimensional, associative array to CSV data
<?php
/**
* Convert a multi-dimensional, associative array to CSV data
* @param array $data the array of data
* @return string CSV text
*/
function str_putcsv($data) {
# Generate CSV data from array
$fh = fopen('php://temp', 'rw'); # don't create a file, attempt
# to use memory instead