What is class=“mb-0” in Bootstrap 4?

Source: https://stackoverflow.com/questions/41574776/what-is-class-mb-0-in-bootstrap-4

Bootstrap has a wide range of responsive margin and padding utility classes. They work for all breakpoints:
xs (<=576px), sm (>=576px), md (>=768px), lg (>=992px) or xl (>=1200px))
The classes are used in the format:
{property}{sides}-{size} for xs & {property}{sides}-{breakpoint}-{size} for sm, md, lg, and xl.
m - sets margin
p - sets padding

t - sets margin-top or padding-top
b - sets margin-bottom or padding-bottom
l - sets margin-left or padding-left
r - sets margin-right or padding-right
x - sets both padding-left and padding-right or margin-left and margin-right
y - sets both padding-top and padding-bottom or margin-top and margin-bottom
blank - sets a margin or padding on all 4 sides of the element

0 - sets margin or padding to 0
1 - sets margin or padding to .25rem (4px if font-size is 16px)
2 - sets margin or padding to .5rem (8px if font-size is 16px)
3 - sets margin or padding to 1rem (16px if font-size is 16px)
4 - sets margin or padding to 1.5rem (24px if font-size is 16px)
5 - sets margin or padding to 3rem (48px if font-size is 16px)
auto - sets margin to auto

Removing Elements Dynamically

Source: https://www.abeautifulsite.net/adding-and-removing-elements-on-the-fly-using-javascript

  • function removeElement(elementId) {
  • // Removes an element from the document
  • var element = document.getElementById(elementId);
  • element.parentNode.removeChild(element);
  • }

Events through ()

Source: https://blog.bitsrc.io/event-binding-mechanism-in-angular-b38f0e46d2ed


In Angular, we can register and capture an event from an element by wrapping the event in a () parenthesis.
We can bind most of the common events in the DOM:
(focus)="focusCallback()"  
(blur)="blurCallback()"
(submit)="submitCallback()" 
(scroll)="scrollCallback()"
(cut)="cutCallback()"
(copy)="copyCallback()"
(paste)="pasteCallback()"
(keydown)="keydownCallback()"
(keypress)="keypressCallback()"
(keyup)="keyupCallback()"
(mouseenter)="mouseenterCallback()"
(mousedown)="mousedownCallback()"
(mouseup)="mouseupCallback()"
(click)="clickCallback()"
(dblclick)="dblclickCallback()"
(drag)="dragCallback()"
(dragover)="dragoverCallback()"
(drop)="dropCallback()"

How do I copy folder with files to another folder in Unix/Linux?

Souce: https://stackoverflow.com/questions/14922562/how-do-i-copy-folder-with-files-to-another-folder-in-unix-linux

The option you're looking for is -R.
cp -R path_to_source path_to_destination/
  • If destination doesn't exist, it will be created.
  • -R means copy directories recursively. You can also use -r since it's case-insensitive.
  • Note the nuances with adding the trailing / as per @muni764's comment.

Spread syntax

Source: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_syntax

Spread syntax allows an iterable such as an array expression or string to be expanded in places where zero or more arguments (for function calls) or elements (for array literals) are expected, or an object expression to be expanded in places where zero or more key-value pairs (for object literals) are expected.

function sum(x, y, z) {
  return x + y + z;
}

const numbers = [1, 2, 3];

console.log(sum(...numbers));
// expected output: 6

console.log(sum.apply(null, numbers));

// expected output: 6

How to extend an existing JavaScript array with another array, without creating a new array

Source: https://stackoverflow.com/questions/1374126/how-to-extend-an-existing-javascript-array-with-another-array-without-creating

The .push method can take multiple arguments. You can use the spread operator to pass all the elements of the second array as arguments to .push:
>>> a.push(...b)
If your browser does not support ECMAScript 6, you can use .apply instead:
>>> a.push.apply(a, b)
Or perhaps, if you think it's clearer:
>>> Array.prototype.push.apply(a,b)
Please note that all these solutions will fail with a stack overflow error if array b is too long (trouble starts at about 100,000 elements, depending on the browser). If you cannot guarantee that b is short enough, you should use a standard loop-based technique described in the other answer.

Call a “local” function within module.exports from another function in module.exports?

