Teknotit Snipet Manager



Api 2 Git 1 aleatoire 2 animation 1 apache2 4 bash 9 cache 1 css 17 curl 1 fastcgi 2 fichier 1 fonctions 10 html 5 inspiration 1 javascript 17 linux 17 mobile 2 mysql 2 nginx 3 php 21 postfix 2 repertoire 3 ssh 9 swap 1 sysadmin 13 taille 1 ubuntu 7 wordpress 8

.

Derniers snippets

acme.sh methode recommendé

https://github.com/acmesh-official/acme.sh/wiki/sudo

https://github.com/acmesh-official/acme.sh/wiki/sudo

<iframe width="100%" height="200" src="http://snipet.teknotit.com/index.php?embed=695fe45fb37dc" type="text/html"></iframe>

Texte seul - Permalink - Snippet public posté le 08/01/2026

Git stasg one file

git stash save -p "my commit message"

   y - stash this hunk
   n - do not stash this hunk
   q - quit; do not stash this hunk or any of the remaining ones
   a - stash this hunk and all later hunks in the file
   d - do not stash this hunk or any of the later hunks in the file
   g - select a hunk to go to
   / - search for a hunk matching the given regex
   j - leave this hunk undecided, see next undecided hunk
   J - leave this hunk undecided, see next hunk
   k - leave this hunk undecided, see previous undecided hunk
   K - leave this hunk undecided, see previous hunk
   s - split the current hunk into smaller hunks
   e - manually edit the current hunk
   ? - print help

Git

<iframe width="100%" height="488" src="http://snipet.teknotit.com/index.php?embed=5fbcba2e21457" type="text/html"></iframe>

Texte seul - Permalink - Snippet public posté le 24/11/2020

changer editeur par default

export EDITOR=/bin/nano
export VISUAL=nano


export EDITOR=/usr/bin/vim
export VISUAL=vim

linux

https://alltime.pp.ua/blog/how-to-change-default-crontab-editor/

<iframe width="100%" height="308" src="http://snipet.teknotit.com/index.php?embed=5e83f19431103" type="text/html"></iframe>

Texte seul - Permalink - Snippet public posté le 01/04/2020

Mulit-byte Unserialize

/**
 * Mulit-byte Unserialize
 *
 * UTF-8 will screw up a serialized string
 *
 * @access private
 * @param string
 * @return string
 */
function mb_unserialize($string) {
    $string = preg_replace('!s:(\d+):"(.*?)";!se', "'s:'.strlen('$2').':\"$2\";'", $string);
    return unserialize($string);
}

php

<iframe width="100%" height="434" src="http://snipet.teknotit.com/index.php?embed=5dfbeb2158cea" type="text/html"></iframe>

Texte seul - Permalink - Snippet public posté le 19/12/2019

améliortion de php7

Null Coalesce Operator

php

https://daylerees.com/php-pandas-php7/

<iframe width="100%" height="218" src="http://snipet.teknotit.com/index.php?embed=5d0d9302e1a25" type="text/html"></iframe>

Texte seul - Permalink - Snippet public posté le 22/06/2019

swap

fallocate -l 1G /swapfile
chmod 600 /swapfile
mkswap /swapfile
swapon /swapfile
sysctl vm.swappiness=20

nano /etc/fstab
/swapfile swap swap defaults 0 0

nano /etc/sysctl.conf => vm.swappiness=10



sysctl vm.vfs_cache_pressure=50

nano /etc/sysctl.conf => vm.vfs_cache_pressure=50

linux swap sysadmin

https://linuxize.com/post/how-to-add-swap-space-on-debian-9/

<iframe width="100%" height="488" src="http://snipet.teknotit.com/index.php?embed=5d0cfdfee2c09" type="text/html"></iframe>

Texte seul - Permalink - Snippet public posté le 11/03/2021

Download from google DRIVE

#!/bin/bash
fileid="### file id ###"
filename="MyFile.csv"
curl -c ./cookie -s -L "https://drive.google.com/uc?export=download&id=${fileid}" > /dev/null
curl -Lb ./cookie "https://drive.google.com/uc?export=download&confirm=`awk '/download/ {print $NF}' ./cookie`&id=${fileid}" -o ${filename}

