Skip to content

Instantly share code, notes, and snippets.

@nhatnx
nhatnx / README.md
Created April 10, 2018 04:45 — forked from hofmannsven/README.md
My simply MySQL Command Line Cheatsheet
@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 / 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 / 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

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 / 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),"
@nhatnx
nhatnx / is_equal_objects.js
Last active March 12, 2023 02:02
Compare 2 objects recursively (if don't want to use lowdash _isEqual)
// https://gomakethings.com/check-if-two-arrays-or-objects-are-equal-with-javascript/
var isEqual = function (value, other) {
// Get the value type
var type = Object.prototype.toString.call(value);
// If the two objects are not the same type, return false
if (type !== Object.prototype.toString.call(other)) return false;
// If items are not an object or array, return false
@nhatnx
nhatnx / curl-error-60-ssl-certificate-unable-to-get-local-issuer-certificate.md
Last active March 16, 2026 05:49
[WAMP] cURL error 60: SSL certificate: unable to get local issuer certificate

Need to do this in both php.ini files !!!

Attention Wamp/Wordpress/windows users. I had this issue for hours and not even the correct answer was doing it for me, because I was editing the wrong php.ini file because the question was answered to XAMPP and not for WAMP users, even though the question was for WAMP.

here's what I did

Download the certificate bundle.

Put it inside of C:\wamp64\bin\php\your php version\extras\ssl

@nhatnx
nhatnx / min_max_dates_in_array.js
Created June 17, 2020 05:13
Min/Max of dates in an array
var dates=[];
dates.push(new Date("2011/06/25"));
dates.push(new Date("2011/06/26"));
dates.push(new Date("2011/06/27"));
dates.push(new Date("2011/06/28"));
var maxDate=new Date(Math.max.apply(null,dates));
var minDate=new Date(Math.min.apply(null,dates));
@nhatnx
nhatnx / prevent_copy.js
Created October 1, 2020 05:13
Prevents user from copying the text from form fields, either by copy/cut or dragging and dropping text
/* preventCopy()
* Prevents user from copying the text from form fields, either by copy/cut or dragging and dropping text.
* Binds preventDefault() to oncopy and oncut events.
* Binds event that makes all fields in selector readonly for onmousedown event. (Doesn't make target field readonly.)
* Binds event that removes readonly for onmouseup event.
* MSIE bug requires a user to click twice after readonly has been removed. Focus() doesn't work, use select().
* I specifically allowed pasting because the issue is really the copying.
* @param selector string required - jQuery selector for form field(s). As allowed by jQuery, this is typically a list of selectors in one string.
* @return void
*/