Skip to content

Instantly share code, notes, and snippets.

View nsdevaraj's full-sized avatar
🎯
Focusing

N.S.Devaraj nsdevaraj

🎯
Focusing
View GitHub Profile

AI vs. Sewing Machines

Socio-Economic Impact Analysis

Content

  • Labor and Production
  • Cost and Investment
  • Impact and Potential

Section 1 - Labor and Production

@nsdevaraj
nsdevaraj / reactail.sh
Created August 13, 2024 10:25
starter
if ! command -v npx
then
echo "npx is required to be installed for this script"
exit
fi
echo "Creating a new project using create-react-app"
npx create-react-app $1
cd $1
@nsdevaraj
nsdevaraj / random loop.js
Created August 6, 2024 14:30
Automation
let randomLoop = 8;
let parentContainer = document.getElementsByClassName("scrollRegion");
 
const getRandomNumber = (min, max) => {
  return Math.floor(Math.random() * (max - min + 1) + min);
};
 
function task(index) {
  if (index >= randomLoop) return;
  let parent = document.getElementsByClassName("scrollRegion")[1];
@nsdevaraj
nsdevaraj / csrf.tsx
Created August 5, 2024 14:13
Prevention of Cross-Site Request Forgery (CSRF) Attacks
import express from 'express';
import csrf from 'csurf';
import cookieParser from 'cookie-parser';
const app = express();
app.use(cookieParser());
app.use(csrf({ cookie: true }));
app.use((req, res, next) => {
@nsdevaraj
nsdevaraj / app-xss.tsx
Created August 5, 2024 14:11
Prevention of Cross-Site Scripting (XSS) Attacks
import express from 'express';
import helmet from 'helmet';
const app = express();
// Use helmet to set various HTTP headers
app.use(helmet());
// Set a custom Content Security Policy
app.use(helmet.contentSecurityPolicy({
@nsdevaraj
nsdevaraj / Inject.ts
Created August 5, 2024 14:09
Prevention of Injection Attacks
import { getRepository } from 'typeorm';
import { User } from './entity/User';
async function getUser(username: string): Promise<User | undefined> {
const userRepository = getRepository(User);
return await userRepository.findOne({ where: { username } });
}
// Usage
const user = await getUser(username);
@nsdevaraj
nsdevaraj / session.ts
Created August 5, 2024 14:07
Prevention of the Use of Insecure Session IDs
import express from 'express';
import session from 'express-session';
import crypto from 'crypto';
const app = express();
app.use(session({
secret: 'your-secret-key',
resave: false,
saveUninitialized: true,
@nsdevaraj
nsdevaraj / checkPermission.ts
Created August 5, 2024 14:04
Prevention of Authorization Bypass Attacks
import { Request, Response, NextFunction } from 'express';
interface User {
id: string;
roles: string[];
}
function checkPermission(permission: string) {
return (req: Request, res: Response, next: NextFunction) => {
const user = req.user as User;
class AppearanceModeProvider {
constructor() {
this.currentMode = 'default';
}
setMode(mode) {
this.currentMode = mode;
this.applyMode();
}
[LicensePlans.WATERFALL]: {
TEMPLATE: [
ETemplateId.WATERFALL_VERTICAL,
ETemplateId.WATERFALL_HORIZONTAL,
ETemplateId.WATERFALL_SINGLE_MEASURE_HORIZONTAL,
ETemplateId.WATERFALL_SINGLE_MEASURE_VERTICAL,
ETemplateId.COLUMN_WATERFALL_HORIZONTAL,
ETemplateId.COLUMN_WATERFALL_VERTICAL,
ETemplateId.PAIRED_WATERFALL_HORIZONTAL,