curl

<iframe width="100%" height="290" src="http://snipet.teknotit.com/index.php?embed=5d0a3744d95aa" type="text/html"></iframe>

Texte seul - Permalink - Snippet public posté le 19/06/2019

Email forwrding

Intersssant

https://improvmx.com/guides/send-emails-using-gmail

<iframe width="100%" height="200" src="http://snipet.teknotit.com/index.php?embed=5cea25d641966" type="text/html"></iframe>

Texte seul - Permalink - Snippet public posté le 26/05/2019

startup script

startup script

ssh

https://ritsch.io/2017/08/02/execute-script-at-linux-startup.html

<iframe width="100%" height="200" src="http://snipet.teknotit.com/index.php?embed=5cae28683bbbf" type="text/html"></iframe>

Texte seul - Permalink - Snippet public posté le 10/04/2019

Extract TAR

tar -xvzf archive.tar.gz

ssh

<iframe width="100%" height="200" src="http://snipet.teknotit.com/index.php?embed=5cad0cfa69cd7" type="text/html"></iframe>

Texte seul - Permalink - Snippet public posté le 09/04/2019

apache exec commande as root

sudo visudo
===========

www-data ALL = NOPASSWD: /usr/bin/php

apache2 php

<iframe width="100%" height="254" src="http://snipet.teknotit.com/index.php?embed=5c536966a35e2" type="text/html"></iframe>

Texte seul - Permalink - Snippet public posté le 31/01/2019

Groupwise Max in MariaDB

Duplicate max
One thing to consider is whether you want -- or do not want -- to see multiple rows for tied winners. For the dataset being used here, that would imply that the two largest cities in a province had identical populations. For this case, a duplicate would be unlikely. But there are many groupwise-max use cases where duplictes are likely.

The two best algorithms differ in whether they show duplicates.

Using an uncorrelated subquery
Characteristics:

Superior performance or medium performance
It will show duplicates
Needs an extra index
Probably requires 5.6
If all goes well, it will run in O(M) where M is the number of output rows.
An 'uncorrelated subquery':

SELECT  c1.province, c1.city, c1.population
    FROM  Canada AS c1
    JOIN
      ( SELECT  province, MAX(population) AS population
            FROM  Canada
            GROUP BY  province
      ) AS c2 USING (province, population)
    ORDER BY c1.province;
But this also 'requires' an extra index: INDEX(province, population). In addition, MySQL has not always been able to use that index effectively, hence the "requires 5.6". (I am not sure of the actual version.)

Without that extra index, you would need 5.6, which has the ability to create indexes for subqueries. This is indicated by <auto_key0> in the EXPLAIN. Even so, the performance is worse with the auto-generated index than with the manually generated one.

With neither the extra index, nor 5.6, this 'solution' would belong in 'The Duds' because it would run in O(N*N) time.

Using @variables
Characteristics:

Good performance
Does not show duplicates (picks one to show)
Consistent O(N) run time (N = number of input rows)
Only one scan of the data
SELECT
        province, city, population   -- The desired columns
    FROM
      ( SELECT  @prev := '' ) init
    JOIN
      ( SELECT  province != @prev AS first,  -- `province` is the 'GROUP BY'
                @prev := province,           -- The 'GROUP BY'
                province, city, population   -- Also the desired columns
            FROM  Canada           -- The table
            ORDER BY
                province,          -- The 'GROUP BY'
                population DESC    -- ASC for MIN(population), DESC for MAX
      ) x
    WHERE  first
    ORDER BY  province;     -- Whatever you like
For your application, change the lines with comments.

The duds
* 'correlated subquery' (from MySQL doc):

SELECT  province, city, population
    FROM  Canada AS c1
    WHERE  population =
      ( SELECT  MAX(c2.population)
            FROM  Canada AS c2
            WHERE  c2.province= c1.province
      )
    ORDER BY  province;
O(N*N) (that is, terrible) performance

* LEFT JOIN (from MySQL doc):

SELECT  c1.province, c1.city, c1.population
    FROM  Canada AS c1
    LEFT JOIN  Canada AS c2 ON c2.province = c1.province
      AND  c2.population > c1.population
    WHERE  c2.province IS NULL
    ORDER BY province;
