Skip to content

Instantly share code, notes, and snippets.

View hendrixroa's full-sized avatar
🏠
Working from home

Hendrix Roa hendrixroa

🏠
Working from home
View GitHub Profile
@hendrixroa
hendrixroa / get_page_headless.ts
Last active March 9, 2023 21:42
Get page function to open a headless browser window
public async getPage() {
if (!this.browser) {
await this.initBrowser();
}
const page = await this.browser.newPage();
// Avoiding Bot detection
const userAgent =
'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.39 Safari/537.36';
await page.setUserAgent(userAgent);
@hendrixroa
hendrixroa / headlessInit.ts
Created March 8, 2023 01:40
Initialize browser headless
private async initBrowser() {
const browserArgs: PuppeteerLaunchOptions = {
args: [
'--no-sandbox',
'--disable-setuid-sandbox',
'--headless',
'--disable-gpu',
'--disable-dev-shm-usage',
'--disable-web-security',
'--disable-infobars',
@hendrixroa
hendrixroa / HeadlessBrowserClass.ts
Created March 8, 2023 01:33
Empty class of headless browser
import { EventEmitter } from 'events';
import * as Puppeteer from 'puppeteer';
export class HeadlessBrowser extends EventEmitter {
protected browser: Puppeteer.Browser;
}
@hendrixroa
hendrixroa / cognito_auth.tsx
Created March 3, 2023 20:49
Snippet code to add authentication to a component
export default withAuthenticator(Swagger, true, [
<Greetings />,
<Loading />,
<SignIn />,
<RequireNewPassword/>,
<ForgotPassword />,
],
);
@hendrixroa
hendrixroa / swagger.tsx
Created March 3, 2023 20:45
Code snippet to configure a swagger instance in react.
const Swagger = ({...props}) => {
useEffect(() => {
const ui = SwaggerUI({
dom_id: '#swagger-custom-ui',
spec: swaggerData,
displayRequestDuration: true,
syntaxHighlight: {
activate: true,
theme: 'monokai'
},
REACT_APP_REGION=us-east-1
REACT_APP_USER_POOL_ID=<value>
REACT_APP_APP_CLIENT_ID=<client>
REACT_APP_API_KEY=<Optional API key>
YARN_AUDIT_SLACK_TOKEN=<yourToken> yarn run audit_report
private async sendSlackMessage(countVulnerabilities: number, packageName: string): Promise<void> {
const postData = {
attachments: [
{
author_name: 'YARN - AUDIT',
color: '#ff0000',
mrkdwn_in: ['text', 'pretext'],
text: `Found *${countVulnerabilities}* vulnerabilities in _${packageName}_ project, for more details run _yarn audit_`,
},
],
private calculateVulnerabilities(dataVulnerabilities: Vulnerabilities): number {
const countVulnerabilities: number = Object.values(
dataVulnerabilities,
).reduce((total: number, current: number) => {
return total + current;
});
return countVulnerabilities;
}
private filterSummaryData(vulnerabilities: string []): AuditData {
const summary: string | undefined =
vulnerabilities.find((item: string) => {
const itemParsed: any = JSON.parse(item);
return itemParsed.type === 'auditSummary';
}) || '{}';
const summaryData: any = JSON.parse(summary);
return summaryData as AuditData;
}