Skip to content

Instantly share code, notes, and snippets.

View senthilmpro's full-sized avatar

Senthil Muthuvel senthilmpro

View GitHub Profile
@senthilmpro
senthilmpro / deep-flatten-array-js.js
Created October 23, 2019 18:55
Deep Flatten Array - Javascript
function deepFlatten(arr){
return [].concat.apply([], arr.map(x => Array.isArray(x) ? deepFlatten(x) : x));
}
@senthilmpro
senthilmpro / delay-es6.js
Created November 12, 2019 02:57
es6-javascript-wait-function-promise
/**
* Sets a delay for 'wait' milliseconds
* @param {Number} wait - wait time in milliseconds
*/
let delay = async (wait) => {
console.log(`Waiting for ${wait} milliseconds`);
return new Promise(p => setTimeout(p, wait));
}
@senthilmpro
senthilmpro / angular-keypress-together.js
Created November 21, 2019 06:46
angular-keypress-together.js
export class AppComponent {
title = 'ui';
keys = {
space : false,
ctrl : false
}
@HostListener('window:keydown', ['$event'])
keyEventDown(event: KeyboardEvent) {
if(event.keyCode === 17){
@senthilmpro
senthilmpro / async-await-es6-angular.js
Created November 21, 2019 22:25
async-await-es6-angular.js
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
@Injectable({
providedIn: 'root'
})
export class AuthService {
httpClient : HttpClient;
constructor(httpClient : HttpClient) {
this.httpClient = httpClient;
@senthilmpro
senthilmpro / nodejs-express-server.js
Created December 5, 2019 22:57
node.js express server
const express = require('express');
const app = new express();
// url requests. GET/POST
app.use(express.json());
app.use(express.urlencoded());
app.use(express.static(__dirname + "/public"));
// routing.
@senthilmpro
senthilmpro / PieChart.js
Created January 11, 2020 19:37
Pie-Chart-React-Hook.js
import React from 'react';
import * as d3 from 'd3';
export const PieChart = (props) => {
const chart = React.useRef();
const { width, height, margin, chartData, title } = props;
// init all d3-chart related data here.
const renderChart = () => {
@senthilmpro
senthilmpro / js-kebab-case.js
Created January 12, 2020 04:25
JS kebab case
const toKebabCase = str =>
str &&
str
.match(/[A-Z]{2,}(?=[A-Z][a-z]+[0-9]*|\b)|[A-Z]?[a-z]+[0-9]*|[A-Z]|[0-9]+/g)
.map(x => x.toLowerCase())
.join('-');
@senthilmpro
senthilmpro / create-folder.js
Last active January 24, 2020 01:54
create-folder.js
const fs = require('fs');
const path = require('path');
const HOME_PATH = "/Users/senthilmpro/Desktop/test";
const HOME_FOLDER = path.resolve(HOME_PATH);
const files = fs.readdirSync(HOME_FOLDER, 'utf-8');
console.log(files);
@senthilmpro
senthilmpro / create-folder-2.js
Created January 29, 2020 03:29
create-folder-2.js
const fs = require('fs');
const path = require('path');
// settings.
const CONF = {
HOME_PATH : "/Volumes/SYMC/movies/2-hindi/2-hindi-hevc"
}
@senthilmpro
senthilmpro / rename-bulk-folder-files.js
Last active February 15, 2020 07:56
rename-bulk-folder-files.js
const renameFile = (folderPath, strToRemove) => {
const fs = require('fs');
const path = require('path');
const files = fs.readdirSync(folderPath,'utf-8');
files.forEach(v => {
if(v.indexOf(strToRemove) !== -1){
let newName = v.replace(strToRemove, "");