Medium performance (2N-3N, depending on join_buffer_size).

For O(N*N) time,... It will take one second to do a groupwise-max on a few thousand rows; a million rows could take hours.

Top-N in each group
This is a variant on "groupwise-max" wherein you desire the largest (or smallest) N items in each group. Do these substitutions for your use case:

province --> your 'GROUP BY'
Canada --> your table
3 --> how many of each group to show
population --> your numeric field for determining "Top-N"
city --> more field(s) you want to show
Change the SELECT and ORDER BY if you desire
DESC to get the 'largest'; ASC for the 'smallest'
SELECT
        province, n, city, population
    FROM
      ( SELECT  @prev := '', @n := 0 ) init
    JOIN
      ( SELECT  @n := if(province != @prev, 1, @n + 1) AS n,
                @prev := province,
                province, city, population
            FROM  Canada
            ORDER BY
                province   ASC,
                population DESC
      ) x
    WHERE  n <= 3
    ORDER BY  province, n;
Output:

+---------------------------+------+------------------+------------+
| province                  | n    | city             | population |
+---------------------------+------+------------------+------------+
| Alberta                   |    1 | Calgary          |     968475 |
| Alberta                   |    2 | Edmonton         |     822319 |
| Alberta                   |    3 | Red Deer         |      73595 |
| British Columbia          |    1 | Vancouver        |    1837970 |
| British Columbia          |    2 | Victoria         |     289625 |
| British Columbia          |    3 | Abbotsford       |     151685 |
| Manitoba                  |    1 | ...
The performance of this is O(N), actually about 3N, where N is the number of source rows.

EXPLAIN EXTENDED gives

+----+-------------+------------+--------+---------------+------+---------+------+------+----------+----------------+
| id | select_type | table      | type   | possible_keys | key  | key_len | ref  | rows | filtered | Extra          |
+----+-------------+------------+--------+---------------+------+---------+------+------+----------+----------------+
|  1 | PRIMARY     | <derived2> | system | NULL          | NULL | NULL    | NULL |    1 |   100.00 | Using filesort |
|  1 | PRIMARY     | <derived3> | ALL    | NULL          | NULL | NULL    | NULL | 5484 |   100.00 | Using where    |
|  3 | DERIVED     | Canada     | ALL    | NULL          | NULL | NULL    | NULL | 5484 |   100.00 | Using filesort |
|  2 | DERIVED     | NULL       | NULL   | NULL          | NULL | NULL    | NULL | NULL |     NULL | No tables used |
+----+-------------+------------+--------+---------------+------+---------+------+------+----------+----------------+
Explanation, shown in the same order as the EXPLAIN, but numbered chronologically: 3. Get the subquery id=2 (init) 4. Scan the the output from subquery id=3 (x) 2. Subquery id=3 -- the table scan of Canada 1. Subquery id=2 -- `init` for simply initializing the two @variables Yes, it took two sorts, though probably in RAM.

Main Handler values:

| Handler_read_rnd           | 39    |
| Handler_read_rnd_next      | 10971 |
| Handler_write              | 5485  |  -- #rows in Canada (+1)
Top-n in each group, take II
This variant is faster than the previous, but depends on `city` being unique across the dataset. (from openark.org)

    SELECT  province, city, population
        FROM  Canada
        JOIN
          ( SELECT  GROUP_CONCAT(top_in_province) AS top_cities
                FROM
                  ( SELECT  SUBSTRING_INDEX(
                                   GROUP_CONCAT(city ORDER BY  population DESC),
                            ',', 3) AS top_in_province
                        FROM  Canada
                        GROUP BY  province
                  ) AS x
          ) AS y
        WHERE  FIND_IN_SET(city, top_cities)
        ORDER BY  province, population DESC;
Output. Note how there can be more than 3 cities per province:

| Alberta                   | Calgary          |     968475 |
| Alberta                   | Edmonton         |     822319 |
| Alberta                   | Red Deer         |      73595 |
| British Columbia          | Vancouver        |    1837970 |
| British Columbia          | Victoria         |     289625 |
| British Columbia          | Abbotsford       |     151685 |
| British Columbia          | Sydney           |          0 | -- Nova Scotia's second largest is Sydney
| Manitoba                  | Winnipeg         |     632069 |
Main Handler values:

