This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <winsock2.h> | |
#include <iostream> | |
struct CLIENT_INFO { | |
SOCKET hClientSocket; | |
struct sockaddr_in clientAddr; | |
}; | |
char szServerIPAddr[] = "192.168.1.4"; // Put here the IP address of the server | |
int nServerPort = 5050; // The server port that will be used by |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const BlobToBase64 = function(blob){ | |
let blobUrl = URL.createObjectURL(blob); | |
return new Promise((resolve, reject) => { | |
let img = new Image(); | |
img.onload = () => resolve(img); | |
img.onerror = err => reject(err); | |
img.src = blobUrl; | |
}).then(img => { | |
URL.revokeObjectURL(blobUrl); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Convert a Readable Stream to base64 string | |
* @param {ReadableStream} stream - a readable stream to convert in base64 string | |
* @returns {Promise} - Promise that resolve in a string containing the base64 | |
*/ | |
const streamToBase64 = (stream) => { | |
const concat = require('concat-stream') | |
const { Base64Encode } = require('base64-stream') | |
return new Promise((resolve, reject) => { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import fs from 'fs'; | |
import path from 'path'; | |
const convert = (imgPath) => { | |
// read image file | |
fs.readFile(imgPath, (err, data)=>{ | |
// error handle | |
if(err) { | |
throw err; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import axios from 'axios'; | |
import {toCamelCase, toSnakeCase} from '../util'; | |
import qs from 'qs'; | |
// You can intercept requests or responses before they are handled by then or catch. | |
// https://github.com/axios/axios#interceptors | |
// Add a response interceptor and camelCase return data (for JS) | |
axios.interceptors.response.use((response) => { | |
response.data = toCamelCase(response.data); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function removeVietnameseTones(str) { | |
str = str.replace(/à|á|ạ|ả|ã|â|ầ|ấ|ậ|ẩ|ẫ|ă|ằ|ắ|ặ|ẳ|ẵ/g,"a"); | |
str = str.replace(/è|é|ẹ|ẻ|ẽ|ê|ề|ế|ệ|ể|ễ/g,"e"); | |
str = str.replace(/ì|í|ị|ỉ|ĩ/g,"i"); | |
str = str.replace(/ò|ó|ọ|ỏ|õ|ô|ồ|ố|ộ|ổ|ỗ|ơ|ờ|ớ|ợ|ở|ỡ/g,"o"); | |
str = str.replace(/ù|ú|ụ|ủ|ũ|ư|ừ|ứ|ự|ử|ữ/g,"u"); | |
str = str.replace(/ỳ|ý|ỵ|ỷ|ỹ/g,"y"); | |
str = str.replace(/đ/g,"d"); | |
str = str.replace(/À|Á|Ạ|Ả|Ã|Â|Ầ|Ấ|Ậ|Ẩ|Ẫ|Ă|Ằ|Ắ|Ặ|Ẳ|Ẵ/g, "A"); | |
str = str.replace(/È|É|Ẹ|Ẻ|Ẽ|Ê|Ề|Ế|Ệ|Ể|Ễ/g, "E"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// check version | |
node -v || node --version | |
// list locally installed versions of node | |
nvm ls | |
// list remove available versions of node | |
nvm ls-remote | |
// install specific version of node |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
// Register the service worker | |
if ('serviceWorker' in navigator) { | |
navigator.serviceWorker.register('/service-worker.js').then(function(registration) { | |
// Registration was successful | |
console.log('ServiceWorker registration successful with scope: ', registration.scope); | |
}).catch(function(err) { | |
// registration failed :( | |
console.log('ServiceWorker registration failed: ', err); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import _ from 'lodash'; | |
/* | |
* Description: | |
* Add `.parent` property (with reference to parent object) | |
* to each array item recursively. | |
* | |
* INPUT: | |
* | |
* parents [] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#### without path | |
##### create table | |
```sql | |
CREATE TABLE _test(id SERIAL PRIMARY KEY, item_id INT NOT NULL, parent_id INT); | |
INSERT INTO _test(item_id, parent_id) VALUES (1, null), (2, 1), (3, 1), (3, 5), (4, 3), (5, 5); | |
``` | |
##### get children recursively | |
```sql |
NewerOlder