Skip to content

Instantly share code, notes, and snippets.

View jcisio's full-sized avatar

Hai-Nam Nguyen jcisio

View GitHub Profile
@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 / convention.md
Last active August 29, 2015 14:01
Convention

Projet xxx

Structure des répertoires

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

-- src

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 / 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(
@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 / 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 / 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 / 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 / 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 / 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'