| Handler_read_next          | 5484  | -- table size
| Handler_read_rnd_next      | 5500  | -- table size + number of provinces
| Handler_write              | 14    | -- number of provinces (+1)
Top-n using MyISAM
(This does not need your table to be MyISAM, but it does need MyISAM tmp table for its 2-column PRIMARY KEY feature.) See previous section for what changes to make for your use case.

    -- build tmp table to get numbering
    -- (Assumes auto_increment_increment = 1)
    CREATE TEMPORARY TABLE t (
        nth MEDIUMINT UNSIGNED NOT NULL AUTO_INCREMENT,
        PRIMARY KEY(province, nth)
    ) ENGINE=MyISAM
        SELECT province, NULL AS nth, city, population
            FROM Canada
            ORDER BY population DESC;
    -- Output the biggest 3 cities in each province:
    SELECT province, nth, city, population
        FROM t
        WHERE nth <= 3
        ORDER BY province, nth;

+---------------------------+-----+------------------+------------+
| province                  | nth | city             | population |
+---------------------------+-----+------------------+------------+
| Alberta                   |   1 | Calgary          |     968475 |
| Alberta                   |   2 | Edmonton         |     822319 |
| Alberta                   |   3 | Red Deer         |      73595 |
| British Columbia          |   1 | Vancouver        |    1837970 |
| British Columbia          |   2 | Victoria         |     289625 |
| British Columbia          |   3 | Abbotsford       |     151685 |
| Manitoba                  |  ...

SELECT for CREATE:
+----+-------------+--------+------+---------------+------+---------+------+------+----------------+
| id | select_type | table  | type | possible_keys | key  | key_len | ref  | rows | Extra          |
+----+-------------+--------+------+---------------+------+---------+------+------+----------------+
|  1 | SIMPLE      | Canada | ALL  | NULL          | NULL | NULL    | NULL | 5484 | Using filesort |
+----+-------------+--------+------+---------------+------+---------+------+------+----------------+
Other SELECT:
+----+-------------+-------+-------+---------------+---------+---------+------+------+-------------+
| id | select_type | table | type  | possible_keys | key     | key_len | ref  | rows | Extra       |
+----+-------------+-------+-------+---------------+---------+---------+------+------+-------------+
|  1 | SIMPLE      | t     | index | NULL          | PRIMARY | 104     | NULL |   22 | Using where |
+----+-------------+-------+-------+---------------+---------+---------+------+------+-------------+
The main handler values (total of all operations):

| Handler_read_rnd_next      | 10970 |
| Handler_write              | 5484  |  -- number of rows in Canada (write tmp table)
Both "Top-n" formulations probably take about the same amount of time.

Windowing functions
Hot off the press from Percona Live... MariaDB 10.2 has "windowing functions", which make "groupwise max" much more straightforward.

The code:

TBD

Postlog
Developed an first posted, Feb, 2015; Add MyISAM approach: July, 2015; Openark's method added: Apr, 2016; Windowing: Apr 2016

I did not include the technique(s) using GROUP_CONCAT. They are useful in some situations with small datasets. They can be found in the references below.


https://mariadb.com/kb/en/library/groupwise-max-in-mariadb/

<iframe width="100%" height="4250" src="http://snipet.teknotit.com/index.php?embed=5c4c822052d67" type="text/html"></iframe>

Texte seul - Permalink - Snippet public posté le 26/01/2019

Autofill transparent

input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus,
input:-webkit-autofill:active {
    transition: background-color 5000s ease-in-out 0s;
    -webkit-text-fill-color: #fff !important;
}

css

<iframe width="100%" height="326" src="http://snipet.teknotit.com/index.php?embed=5c15c88237805" type="text/html"></iframe>

Texte seul - Permalink - Snippet public posté le 16/12/2018

Replace NULL with a Different Value in MySQL

4 Ways to Replace NULL with a Different Value in MySQL
MAY 31, 2018 / IAN

 
In MySQL, sometimes you don’t want NULL values to be returned as NULL. Sometimes you want NULL values to be returned with a different value, such as “N/A”, “Not Applicable”, “None”, or even the empty string “”.

