Skip to content

Instantly share code, notes, and snippets.

View jcisio's full-sized avatar

Hai-Nam Nguyen jcisio

View GitHub Profile
@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 / gist:4603181
Created January 23, 2013 08:35
MySQL table deduplication
-- Deduplication on all rows
CREATE TEMPORARY TABLE bad_temp AS SELECT DISTINCT * FROM your_table;
DELETE FROM your_table;
INSERT INTO your_table SELECT * FROM bad_temp;
-- Deduplication on some rows
CREATE TEMPORARY TABLE bad_temp AS SELECT * FROM your_table GROUP BY field1, field2, field3;
DELETE FROM your_table;
INSERT INTO your_table SELECT * FROM bad_temp;
@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'
@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 / 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);
@jcisio
jcisio / ideas.md
Last active December 17, 2015 07:39
MHST 2013: xén ảnh thông minh nhờ phát hiện khuôn mặt

Xén ảnh thông minh nhờ phát hiện khuôn mặt

Mức độ: trung bình/khó.

Thực hiện một thuật toán phát hiện khuôn mặt (face detection) trên PHP, sau đó tích hợp vào một hệ quản trị nội dung (CMS) để giải quyết bài toán xén ảnh thông minh.

Vấn đề

Phát hiện khuôn mặt là một bài toán cơ bản trong xử lí ảnh. Đã có khá nhiều thuật toán giải quyết vấn đề này, viết trên nhiều ngôn ngữ khác nhau. Thư viện OpenCV cũng có sẵn công cụ để phát hiện khuôn mặt.

@jcisio
jcisio / bash.git_prompt
Created February 20, 2013 21:20
Make bash prompt know about git
# Colors
NoColor="\033[0m"
Cyan="\033[0;36m"
Green="\033[0;32m"
Red="\033[0;31m"
Yellow="\033[0;33m"
# Chars
RootPrompt="\#"
NonRootPrompt="\$"
@jcisio
jcisio / update_nodes.php
Created January 27, 2013 11:16
Move taxonomy from node to content taxonomy fields. Use with drush.
<?php
/**
* @file
* Move taxonomy term from taxonomy_node table to field tables.
*/
$types = array(
array(
'type' => 'product',
'fields' => array(