Skip to content

Instantly share code, notes, and snippets.

View Matheswaaran's full-sized avatar
🤟
Cool

Matheswaaran Matheswaaran

🤟
Cool
View GitHub Profile
@Matheswaaran
Matheswaaran / DocxReader.js
Created April 3, 2023 17:55
Reading .docx files in react.js
import React, { useState } from "react";
import PizZip from "pizzip";
import { DOMParser } from "@xmldom/xmldom";
function str2xml(str) {
if (str.charCodeAt(0) === 65279) {
// BOM sequence
str = str.substr(1);
}
return new DOMParser().parseFromString(str, "text/xml");
import React from "react";
import { hasCookie, setCookie } from "cookies-next";
const CookieConsent = (props) => {
const [showConsent, setShowConsent] = React.useState(true);
React.useEffect(() => {
setShowConsent(hasCookie("localConsent"));
}, []);
import JsPDF from "jspdf";
import html2canvas from "html2canvas";
const htmlStringToPdf = async (htmlString) => {
let iframe = document.createElement("iframe");
iframe.style.visibility = "hidden";
document.body.appendChild(iframe);
let iframedoc = iframe.contentDocument || iframe.contentWindow.document;
iframedoc.body.innerHTML = htmlString;
import React, { useState } from 'react';
import csv from 'csv';
function CsvParser() {
const [headers, setHeaders] = useState([]);
const [csvData, setCsvData] = useState([]);
const onFileUpload = (event) => {
const fileReader = new FileReader();
@Matheswaaran
Matheswaaran / envChange.js
Last active June 4, 2021 06:05
Change environment variables in JSON
const fs = require('fs');
const envChange = () => {
let env = process.argv.slice(2)[0].split("=")[1];
if (env === "dev" || env === "testing" || env === "production") {
fs.readFile(`./env/${env}.json`, 'utf8', (err, data) => {
if (err) {
throw err;
} else {
@Matheswaaran
Matheswaaran / CompressedUpload.js
Created March 7, 2021 05:14
Image Compressing using "compressorjs" package
import React, {useState} from 'react';
import Compressor from 'compressorjs';
const Upload = () => {
const [compressedFile, setCompressedFile] = useState(null);
const handleCompressedUpload = (e) => {
const image = e.target.files[0];
new Compressor(image, {
quality: 0.8, // 0.6 can also be used, but its not recommended to go below.
@Matheswaaran
Matheswaaran / default
Created December 3, 2020 13:38
Nginx configuration for the apple-app-site-association file
##
# You should look at the following URL's in order to grasp a solid understanding
# of Nginx configuration files in order to fully unleash the power of Nginx.
# https://www.nginx.com/resources/wiki/start/
# https://www.nginx.com/resources/wiki/start/topics/tutorials/config_pitfalls/
# https://wiki.debian.org/Nginx/DirectoryStructure
#
# In most cases, administrators will remove this file from sites-enabled/ and
# leave it as reference inside of sites-available where it will continue to be
# updated by the nginx packaging team.
@Matheswaaran
Matheswaaran / ImageUploadCrop.js
Created March 20, 2020 08:29
Cropping image in ReactJs
import { Button, Icon, Modal, Popover, Upload } from "antd";
import React from "react";
import ReactImageCrop from "react-image-crop";
import "react-image-crop/dist/ReactCrop.css";
class ImageUploadCrop extends React.Component {
constructor(props) {
super(props);
this.state = {
loading: false,
import React from "react";
import ReactDOM from "react-dom";
import {Select} from "antd";
//API endpoint
const API_ROOT = "";
// Give the API call to add a new tag
cosnt ADD_TAG = "";
mport React from "react";
import ReactJWPlayer from "react-jw-player";
import './index.css';
class JwPlayer extends React.Component {
constructor(props) {
super(props);
this.state = {
is_liked: false,
};