Fortunately there are several ways to do this in MySQL.

Here are four:

The IFNULL() function
The COALESCE() function
The IF() function combined with the IS NULL (or IS NOT NULL) operator
The CASE expression combined with the IS NULL (or IS NOT NULL) operator
Examples of these options are below.


Sample Data
First, let’s grab some sample data:

USE Solutions;
SELECT TaskCode
From Tasks;
Result:

+----------+
| TaskCode |
+----------+
| gar123   |
| NULL     |
| NULL     |
| dog456   |
| NULL     |
| cat789   |
+----------+
So we have three NULL values and three non-NULL values.

The IFNULL() Function
Given its name, this is probably the most obvious option for replacing NULL values in MySQL. This function is basically the equivalent of ISNULL() in SQL Server.

The IFNULL() function allows you to provide two arguments. The first argument is returned only if it is not NULL. If it is NULL, then the second argument is returned instead.

Here’s an example of using IFNULL() against our sample data set:

SELECT IFNULL(TaskCode, 'N/A') AS Result 
FROM Tasks;
Result:

+--------+
| Result |
+--------+
| gar123 |
| N/A    |
| N/A    |
| dog456 |
| N/A    |
| cat789 |
+--------+
Here, we simply replaced NULL values with N/A.

The COALESCE() Function
This function is similar to the IFNULL() function, but slightly different. This function adheres to the ANSI  SQL standard, and it is widely deployed across various RDBMSs .

The way it works is, you provide as many arguments as you need. COALESCE() will then return the first non-NULL value in the list, or NULL if there are no non-NULL values.

Like this:

SELECT COALESCE(TaskCode, 'N/A') AS Result 
FROM Tasks;
Result:

+--------+
| Result |
+--------+
| gar123 |
| N/A    |
| N/A    |
| dog456 |
| N/A    |
| cat789 |
+--------+
So we get exactly the same result as previously.

However, the difference with this function is that, as mentioned, you can provide a list of arguments. The COALESCE() function will take whichever is the first non-NULL value.

So for example, we could add NULL as the first argument and place None before N/A and look what happens:

SELECT COALESCE(NULL, TaskCode, 'None', 'N/A') AS Result 
FROM Tasks;
Result:

+--------+
| Result |
+--------+
| gar123 |
| None   |
| None   |
| dog456 |
| None   |
| cat789 |
+--------+
It skipped the first NULL as expected, then it skipped any NULL values in the TaskCode column, before settling on None.  The N/A value didn’t get used in this case because None came first and it’s a non-NULL value.

The IF() Function Combined with IS NULL/IS NOT NULL
The IS NULL and IS NOT NULL operators allow you to test for NULL values, and present a different value depending on the outcome.

We can use these operators inside the IF() function, so that non-NULL values are returned, and NULL values are replaced with a value of our choosing.

Example:

SELECT IF(TaskCode IS NOT NULL, TaskCode, 'N/A') AS Result 
FROM Tasks;
Result:

+--------+
| Result |
+--------+
| gar123 |
| N/A    |
| N/A    |
| dog456 |
| N/A    |
| cat789 |
+--------+
So the same result as with the IFNULL() and COALESCE() functions.

And of course, we could swap IS NOT NULL with IS NULL. If we do that, we would need to swap the subsequent arguments too:

SELECT IF(TaskCode IS NULL, 'N/A', TaskCode) AS Result 
FROM Tasks;
The CASE Expression Combined with IS NULL/IS NOT NULL
Another way to do it is to use the CASE expression:

SELECT 
    CASE 
        WHEN TaskCode IS NOT NULL THEN TaskCode 
        ELSE 'N/A' 
    END AS Result
FROM Tasks;
Result:

+--------+
| Result |
+--------+
| gar123 |
| N/A    |
| N/A    |
| dog456 |
| N/A    |
| cat789 |
+--------+
As with the previous example, this could be rewritten to use IS NULL instead of IS NOT NULL:

SELECT 
    CASE 
        WHEN TaskCode IS NULL THEN 'N/A' 
        ELSE TaskCode 
    END AS Result
FROM Tasks;