Source: https://stackoverflow.com/questions/10462223/call-a-local-function-within-module-exports-from-another-function-in-module-ex
https://stackoverflow.com/questions/33078967/node-js-call-a-local-function-within-module-exports/33080602

I think I got it. I just changed this.foo() to module.exports.foo() and it seems to be working.
If someone has a better or more proper method, please feel free to correct me.

"use strict"
var self = module.exports = {
    myName : function(req, res, next) {
        // accessing method within controller
        self.getName(data);
    },

    getName : function(data) {
        // code
    }
}

MySQL: Update If exist

Source: https://stackoverflow.com/questions/46628616/ignore-update-data-if-exist-in-mysql-by-node-js

https://dev.mysql.com/doc/refman/8.0/en/insert-on-duplicate.html

Fixed it by :
ON DUPLICATE KEY UPDATE

connection.connect( function( err ) {

    connection.query( "INSERT INTO real_user SET ? ON DUPLICATE KEY UPDATE updated_at = '" + data.created_at
     + "', request_count = '" + data.request_count + "'", 
        data,  function( err, res ) {
            connection.end();
        });

    });

node.js sync nested mysql queries

Source: https://www.codexpedia.com/javascript/nodejs-sync-nested-mysql-queries/

Node.js is asynchronous I/O that other processes can start and doesn’t have to wait for some long running input/output processes such read and write from files or databases.For example, you are running five queries in for loop, the result of each loop will be appended to an array. Right after the for loop, you are calling the callback function to get all the results, but the chances are you will get an empty array because the line after the for loop is executed before the lines in the for loop. The code snippet below demonstrates how to make sure all the queries are processed before make the callback function. It declares an counting variable pending and set it to the number of queries to be ran. After a query is executed successfully, decrease the pending by 1, call the callback function if when pending is equal to 0.

var mysql = require('mysql');
var pool =  mysql.createPool({
host : 'localhost',
user : 'root',
password: '',
database: 'test'
});

function getStudents(ids, cb) { 
    var students = [];
    var pending = ids.length;

    for(var i in ids) {
        pool.query('SELECT * FROM students WHERE id = ?', [ ids[i] ], function(err, stu){
            students.push(stu);
            if( 0 === --pending ) {
                cb(students); //callback if all queries are processed
            }
        });
    }
}

var ids = [1,2,3,4,5];
getStudents(ids, function(students){
    console.log(students);

});

The table used in the demonstration above.

CREATE database `test`;
CREATE TABLE `students` (
  `id` int(11) NOT NULL,
  `name` varchar(20) DEFAULT NULL,
  `grade` int(11) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

INSERT INTO `students` (`id`, `name`, `grade`)
VALUES
    (1,'ken',90),
    (2,'jim',90),
    (3,'kay',57),
    (4,'jerry',57),

    (5,'wen',66);

Angular 4.3 - HttpClient set params

Source: https://stackoverflow.com/questions/45210406/angular-4-3-httpclient-set-params

HttpParams is intended to be immutable. The set and append methods don't modify the existing instance. Instead they return new instances, with the changes applied.
let params = new HttpParams().set('aaa', 'A');    // now it has aaa
params = params.set('bbb', 'B');                  // now it has both
This approach works well with method chaining:
const params = new HttpParams()
  .set('one', '1')
  .set('two', '2');
...though that might be awkward if you need to wrap any of them in conditions.
Your loop works because you're grabbing a reference to the returned new instance. The code you posted that doesn't work, doesn't. It just calls set() but doesn't grab the result.
let httpParams = new HttpParams().set('aaa', '111'); // now it has aaa
httpParams.set('bbb', '222');                        // result has both but is discarded

Convert snake-case to camelCase

Source: https://coderwall.com/p/iprsng/convert-snake-case-to-camelcase

function snakeToCamel(s){
    return s.replace(/(\-\w)/g, function(m){return m[1].toUpperCase();});
}
or as more readable code


var snakeCaseString = 'lorem-ipsum';

var find = /(\-\w)/g;
var convert =  function(matches){
    return matches[1].toUpperCase();
};
var camelCaseString = snakeCaseString.replace(
    find,
    convert
);

Renewing Facebook Graph API token automatically?

  Mã truy cập dài hạn https://developers.facebook.com/docs/facebook-login/guides/access-tokens/get-long-lived/ https://community.n8n.io/t/re...