E-mail extraction from an Outlook copied string

Sometimes you need to extract an e-mail address from a format like this:

Name Surname <[email protected]>

In such cases use this function:

/**
 * Extract mail address from a string
 * 
 * @param string $emailString
 * @return mixed match on success, false on error
 */
function extractEmail( $emailString ) {
    /** @var string $result **/
    $result = preg_match( '/^(?:[\w.\- ]+<)?([\w._-][email protected][\da-z\.-]+\.[a-z\.]{2,6})>?$/iu', $emailString, $matches );
                               
    if( $result === 1 || $result !== false ) {
        return $matches[1];
    } else {
        return false;
    }      
}

Link to test regular expression used by me is here.

A MAN LEARNS THROUGHOUT HIS WHOLE LIFE

If you’re a fan of Firefox (mainly because it’s an awesome tool for webdevelopment) like me. You should already know that there’s an additional console for developers (I’ve did not until five minutes ago). When you press Shift + F2 it shows little input bar on the bottom of the window. For example type the following command :

screenshot --clipboard --fullpage

Press Enter and BANG! Screenshot of a entire page in your MEMORY!

Mother of God… This is so awesome!

PS. Try different commands, you can use Tab for completion and help to list them all.

How to unfreeze KDE’s plasmashell?

I’m using Debian 9.4 and this freaking KDE5 is freezing very often! What you can do when your desktop stops responding? Restart computer? Use ALT+CTRL+F1…12? Nah! There’s a better solution!

Simply edit your  ~/.bash_aliases:

nano ~/.bash_aliases

And append to it:

alias restart-plasma='kquitapp5 plasmashell && kstart plasmashell'

Now whenever your plasma desktop starts trolling you, go to your console and type restart-plasma voilàDezombified!

PS. Use tilda to open console in every shitty situation you’ll get into! Simply press F12 and you’ll get nice Quake like terminal.

Feel like a ninja
Feel like a Linux ninja

Quick optimization of jpeg files in a directory (Linux bash)

Firstly install jpegoptim.

You can do this on Debian like systems using apt:

sudo apt-get update && sudo apt-get install jpegoptim

Then go to directory with jpeg files and use this command:

find . -name '*.jpg' -exec jpegoptim -m70 -o -f --strip-all {} \;

It will find all jpg files recursively and optimize with following settings:

  • m70 stands for jpeg quality (about 70 – 80 should be fine but lossy)
  • o is for overwrite
  • f is for force
  • strip-all removes all EXIF and other textual data from files

Start a new project with grunt & github for (total) dummies…

This short article will guide you through very basics of web development automatization. You’ll need a terminal and some basic knowledge how to use it. I work on Linux bash but it can be basically anything (well maybe not AmigaDOS). I’ll cover git basics also.

Continue reading Start a new project with grunt & github for (total) dummies…