mysql

https://database.guide/4-ways-to-replace-null-with-a-different-value-in-mysql/

<iframe width="100%" height="3080" src="http://snipet.teknotit.com/index.php?embed=5c0dc2337ec23" type="text/html"></iframe>

Texte seul - Permalink - Snippet public posté le 10/12/2018

Date Diff

<?php
  
  // Set timezone
  date_default_timezone_set("UTC");

  // Time format is UNIX timestamp or
  // PHP strtotime compatible strings
  function dateDiff($time1, $time2, $precision = 6) {
    // If not numeric then convert texts to unix timestamps
    if (!is_int($time1)) {
      $time1 = strtotime($time1);
    }
    if (!is_int($time2)) {
      $time2 = strtotime($time2);
    }

    // If time1 is bigger than time2
    // Then swap time1 and time2
    if ($time1 > $time2) {
      $ttime = $time1;
      $time1 = $time2;
      $time2 = $ttime;
    }

    // Set up intervals and diffs arrays
    $intervals = array('year','month','day','hour','minute','second');
    $diffs = array();

    // Loop thru all intervals
    foreach ($intervals as $interval) {
      // Create temp time from time1 and interval
      $ttime = strtotime('+1 ' . $interval, $time1);
      // Set initial values
      $add = 1;
      $looped = 0;
      // Loop until temp time is smaller than time2
      while ($time2 >= $ttime) {
        // Create new temp time from time1 and interval
        $add++;
        $ttime = strtotime("+" . $add . " " . $interval, $time1);
        $looped++;
      }
 
      $time1 = strtotime("+" . $looped . " " . $interval, $time1);
      $diffs[$interval] = $looped;
    }
    
    $count = 0;
    $times = array();
    // Loop thru all diffs
    foreach ($diffs as $interval => $value) {
      // Break if we have needed precission
      if ($count >= $precision) {
        break;
      }
      // Add value and interval 
      // if value is bigger than 0
      if ($value > 0) {
        // Add s if value is not 1
        if ($value != 1) {
          $interval .= "s";
        }
        // Add value and interval to times array
        $times[] = $value . " " . $interval;
        $count++;
      }
    }

    // Return string with times
    return implode(", ", $times);
  }

?>

php

https://www.if-not-true-then-false.com/2010/php-calculate-real-differences-between-two-dates-or-timestamps/

<iframe width="100%" height="1496" src="http://snipet.teknotit.com/index.php?embed=5c0c234570d95" type="text/html"></iframe>

Texte seul - Permalink - Snippet public posté le 08/12/2018

Flush iptable

iptables -P INPUT ACCEPT
iptables -P FORWARD ACCEPT
iptables -P OUTPUT ACCEPT
iptables -t nat -F
iptables -t mangle -F
iptables -F
iptables -X

linux ssh

<iframe width="100%" height="326" src="http://snipet.teknotit.com/index.php?embed=5beaf2818b827" type="text/html"></iframe>

Texte seul - Permalink - Snippet public posté le 13/11/2018

javascript Header Auth

$.ajax({
    type: 'GET',
    url: 'url',
    dataType: 'json',
    //whatever you need
    beforeSend: function (xhr) {
        xhr.setRequestHeader('Authorization', make_base_auth(user, password));
    },
    success: function () {});
});

function make_base_auth(user, password) {
    var tok = user + ':' + password;
    var hash = btoa(tok);
    return 'Basic ' + hash;
}

javascript

<iframe width="100%" height="470" src="http://snipet.teknotit.com/index.php?embed=5bdf788df1935" type="text/html"></iframe>

Texte seul - Permalink - Snippet public posté le 04/11/2018

verouiller un fichier

#Vérouiller

chattr +i filename

# Dévéruiller

chattr -i filename


# Vérouiller avec option ajout uniquement

chattr +a filename


#Vérivier si y a un vérrou

lsattr filename


ssh sysadmin

https://www.howtoforge.com/linux-chattr-command/

<iframe width="100%" height="524" src="http://snipet.teknotit.com/index.php?embed=5bc314672d854" type="text/html"></iframe>

Texte seul - Permalink - Snippet public posté le 03/04/2020

100% video

