Skip to content

Instantly share code, notes, and snippets.

View nhatnx's full-sized avatar

Nhat Nguyen nhatnx

  • Ho Chi Minh city, Vietnam
View GitHub Profile
@nhatnx
nhatnx / MySQL find_in_set with multiple search string.sql
Created May 24, 2019 17:34
MySQL find_in_set with multiple search string
/*
Something likes find_in_set('a,b,c', 'a,b,c,d')
We can use OR:
find_in_set('a', 'a,b,c,d') OR find_in_set('b', 'a,b,c,d') OR find_in_set('b', 'a,b,c,d')
*/
WHERE CONCAT(",", `setcolumn`, ",") REGEXP ",(val1|val2|val3),"

Keybase proof

I hereby claim:

  • I am nhatnx on github.
  • I am nhatnx (https://keybase.io/nhatnx) on keybase.
  • I have a public key whose fingerprint is B832 DC09 F93F D97E BDA8 6EBF 033F 0A9F 0C44 6A2E

To claim this, I am signing this object:

@nhatnx
nhatnx / remove_duplicate_rows_based_on_one_column_value.sql
Created March 9, 2019 05:07
[MySql] Remove duplicate rows based on one column value
DELETE t1 FROM table t1
INNER JOIN table t2
ON t2.refID = t1.refID
AND t2.ID < t1.ID
@nhatnx
nhatnx / sort_object_by_value_of_key_AND_by_key.js
Created December 12, 2018 03:46
Sort object by value of a key AND by key
// by_value_of_key
// e.g. array = [{index: 3, sortProp: 'aaa'}, {index: 1, sortProp: 'ccc'}, {index: 2, sortProp: 'bbb'}]
var sortProp = "keyToSortByItsValues"
array.sort(function (left, right) {
let a = left[sortProp];
let b = right[sortProp];
if (a !== b) {
if (a > b || a === void 0) return -1;
if (a < b || b === void 0) return 1;
}
@nhatnx
nhatnx / move_save_model_outside_loop.php
Created September 11, 2018 03:58
[PHP] How move a save model outside a loop in Yii?
<?php
$values = [];
foreach ($nodes as $node) {
$values[] = [
'name' => $node['name'],
'birthDate' => $node['birthDate']
];
}
@nhatnx
nhatnx / README.md
Created April 10, 2018 04:45 — forked from hofmannsven/README.md
My simply MySQL Command Line Cheatsheet
@nhatnx
nhatnx / break_jquery_each_loop.js
Created February 28, 2018 06:24
Break a jQuery each Loop
// To break a <var>$.each</var> loop, you have to <var>return false</var> in the loop callback.
// Returning <var>true</var> skips to the next iteration, equivalent to a <var>continue</var> in a normal loop.
$.each(array, function(key, value) {
if(value === "foo") {
return false;
}
});
@nhatnx
nhatnx / [PHP] Array delete by value.php
Created January 17, 2018 11:39
PHP array delete by value (not key)
<?php
if (($key = array_search($del_val, $messages)) !== false) {
unset($messages[$key]);
}
?>
@nhatnx
nhatnx / clear_ckeditor_content_has_only_spaces.php
Created January 17, 2018 04:15
Clear CKEditor content which has only spaces
<?php
$content = trim(preg_replace('/<p>(\s+|&nbsp;)+<\/p>/', ' ', $content));
?>
@nhatnx
nhatnx / ignore_events_on_element.css
Created January 10, 2018 04:37
Ignore events (click, touch...) on an element using CSS3
.element {
pointer-events: none;
}