Devenet Devenet

Liens en vrac

Quelques 337 marque-pages glanés pendant ma navigation sur le Web.

Detect down/up scrolling in Javascript

http://lehollandaisvolant.net/?mode=links

// Initial state
var scrollPos = 0;
// adding scroll event
window.addEventListener('scroll', function(){ scrolling() });

// the function : compares the new scrolling state with the previous
// (this allows detecting either “up” or “down” scrolling)
// then saves the new in the $previous for the next iteration.

function scrolling() {
if ((document.body.getBoundingClientRect()).top > scrollPos) {
console.log('scrolling DOWN');
} else {
console.log('scrolling UP');
}
scrollPos = (document.body.getBoundingClientRect()).top;
}

Sending a multi-part e-mail with html and plain text

http://bookmarks.ecyseo.net/?rZSKHA

//specify the email address you are sending to, and the email subject
$email = 'email@example.com';
$subject = 'Email Subject';

//create a boundary for the email. This
$boundary = uniqid('np');

//headers - specify your from email address and name here
//and specify the boundary for the email
$headers = "MIME-Version: 1.0\r\n";
$headers .= "From: Your Name \r\n";
$headers .= "To: ".$email."\r\n";
$headers .= "Content-Type: multipart/alternative;boundary=" . $boundary . "\r\n";

//here is the content body
$message = "This is a MIME encoded message.";
$message .= "\r\n\r\n--" . $boundary . "\r\n";
$message .= "Content-type: text/plain;charset=utf-8\r\n\r\n";

//Plain text body
$message .= "Hello,\nThis is a text email, the text/plain version.
\n\nRegards,\nYour Name";
$message .= "\r\n\r\n--" . $boundary . "\r\n";
$message .= "Content-type: text/html;charset=utf-8\r\n\r\n";

//Html body
$message .= "
Hello,
This is a text email, the html version.

Regards,
Your Name";
$message .= "\r\n\r\n--" . $boundary . "--";

//invoke the PHP mail function
mail('', $subject, $message, $headers);

Font loading revisited with font events

https://www.filamentgroup.com/lab/font-events.html

Chargement “différé” des fonts sur une page web pour un rendu plus rapide.

On charge les fonts via CSS, comme habituellement.
On définit les éléments avec ces polices comme enfant de .fonts-loaded.
Via une API JavaScript, on détecte quand les fonts sont chargées et prêtes, et on ajoute la classe .fonts-loaded à l’élément body : les polices sont affichées.
→ Pas de page sans police ou un blanc entre le chargement des polices.

Dans le même genre : http://www.zachleat.com/web/foft/

Le test du marshmallow

http://gift.mercialfred.com/topo/test-marshmallow

On voulait vous présenter deux personnes. Lui, c’est Tom. Et ça, c’est Nico.

Un jour, en rentrant dans leur salle de classe, ils découvrent un marshmallow posé sur leur table. Sauf que derrière le marshmallow, il y a un type un peu bizarre.

Ils se disent “Génial, un marshmallow” ! Mais là, le type bizarre leur dit :
“Vous avez deux options :
1) manger le marshmallow tout de suite,
2) attendre 15 minutes que je revienne ; si vous n’avez pas mangé le marshmallow, je vous en donnerai un deuxième.”

Pas la peine d’appeler la police : le type bizarre, c’est juste un chercheur en économie comportementale — aux États-Unis, ils appellent ça un comportementaliste. Et il est en train de réaliser une expérience hyper célèbre inventée par Walter Mischel, chercheur à l’université de Stanford, en 1972. Pourquoi est-ce que cette expérience est aussi connue ? Parce qu’elle a été reproduite plusieurs fois, et qu’à chaque fois, la conclusion était la même : le résultat au test du marshmallow est le meilleur prédicteur de la réussite future d’un individu.

Nettoyer son système Debian

http://pingouindoc.tuxfamily.org/pub/posts/nettoyer_son_syst%C3%A8me.html

À force d’installation et de désinstallation de logiciels, votre système Debian s’encombre de fichiers de configuration inutiles. Il est donc temps de faire un petit nettoyage.

Voici la formule magique :
> dpkg -P $(dpkg -l | grep '^rc' | awk '{ print $2 }')

Créer un nas avec le Raspberry Pi

http://blog.idleman.fr/billet-invite-creer-un-nas-avec-le-raspberry-pi/

Fichier samba.conf :
[global]
  workgroup = WORKGROUP
  server string = %h server
  netbios name = SERVEURIX2000
  dns proxy = no
  log file = /var/log/samba/log.%m
  max log size = 1000
  syslog = 0
  panic action = /usr/share/samba/panic-action %d
  security = user
  encrypt passwords = true
  passdb backend = tdbsam
  obey pam restrictions = yes
  unix password sync = yes
  passwd program = /usr/bin/passwd %u
  passwd chat = *Enter\snew\s*\spassword:* %n\n *Retype\snew\s*\spassword:* %n\n *password\supdated\ssuccessfully* .
  pam password change = yes
  map to guest = bad user
  usershare allow guests = yes

[Public]
  path =/media/USBHDD1/SERVEURIX2000/Public
  read only = no
  locking = no
  guest ok = yes
  force user = pi

[Music]
  path =/media/USBHDD1/SERVEURIX2000/Music
  read only = yes
  locking = no
  guest ok = yes
  force user = pi

[Private]
  browseable = no
  path = /media/USBHDD1/SERVEURIX2000/Private
  writable = yes
  username = JeanLouis
  only user = yes
  create mode = 0600
  directory mask = 0700

Vous pouvez sauvegarder et fermer le fichier. Si vous voulez ajouter d’autres dossiers à partager, ce sera celui-ci. Maintenant, nous allons créer un compte SAMBA qui va nous permettre d’avoir un login et un mdp pour le dossier Private.

Tout d’abord, on crée un compte utilisateur sur Wheezy:
 sudo useradd JeanLouis -m -G users
 sudo passwd JeanLouis

Puis on l’utilise pour SAMBA:
 sudo smbpasswd -a JeanLouis

Ensuite on donne à cet user l’accès au dossier Private:
 sudo chown JeanLouis:JeanLouis /media/USBHDD1/SERVEURIX2000/Private/

Enfin, on redémarre tout ce boxon:
 sudo /etc/init.d/samba restart

Et voilà, vous avez maintenant accès à vos dossiers sur les disques durs depuis le réseau.

PHP: gethostbynamel

https://www.php.net/manual/en/function.gethostbynamel.php

Récupération de la liste d’adresses IP v4 à partir d’un nom de domaine.

Voir aussi :
• gethostbyname() - Get the IPv4 address corresponding to a given Internet host name
• gethostbyaddr() - Get the Internet host name corresponding to a given IP address
• checkdnsrr() - Check DNS records corresponding to a given Internet host name or IP address
• getmxrr() - Get MX records corresponding to a given Internet host name