/* 100% video */
.video-container {
   position: relative;
   padding-bottom: 56.25%;
   padding-top: 30px;
   height: 0;
   overflow: hidden;
   margin: 10px 0;
}

.video-container iframe,  
.video-container object,  
.video-container embed {
   position: absolute;
   top: 0;
   left: 0;
   width: 100%;
   height: 100%;
}

css

<iframe width="100%" height="524" src="http://snipet.teknotit.com/index.php?embed=5b41afb410189" type="text/html"></iframe>

Texte seul - Permalink - Snippet public posté le 08/07/2018

remove double slash

RewriteCond %{THE_REQUEST} \ //+
RewriteRule (.*) /$1 [R=301,L]

apache2

<iframe width="100%" height="236" src="http://snipet.teknotit.com/index.php?embed=5b17133760573" type="text/html"></iframe>

Texte seul - Permalink - Snippet public posté le 05/06/2018

Uniq ID multiple call

function uniqidReal($lenght = 13) {
    // uniqid gives 13 chars, but you could adjust it to your needs.
    if (function_exists("random_bytes")) {
        $bytes = random_bytes(ceil($lenght / 2));
    } elseif (function_exists("openssl_random_pseudo_bytes")) {
        $bytes = openssl_random_pseudo_bytes(ceil($lenght / 2));
    } else {
        throw new Exception("no cryptographically secure random function available");
    }
    return substr(bin2hex($bytes), 0, $lenght);
}

php

<iframe width="100%" height="380" src="http://snipet.teknotit.com/index.php?embed=5b07801aa1370" type="text/html"></iframe>

Texte seul - Permalink - Snippet public posté le 25/05/2018

Affectation et comparaison

if ( false === ( $results = get_transient( 'transient_key_name' ) ) ) {
  $results = ...; // Do the slow query to get the results here
  // 60 * 60 is the expiration in seconds - in this case, 3600 seconds (1 hour)
  set_transient( 'transient_key_name', $results, 60 * 60 ); 
}

php wordpress

<iframe width="100%" height="272" src="http://snipet.teknotit.com/index.php?embed=5afcf90f56ada" type="text/html"></iframe>

Texte seul - Permalink - Snippet public posté le 17/05/2018

Scaled/Proportional Content with CSS and JavaScript

Proportional scaling of a *container* is fairly easy


.parent {
  height: 0;
  padding-bottom: 56.25%; /* 16:9 */
  position: relative;
}

.child {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
}

css

https://css-tricks.com/scaled-proportional-blocks-with-css-and-javascript/

<iframe width="100%" height="434" src="http://snipet.teknotit.com/index.php?embed=5a9ee13914442" type="text/html"></iframe>

Texte seul - Permalink - Snippet public posté le 06/03/2018

npm install version specifique d'un package

npm install <package_name>@version --save

npm install <package_name>@version --save-dev

javascript

https://docs.npmjs.com/getting-started/using-a-package.json

<iframe width="100%" height="254" src="http://snipet.teknotit.com/index.php?embed=5a842c7e684d7" type="text/html"></iframe>

Texte seul - Permalink - Snippet public posté le 14/02/2018

Stop services for optimisation

/etc/init.d/spamassassin stop
/etc/init.d/clamav-freshclam stop
/etc/init.d/clamav-daemon stop




/etc/init.d/clamav-daemon stop
/etc/init.d/clamav-freshclam stop
/etc/init.d/amavis stop

update-rc.d -f clamav-daemon remove
update-rc.d -f clamav-freshclam remove
update-rc.d -f amavis remove

update-rc.d -f spamassassin remove

sysadmin

https://www.faqforge.com/linux/controlpanels/ispconfig3/how-to-disable-spamfilter-and-antivirus-functions-in-ispconfig-3/

<iframe width="100%" height="488" src="http://snipet.teknotit.com/index.php?embed=5a6047a0cefc6" type="text/html"></iframe>

Texte seul - Permalink - Snippet public posté le 18/01/2018

Codes reponses HTTP

