Today I learned - Page 4
Page 4 of 20 FirstFirst ... 2345614 ... LastLast
Results 46 to 60 of 296

Thread: Today I learned

  1. #46
    Senior Member cluelessPHP's Avatar
    Join Date
    Apr 2015
    Location
    Scotland
    Posts
    493
    Today I learned

    HTML Code:
    var supported = document.implementation.hasFeature('Events', '4.0');
    var supporteddom3 = document.implementation.hasFeature('Events', '3.0');
    Once you had a good excuse, you opened the door to bad excuses ― Terry Pratchett, Thud
    Fresh start
    Github version
    Current date 14/10/17
    Finish date "should be" 14/04/18

    Vote on your preferred indentation method

  2. #47
    Senior Member cluelessPHP's Avatar
    Join Date
    Apr 2015
    Location
    Scotland
    Posts
    493
    Today I learned

    Once you had a good excuse, you opened the door to bad excuses ― Terry Pratchett, Thud
    Fresh start
    Github version
    Current date 14/10/17
    Finish date "should be" 14/04/18

    Vote on your preferred indentation method

  3. #48
    Senior Member cluelessPHP's Avatar
    Join Date
    Apr 2015
    Location
    Scotland
    Posts
    493
    Today I learned

    HTML Code:
    var d = new Date();
    	var n = d.getFullYear();
    	console.log(n);
    	 
    	var val = Number.MAX_VALUE; 
    	
    	var i = 0;
    	while (n < val) 
    	{
    		document.write ("Time until mastered JavaScript " + val ); 
    		i++;
    	}
    Once you had a good excuse, you opened the door to bad excuses ― Terry Pratchett, Thud
    Fresh start
    Github version
    Current date 14/10/17
    Finish date "should be" 14/04/18

    Vote on your preferred indentation method

  4. #49
    High Energy Magic Dept. NogDog's Avatar
    Join Date
    Aug 2006
    Location
    Ankh-Morpork
    Posts
    14,888
    Today I learned you can set the default timezone for PostgreSQL at the session level or at the database level if needed.
    "Well done....Consciousness to sarcasm in five seconds!" ~ Terry Pratchett, Night Watch

    How to Ask Questions the Smart Way (not affiliated with this site, but well worth reading)

    My Blog
    cwrBlog: simple, no-database PHP blogging framework

  5. #50
    Senior Member cluelessPHP's Avatar
    Join Date
    Apr 2015
    Location
    Scotland
    Posts
    493
    Today I learned lots-many-two useful php things
    Once you had a good excuse, you opened the door to bad excuses ― Terry Pratchett, Thud
    Fresh start
    Github version
    Current date 14/10/17
    Finish date "should be" 14/04/18

    Vote on your preferred indentation method

  6. #51
    Settled 4 red convertible dalecosp's Avatar
    Join Date
    Jul 2002
    Location
    Accelerating Windows at 9.81 m/s....
    Posts
    8,525
    Today I learned (I think) that VirtualBox *still* leaks memory on this workstation if you run it too long without a reboot....
    /!!\ mysql_ is deprecated --- don't use it! Tell your hosting company you will switch if they don't upgrade! /!!!\ ereg() is deprecated --- don't use it!

    dalecosp "God doesn't play dice." --- Einstein "Perl is hardly a paragon of beautiful syntax." --- Weedpacket

    Getting Help at All --- Collected Solutions to Common Problems --- Debugging 101 --- Unanswered Posts --- OMBE: Office Machines, Business Equipment

  7. #52
    High Energy Magic Dept. NogDog's Avatar
    Join Date
    Aug 2006
    Location
    Ankh-Morpork
    Posts
    14,888
    Quote Originally Posted by dalecosp View Post
    Today I learned (I think) that VirtualBox *still* leaks memory on this workstation if you run it too long without a reboot....
    Time to try Docker? (It can be a real disk hog, though, if you don't keep an eye on it and clean up unused containers.)
    "Well done....Consciousness to sarcasm in five seconds!" ~ Terry Pratchett, Night Watch

    How to Ask Questions the Smart Way (not affiliated with this site, but well worth reading)

    My Blog
    cwrBlog: simple, no-database PHP blogging framework

  8. #53
    Settled 4 red convertible dalecosp's Avatar
    Join Date
    Jul 2002
    Location
    Accelerating Windows at 9.81 m/s....
    Posts
    8,525
    Quote Originally Posted by NogDog View Post
    Time to try Docker? (It can be a real disk hog, though, if you don't keep an eye on it and clean up unused containers.)
    Looking into it now. What would the advantages be? Does the container act similar to a FreeBSD "Jail" and have hard limits on RAM & stuff? (Hmm. Your second sentence might indicate otherwise ...) ... and dang, that license has a LOT of legal-eagle-junk to read.
    /!!\ mysql_ is deprecated --- don't use it! Tell your hosting company you will switch if they don't upgrade! /!!!\ ereg() is deprecated --- don't use it!

    dalecosp "God doesn't play dice." --- Einstein "Perl is hardly a paragon of beautiful syntax." --- Weedpacket

    Getting Help at All --- Collected Solutions to Common Problems --- Debugging 101 --- Unanswered Posts --- OMBE: Office Machines, Business Equipment

  9. #54
    High Energy Magic Dept. NogDog's Avatar
    Join Date
    Aug 2006
    Location
    Ankh-Morpork
    Posts
    14,888
    Quote Originally Posted by dalecosp View Post
    Looking into it now. What would the advantages be? Does the container act similar to a FreeBSD "Jail" and have hard limits on RAM & stuff? (Hmm. Your second sentence might indicate otherwise ...) ... and dang, that license has a LOT of legal-eagle-junk to read.
    I'm not an expert, mind you, just someone who has to use it at work and has played around with it just enough to get the general idea.

    For whatever reason, it seems less "flaky" to me than my prior experiences using Vagrant. The disk space issue was more about me not paying attention to the fact that, while playing around with it and trying different configs to spin up assorted environments, I didn't realize how much space each different config was taking, as well as each instance that was running or suspended (but not deleted). I suspect you'd have similar issues with Vagrant if you spun up a bunch of separate servers at the same time -- but I think maybe Docker made that easier for me to do?

    The power users of it on our team swear by it, and use it as an integral part of our continuous deployment strategy. I mostly just create bash aliases to do the common commands I need to use.
    "Well done....Consciousness to sarcasm in five seconds!" ~ Terry Pratchett, Night Watch

    How to Ask Questions the Smart Way (not affiliated with this site, but well worth reading)

    My Blog
    cwrBlog: simple, no-database PHP blogging framework

  10. #55
    Senior Member cluelessPHP's Avatar
    Join Date
    Apr 2015
    Location
    Scotland
    Posts
    493
    Today I learned Fife college will sink to any level
    Once you had a good excuse, you opened the door to bad excuses ― Terry Pratchett, Thud
    Fresh start
    Github version
    Current date 14/10/17
    Finish date "should be" 14/04/18

    Vote on your preferred indentation method

  11. #56
    High Energy Magic Dept. NogDog's Avatar
    Join Date
    Aug 2006
    Location
    Ankh-Morpork
    Posts
    14,888
    Today I learned how fast I can go from looking at a JIRA ticket, moving it to "in progress", making a fix, committing it to Git, creating a pull request on GitHub and moving the JIRA ticket to "in pull request", getting a review and thumbs-up, merging the Git branch, deploying the fix to Test and moving the JIRA ticket to "ready for QA", getting it tested, and moving the JIRA ticket to "resolved" and deleting the bug-fix branch on GitHub.

    About 30 minutes, give or take.
    "Well done....Consciousness to sarcasm in five seconds!" ~ Terry Pratchett, Night Watch

    How to Ask Questions the Smart Way (not affiliated with this site, but well worth reading)

    My Blog
    cwrBlog: simple, no-database PHP blogging framework

  12. #57
    Senior Member cluelessPHP's Avatar
    Join Date
    Apr 2015
    Location
    Scotland
    Posts
    493
    PHP Code:
    <?php 
    require "errorHandler.php";
    require 
    "Validator.php";

    $errorHandler = new ErrorHandler;


    if(!empty(
    $_POST))
    {
        
    $validator = new Validator($errorHandler);
        
        
    $validation $validator->check($_POST, [
        
    'username' =>[
        
    'required'=> true,
        
    'maxlength' => 20,
        
    'minlength' => 3
        
    ]
        ]);
        
        if(
    $validation->fails())
    {
        
        echo 
    '<pre>' print_r($validation->errors()->all()) . '</pre>';
    }
    }


    ?>
    PHP Code:
    <?php

    class ErrorHandler
    {
        protected 
    $errors = [];
        
        public function 
    addError($error$key null)
        {
            if(
    $key)
            {
                
    $this->errors[$key][] = $error;
            }    
            else
            {
                
    $this->errors[] = $error;
            }    
        }
        
        public function 
    all($key null)
        {
            return isset(
    $this->errors[$key]) ? $this->errors[$key] : $this->errors;
        }
        public function 
    hasErrors()
        {
            return 
    count($this->all()) ? true false;
        }
        
        public function 
    first($key)
        {
            return isset(
    $this->all()[$key][0]) ? $this->all()[$key][0]: false;
        }
    }

    PHP Code:
    <?php



    class Validator
    {
        
        protected 
    $errorHandler;
        protected 
    $rules = ['required''minlength''maxlength''email'];
        
        public 
    $messages = [
        
    'required' => 'The :field field is required',
        
    'minlength' => 'The :field field must be a min of :satisfier',
        
    'maxlength' =>  'The :field field must be a min of :satisfier',
        
    'email' => 'nope'
        
    ];
        public function 
    __construct(ErrorHandler $errorHandler)
        {
            
    $this->errorHandler $errorHandler;
        }
        
        public function 
    check($items$rules)
        {
            foreach(
    $items as $item => $value)
            {
                foreach(
    $items as $item => $value)
                {
                    if(
    in_array($itemarray_keys($rules)))
                    {
                        
    $this->validate([
                            
    'field' => $item,
                            
    'value' => $value,
                            
    'rules'  => $rules[$item
                        ]);
                    }
                }
            }
            return 
    $this;
        }
        
        public function 
    fails()
        {
            return 
    $this->errorHandler->hasErrors();
        }
        protected function 
    validate($item)
        {
            
    $field $item['field'];
            
            foreach(
    $item['rules'] as $rule => $satisfier)
            {
                if(
    in_array($rule$this->rules))
                {
                    if(!
    call_user_func_array([$this$rule], [$field$item['value'], $satisfier]))
                    {
                        
    $this->errorHandler->addError(
                        
    str_replace([':field'], [':satisfier'], [$field$satisfier], $this->messages[$rule]), 
                        
    $field);
                    }    
                }    
            }
        }
        
        public function 
    errors()
        {
            return 
    $this->errorHandler;
        }
        
        protected function 
    required($field$value$satisfier)
        {
            return !empty(
    trim($value));
        }
        
        protected function 
    minlength($field$value$satisfier)
        {
            return 
    mb_strlen($value) >= $satisfier;
        }
        
        protected function 
    maxlength($field$value$satisfier)
        {
            return 
    mb_strlen($value) <= $satisfier;
        }
        
        protected function 
    email($field$value$satisfier)
        {
            return 
    filter_var($valueFILTER_VALIDATE_EMAIL);
        }
    }
    Seems so so
    Once you had a good excuse, you opened the door to bad excuses ― Terry Pratchett, Thud
    Fresh start
    Github version
    Current date 14/10/17
    Finish date "should be" 14/04/18

    Vote on your preferred indentation method

  13. #58
    Settled 4 red convertible dalecosp's Avatar
    Join Date
    Jul 2002
    Location
    Accelerating Windows at 9.81 m/s....
    Posts
    8,525
    Quote Originally Posted by NogDog View Post
    Today I learned how fast I can go from looking at a JIRA ticket, moving it to "in progress", making a fix, committing it to Git, creating a pull request on GitHub and moving the JIRA ticket to "in pull request", getting a review and thumbs-up, merging the Git branch, deploying the fix to Test and moving the JIRA ticket to "ready for QA", getting it tested, and moving the JIRA ticket to "resolved" and deleting the bug-fix branch on GitHub.

    About 30 minutes, give or take.
    That's impressive. :-)
    /!!\ mysql_ is deprecated --- don't use it! Tell your hosting company you will switch if they don't upgrade! /!!!\ ereg() is deprecated --- don't use it!

    dalecosp "God doesn't play dice." --- Einstein "Perl is hardly a paragon of beautiful syntax." --- Weedpacket

    Getting Help at All --- Collected Solutions to Common Problems --- Debugging 101 --- Unanswered Posts --- OMBE: Office Machines, Business Equipment

  14. #59
    Senior Member cluelessPHP's Avatar
    Join Date
    Apr 2015
    Location
    Scotland
    Posts
    493
    Today I learned

    Once you had a good excuse, you opened the door to bad excuses ― Terry Pratchett, Thud
    Fresh start
    Github version
    Current date 14/10/17
    Finish date "should be" 14/04/18

    Vote on your preferred indentation method

  15. #60
    High Energy Magic Dept. NogDog's Avatar
    Join Date
    Aug 2006
    Location
    Ankh-Morpork
    Posts
    14,888
    Quote Originally Posted by dalecosp View Post
    That's impressive. :-)
    The first secret was that when I looked at the line of code pointed to by the error output, I immediately saw an extra closing parenthesis, something like
    Code:
    SomeClass::aStaticMethod()$argument);
    The second secret was that the developer who was sitting 5 feet away could approve the PR for me.

    The third secret was that the developer who was sitting 5 feet away could test it with his sync tool that originally found the problem and caused him to write the ticket in the first place.
    "Well done....Consciousness to sarcasm in five seconds!" ~ Terry Pratchett, Night Watch

    How to Ask Questions the Smart Way (not affiliated with this site, but well worth reading)

    My Blog
    cwrBlog: simple, no-database PHP blogging framework

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •