⚗️ TIPS.LUUSE.IO 🖥️

Code that might work

Bash

  • Rename all files by number in a directory

    $ ls | cat -n | while read n f; do mv "$f" `printf "%02d.png" $n`; done
  • Show Key Name

    showkey - examine the codes sent by the keyboard

        $ showkey -a 
        Press any keys - Ctrl-D will terminate this program
        a    97 0141 0x61
  • Grep

    Find content into directory files.
        grep "some string" . -R
  • Make File Executable

    chmod u+x script.sh

Bootable usb (linux)

Voici le processus pour générer une clé usb d'installation d'un système Gnu/Linux. Avant tout, il faut se procurer un .iso du système à installer et une clé USB avec un espace de stokage supérieur à cet .iso.

  • Trouver le périphérique de la clé USB

      $ sudo fdisk -l
      ...
      Disque /dev/sdb : 7,2 GiB, 7763656704 octets, 15163392 secteurs
      Modèle de disque : USB DISK 2.0    
      Unités : secteur de 1 × 512 = 512 octets
      Taille de secteur (logique / physique) : 512 octets / 512 octets
      taille d'E/S (minimale / optimale) : 512 octets / 512 octets
      Type d'étiquette de disque : dos
      Identifiant de disque : 0x39d2fa1e
      ...

    Dans la réponse vous devez récupérer un chemin qui doit ressembler à quelque chose comme ça /dev/sdx dans cet exemple nous avons /dev/sdb.

  • Générer la clé USB à partir de l'Iso

      $ dd if=image.iso of=/dev/sdb bs=4M && sync

    Si cette opération ne fonctionne pas essayez de reformater la clé.

CSS

image pseudo-monochrome

<div class="filtered">
  <img src="https://icatcare.org/app/uploads/2018/06/Layer-1704-1920x840.jpg">
</div>
.filtered {
   background: yellow;
   position: relative;
}
.filtered img {
  -webkit-filter: grayscale(100%);
  filter: grayscale(100%);
  opacity: 0.5;
}

ffmpeg

  • Concatenate

      ffmpeg -i ressources_2.mp4 -i ressources_3.mp4 -filter_complex "concat=n=2:v=0:a=0" resources_1.mp4
      ffmpeg -i input.mp4 -i input.mp4 -filter_complex "concat=n=2:v=0:a=0" output.mp4
  • Extract Images at Framerate

      ffmpeg -i video.mp4 -vf fps=framerate output_images%02d.jpg
  • Mov to mp4

      ffmpeg -i movie.mov -vcodec copy -acodec copy out.mp4
  • 1.5 scaling

      ffmpeg -i output.mp4 -vf "scale=iw/1.5:ih/1.5" output3.mp4
  • Cutting

      ffmpeg -ss 00:00:00.0 -i boctok.mp4 -c copy -t 00:01:18.0 cut2.mp4
  • Get first frame -- same size

      ffmpeg -i bocto-site.mp4 -vf "select=eq(n\,0)" -q:v 3 bisous.jpg
  • Get frame at time

      ffmpeg -ss 00:23:45 -i input -vframes 1 -q:v 2 output.jpg
      ffmpeg -ss 0.5 -i inputfile.mp4 -t 1 -s 480x300 -f image2 imagefile.jpg
    
  • Convert images to video

      ffmpeg -framerate 1 -pattern_type glob -i '*.jpg' -c:v libx264 -r 3 out.mp4

fish

The friendly interactive shell. website

  • Define Fish to default shell

    1. Shows the full path of fish with which or whereis:
      $ which fish
      > /usr/bin/fish
    2. Now, change your login shell:
      chsh -s /usr/bin/fish
  • Alias

    Add alias (exemple):

      $ alias x="exit"

    Save alias:

      $ funcsave x

Git

  • Git Log

    Decoration

    git log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold cyan)%aD%C(reset) %C(bold green)(%ar)%C(reset)%C(bold yellow)%d%C(reset)%n''          %C(white)%s%C(reset) %C(dim white)- %an%C(reset)' --all 

    git log color After you can build an alias.

  • .gitignore Grav Project

    .libsass.json
    .DS_Store
    *.min.css
    *.css.map
    accounts/*
    plugins/*
    *.png
    *.PNG
    *.jpg
    *.JPG
    *.jpeg
    *.JPEG
    *.GIF
    *.gif
    *.mp4
    *.MP4
    *.tiff
    *.tif
    *.TIFF
    

Imagmagick

  • Turn pngs into gifs

    convert -delay 60 *.png -loop 0 live3.gif convert rose.jpg -resize 80% rose.png 
  • Pdf to png > all files in a directory

    mogrify -density 300 -format png *.pdf
  • 72 dpi

    convert -units PixelsPerInch input.png -density 72 output.png
  • resize %

    convert -resize 40% versions_44.png
  • Blur img

    convert -resize 10% -resize 1000% output_image.jpg blured.jpg

Inotifywait

Inotifywait efficiently waits for changes to files using Linux's inotify interface. It is suitable for waiting for changes to files from shell scripts. It can either exit once an event occurs, or continually execute and output events as they occur.

  • Install

On Archlinux : sudo pacman -Ss inotify-tools.
With npm : npm install -g inotify.

  • Exemples

If you want make an event with recursives files. '.' is the root path.

#!/usr/bin/env bash

inotifywait -m -r '.' -e create -e moved_to |
while read path action file; do
  echo 'ACTION HERE!!';
done

Javascript

  • XMLHttpRequest

var xhr = new XMLHttpRequest()
xhr.open('GET', 'https://your.site')
xhr.send(null)

xhr.onreadystatechange = function () {
    var DONE = 4
    var OK = 200
    if (xhr.readyState === DONE) {
        if (xhr.status === OK) {
            console.log('yes')
        } else {
            console.log('Error: ' + xhr.status)
        }
    }
}

Php

  • Run php without apache

    In your shell:

      php -S localhost:8000

    if you want start at a different root:

      php -S localhost:8000 -t </path/to/root>
  • Slugify

    
    public function slugify($string){
    
      $string = str_replace(array('[\', \']'), '', $string);
      $string = preg_replace('/\[.*\]/U', '', $string);
      $string = preg_replace('/&(amp;)?#?[a-z0-9]+;/i', '-', $string);
      $string = htmlentities($string, ENT_COMPAT, 'utf-8');
      $string = preg_replace('/&([a-z])(acute|uml|circ|grave|ring|cedil|slash|tilde|caron|lig|quot|rsquo);/i', '\\1', $string );
      $string = preg_replace(array('/[^a-z0-9]/i', '/[-]+/') , '-', $string);
    
      return strtolower(trim($string, '-'));
    }
  • Regex for type (french)

    function rft($content) {
      $thinsp = '<span class="thinsp">&nbsp;</span>';
      $regex = array(
          "/ ;/"    => ';',
        "/« /"      => '«',
          "/“ /"    => '«',
          "/ »/"    => '»',
          "/ ”/"    => '»',
          "/ :/"    => ':',
          "/ !/"    => '!',
        "/ €/"    => '€',
        "/ $/"    => '$',
        "/ £/"    => '£',
          "/ \?/"   => '?',
          "/:/"     => $thinsp . ':',
        "/«/"     => '«' . $thinsp,
          "/“/"     => '«' . $thinsp,
        "/»/"       => $thinsp . '»',
        "/€/"     => $thinsp . '€',
        "/$/"     => $thinsp . '$',
        "/£/"     => $thinsp . '£',
          "/”/"     => $thinsp . '»',
          "/!/"     => $thinsp . '!',
          "/\?/"    => $thinsp . '?',
          "/& /"    => '&amp; ',
          "/oe/"    => '&#339;',
          "/ae/"    => '&#230;',
          "/OE/"    => '&#338;',
          "/AE/"    => '&#198;',
          "/\.\.\./"=> '&#8230;',
          # url bug correction
          '/http<span class="thinsp">&nbsp;<\/span>:/' => 'http:',
          '/https<span class="thinsp">&nbsp;<\/span>:/' => 'https:',
          '/href="mailto<span class="thinsp">&nbsp;<\/span>:/' => 'href="mailto:',
          '/watch<span class="thinsp">&nbsp;<\/span>?/' => 'watch',
     });
    
      foreach ($regex as $input => $output) {
          $content = preg_replace($input, $output, $content);
        }
        return $content;
      }

    Then use the css property letter-spacing on .thinsp to set the width value of your thinspace.

  • Regex for type (english)

    function rft($content) {
      $thinsp = '<span class="thinsp">&nbsp;</span>';
      $regex = array(
          "/ ;/"    => ';',
          "/« /"    => '«',
          "/“ /"    => '“',
          "/ »/"    => '»',
          "/ ”/"    => '”',
          "/ :/"    => ':',
          "/ !/"    => '!',
          "/ €/"    => '€',
          "/ $/"    => '$',
          "/ £/"    => '£',
          "/ \?/"   => '?',
          "/«/"     => '«' . $thinsp,
          "/»/"     => $thinsp . '»',
          "/€/"     => $thinsp . '€',
          "/$/"     => $thinsp . '$',
          "/£/"     => $thinsp . '£',
          "/& /"    => '&amp; ',
          "/oe/"    => '&#339;',
          "/ae/"    => '&#230;',
          "/OE/"    => '&#338;',
          "/AE/"    => '&#198;',
          "/\.\.\./"=> '&#8230;',
            # url bug correction
          '/http<span class="thinsp">&nbsp;<\/span>:/' => 'http:',
          '/https<span class="thinsp">&nbsp;<\/span>:/' => 'https:',
          '/href="<main></main>ilto<span class="thinsp">&nbsp;<\/span>:/' => 'href="mailto:',
          '/watch<span class="thinsp">&nbsp;<\/span>?/' => 'watch',
         });
    
        foreach ($regex as $input => $output) {
              $content = preg_replace($input, $output, $content);
        }
        return $content;
    }

    Then use the css property letter-spacing on .thinsp to set the width value of your thinspace.

Twig

  • Access item at index in associative array

    array|slice(index, 1)|first

Vim

  • Replace.

    Simple replace

    All in content

      :%s/paul/luc/g

    Remove all balise xml/html

      :%s/<[^>]*>//g

youtube-dl

Download videos from youtube.com or other video platforms - github

  • Download playlist from youtube

      youtube-dl --extract-audio --audio-format mp3 -o "%(title)s.%(ext)s" <url to playlist>
Our favorite softwares