codes = (
    100 -> "Continue",
    101 -> "Switching Protocols",
    102 -> "Processing",
    200 -> "OK",
    201 -> "Created",
    202 -> "Accepted",
    203 -> "Non-Authoritative Information",
    204 -> "No Content",
    205 -> "Reset Content",
    206 -> "Partial Content",
    207 -> "Multi-Status",
    208 -> "Already Reported",
    226 -> "IM Used",
    300 -> "Multiple Choices",
    301 -> "Moved Permanently",
    302 -> "Found",
    303 -> "See Other",
    304 -> "Not Modified",
    305 -> "Use Proxy",
    306 -> "Switch Proxy",
    307 -> "Temporary Redirect",
    308 -> "Permanent Redirect",
    400 -> "Bad Request",
    401 -> "Unauthorized",
    402 -> "Payment Required",
    403 -> "Forbidden",
    404 -> "Not Found",
    405 -> "Method Not Allowed",
    406 -> "Not Acceptable",
    407 -> "Proxy Authentication Required",
    408 -> "Request Timeout",
    409 -> "Conflict",
    410 -> "Gone",
    411 -> "Length Required",
    412 -> "Precondition Failed",
    413 -> "Request Entity Too Large",
    414 -> "Request-URI Too Long",
    415 -> "Unsupported Media Type",
    416 -> "Requested Range Not Satisfiable",
    417 -> "Expectation Failed",
    418 -> "I'm a teapot",
    420 -> "Enhance Your Calm",
    422 -> "Unprocessable Entity",
    423 -> "Locked",
    424 -> "Failed Dependency",
    425 -> "Unordered Collection",
    426 -> "Upgrade Required",
    428 -> "Precondition Required",
    429 -> "Too Many Requests",
    431 -> "Request Header Fields Too Large",
    444 -> "No Response",
    449 -> "Retry With",
    450 -> "Blocked by Windows Parental Controls",
    499 -> "Client Closed Request",
    500 -> "Internal Server Error",
    501 -> "Not Implemented",
    502 -> "Bad Gateway",
    503 -> "Service Unavailable",
    504 -> "Gateway Timeout",
    505 -> "HTTP Version Not Supported",
    506 -> "Variant Also Negotiates",
    507 -> "Insufficient Storage",
    509 -> "Bandwidth Limit Exceeded",
    510 -> "Not Extended")

Api

<iframe width="100%" height="1352" src="http://snipet.teknotit.com/index.php?embed=5a21dbe204889" type="text/html"></iframe>

Texte seul - Permalink - Snippet public posté le 01/12/2017

jQuery contentType vs dataType

//pour l'envoi en payload defaut contentType (default: 'application/x-www-form-urlencoded; charset=UTF-8')

contentType: "application/json",

// pour le retour
dataType: 'json'

http://api.jquery.com/jquery.ajax/

<iframe width="100%" height="290" src="http://snipet.teknotit.com/index.php?embed=59cc7f92f37e6" type="text/html"></iframe>

Texte seul - Permalink - Snippet public posté le 28/09/2017

Chargement css sans bloquer le rendu

<link rel="stylesheet" href="style.css" media="none" onload="if(media!='all')media='all'">
<noscript><link rel="stylesheet" href="style.css"></noscript>

css html javascript

<iframe width="100%" height="218" src="http://snipet.teknotit.com/index.php?embed=590a0fc01cf81" type="text/html"></iframe>

Texte seul - Permalink - Snippet public posté le 03/05/2017

jQuery insertAt

Y.eq(i).after(X);

inserer l'element X a la position i des fils de l'element Y

javascript

<iframe width="100%" height="236" src="http://snipet.teknotit.com/index.php?embed=58e19cf991749" type="text/html"></iframe>

Texte seul - Permalink - Snippet public posté le 03/04/2017

Static en javascript

function counter() {
    var count = 0;
    return function() {
        alert(count++);
    }
}
var count = counter();
count();
count();
count();


ou bien ca

var Counter = function(){
var count =0;
return function(){
console.log(count++);
}
}();

javascript

<iframe width="100%" height="542" src="http://snipet.teknotit.com/index.php?embed=58d407e5d30a2" type="text/html"></iframe>

Texte seul - Permalink - Snippet public posté le 23/03/2017

1234567

Flux RSS de cette page


Teknotit Snipet Manager 1.84 par Bronco - Page générée en 0.005 s