Skip to content

Instantly share code, notes, and snippets.

View jcisio's full-sized avatar

Hai-Nam Nguyen jcisio

View GitHub Profile
@jcisio
jcisio / download.js
Last active October 16, 2025 16:10
Download all links in selected text
(async () => {
// Defaults that usually work, but change to fit your need.
const delayMs = 1000; // delay between links (milliseconds), it should be at least 1/3 the time to download a file
const allow = /\.(pdf|zip|mp3)(\?|#|$)/i; // Restrict to certain file types
// === Nothing to change after this ===
const sel = window.getSelection();
if (!sel || sel.rangeCount === 0) {
alert('Select some content on the page first.');
@jcisio
jcisio / selectors.js
Created May 15, 2019 10:44
JavaScript
// https://stackoverflow.com/a/12313690/417401
var
styleSheets = document.styleSheets,
totalStyleSheets = styleSheets.length;
for (var j = 0; j < totalStyleSheets; j++){
var
styleSheet = styleSheets[j],
rules = styleSheet.cssRules,
totalRulesInStylesheet = rules.length,
@jcisio
jcisio / paragraph.md
Created February 14, 2018 10:48
Combien de paragraphes ?

Les paragraphes sont maintenant le coeur d'un site Drupal. On les rencontre beaucoup plus souvent que les autres entités, même les nodes ou les termes de taxonomie.

Le problème

Le nombre de types de pagragraphe d'un site augmente jour après jour. Il n'est plus rare de se retrouver sur un site avec 20 ou 30 types de paragraphe. Cela a des conséquences :

  • Lors de la création d'un paragraphe, les utilisateurs sont proposés chaque fois une large liste, alors qu'ils utilisent 2 ou 3 types de paragraphe (image, texte) dans la majorité de cas. On peut avoir une meilleur ergonomie.
  • Les développeur et les intégrateur doivent gérer plusieurs types de paragraphe, des fois très similaires. Il va avoir de duplication de code. Même si on peut refactoriser pour réutiliser un morceau de code, la logique est floue et ce n'est pas optimal.
  • Fonctionnalité : dans un contexte responsive et il y a de plus en plus de trafic en mobile, l'affichage mobile est simplifié et on peut se retrouver sur deux paragraphes différents
@jcisio
jcisio / update.sql
Created November 23, 2017 11:26
Update nodes to the last revisions
UPDATE node
JOIN (SELECT nid, max(vid) as vid FROM node_revision GROUP BY nid) as tv USING(nid)
SET node.vid = tv.vid
WHERE node.type = 'cours'

Keybase proof

I hereby claim:

  • I am jcisio on github.
  • I am jcisio (https://keybase.io/jcisio) on keybase.
  • I have a public key whose fingerprint is D874 6FA0 BBDC 9BBF 3363 8998 089D 0553 2E73 7667

To claim this, I am signing this object:

@jcisio
jcisio / scripts.js
Last active March 17, 2016 10:20
Daily tools
// List checked checkboxes
(function () {
var checkboxes = document.querySelectorAll('[checked=checked]');
for (var i = 0; i < checkboxes.length; ++i) {
console.log(checkboxes[i].name);
}
})();
@jcisio
jcisio / convention.md
Last active August 29, 2015 14:01
Convention

Projet xxx

Structure des répertoires

/-- conf
 -- drush
 -- patches
 -- scripts
 -- sql

-- src

@jcisio
jcisio / removeAccents.js
Created February 13, 2014 14:32
Transliteration: remove all accents (diacritics). Not the fastest, but easy to understand and to change.
(function() {
String.prototype.removeAccents = function () {
var diacritics = [
{'base':'A', 'letters':/[\u0041\u24B6\uFF21\u00C0\u00C1\u00C2\u1EA6\u1EA4\u1EAA\u1EA8\u00C3\u0100\u0102\u1EB0\u1EAE\u1EB4\u1EB2\u0226\u01E0\u00C4\u01DE\u1EA2\u00C5\u01FA\u01CD\u0200\u0202\u1EA0\u1EAC\u1EB6\u1E00\u0104\u023A\u2C6F]/g},
{'base':'AA','letters':/[\uA732]/g},
{'base':'AE','letters':/[\u00C6\u01FC\u01E2]/g},
{'base':'AO','letters':/[\uA734]/g},
{'base':'AU','letters':/[\uA736]/g},
{'base':'AV','letters':/[\uA738\uA73A]/g},
@jcisio
jcisio / gist:5685082
Created May 31, 2013 13:46
Drupal: Format Date field
$node = node_load(48617);
$item = $node->field_simplenews_date[LANGUAGE_NONE][0];
$date = new DateObject($item['value'], $item['timezone_db'], date_type_format($item['date_type']));
// $date->format is not localized
$timestamp = $date->format(U);
print format_date($timestamp, 'custom', 'd F Y');
@jcisio
jcisio / views_render.module
Created May 21, 2013 08:15
Use Views to render precalculated data.
/**
* Override a view result with nids and render.
*/
function hook_render_view_with_nids($view_name, $display_id, $nids) {
if (!is_array($nids)) {
$nids = array($nids);
}
$view = views_get_view($view_name);
$view->set_display($display_id);