snippets / alqimantas / 

All alqimantas's snippets (8)

  1. PHP random password

    Generates random php password from [0-9a-z] characters.

    1 <?php echo base_convert(rand(0, PHP_INT_MAX) . rand(0, PHP_INT_MAX), 10, 36);
    first posted by alqimantas to php php random password ... saved by 1 person ... 0 comments ... 7 months, 2 weeks
  2. MySQL random password string

    Random string (like password).

    1 SELECT CONV(FLOOR(RAND() * 99999999999999), 10, 36);
    first posted by alqimantas to sql mysql random password ... saved by 1 person ... 0 comments ... 7 months, 2 weeks
  3. Object equality comparison

    Interface for object equality comparison and sample model class.

     1 <?php
    2
    3 interface Compareble_Equals
    4 {
    5 public function equals(self $other);
    6 }
    7
    8
    9 class SampleModel extends ActiveRecord implements Comparable_Equals
    10 {
    11 public function equals(self $other)
    12 {
    13 return $this['id'] == $other['id'];
    14 }
    15 }
    first posted by alqimantas to php object quals interface ... saved by 1 person ... 0 comments ... 1 year, 1 month
  4. Generate random password

    Simple straightforward algorithm

     1 <?php
    2
    3 function generate_random_password($length = 8)
    4 {
    5 $charset = 'qwertyuioplkjhgfdsazxcvbnm1234567890';
    6 $last_char_pos = strlen($charset) - 1;
    7
    8 $password = '';
    9
    10 for ($i = 0; $i < $length; $i++) {
    11 $char = rand(0, $last_char_pos);
    12 $password .= $charset[$char];
    13 }
    14
    15 return $password;
    16 }
    first posted by alqimantas to php generate random password ... saved by 1 person ... 0 comments ... 1 year, 1 month
  5. Check wether string end with a given string

    .

     1 <?php
    2
    3 function string_ends_with($string, $ending)
    4 {
    5 $len = strlen($ending);
    6 $string_end = substr($string, strlen($string) - $len);
    7
    8 return $string_end == $ending;
    9 }
    10
    11 ?>
    first posted by alqimantas to php php string ends ... saved by 1 person ... 0 comments ... 1 year, 1 month
  6. Check whether string begins with given string

    .

    1 <?php
    2
    3 function string_begins_with($string, $search)
    4 {
    5 return (strncmp($string, $search, strlen($search)) == 0);
    6 }
    7
    8 ?>
    first posted by alqimantas to php php string begins starts ... saved by 1 person ... 0 comments ... 1 year, 1 month
  7. Get file extension

    .

    1 <?php
    2
    3 function file_extension($filename)
    4 {
    5 $path_info = pathinfo($filename);
    6 return $path_info['extension'];
    7 }
    8
    9 ?>
    first posted by alqimantas to php file extension php ... saved by 1 person ... 0 comments ... 1 year, 1 month
  8. Sample php date calculations

    Why do I need to fill notes?

    1 Today: <?php echo date('Y-m-d') ?> <br />
    2 Tomorrow: <?php echo date('Y-m-d', strtotime('+1 day')) ?> <br />
    3 1 week later: <?php echo date('Y-m-d', strtotime('+1 week')) ?> <br />
    4 1 month later: <?php echo date('Y-m-d', strtotime('+1 month')) ?> <br />
    first posted by alqimantas to php date ... saved by 1 person ... 0 comments ... 1 year, 1 month
showing 10, 25, 50 items per pages

Pages : 1