Skip to content

Instantly share code, notes, and snippets.

View senthilmpro's full-sized avatar

Senthil Muthuvel senthilmpro

View GitHub Profile
@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 / 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 / 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 / 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 / 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 / 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 / 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 / fastify-server.js
Created April 16, 2019 22:01
fastify-server setup
const fastify = require('fastify')({ logger: true });
const axios = require('axios');
const path = require('path');
const routes = require('./routes/route');
//console.log(route);
routes.forEach((route, index) => {
fastify.route(route)
});
@senthilmpro
senthilmpro / read-files-from-folder.js
Created April 1, 2019 23:24
Node.js Read files from Folder
const path = require('path');
const fs = require('fs');
function readFilesFromDir(dir) {
var filelist = [];
walkSync(dir, filelist);
return filelist;
}
@senthilmpro
senthilmpro / create-acc-arch1ve-new.js
Last active April 27, 2024 05:26
create-acc-arch1ve-new.js
async function createAccount(){
var USER_PREFIX = 'USERNAME'; // change here.
var USER_PASS = 'PASSWORD'; // change-here
var TIMER_DELAY = 400;
// username
await delay(TIMER_DELAY);
var randomGuid = guid();