Skip to content

Instantly share code, notes, and snippets.

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

Saras Arya SarasArya

🏠
Working from home
View GitHub Profile
@SarasArya
SarasArya / printersettings.cs
Created October 15, 2023 06:01
Printer Settings in C#
string selectedPrinter = "";
selectedPrinter = BilzoLogs.ReadValueFromRegistry("PrinterName");
m_prefPaperSize = BilzoLogs.ReadValueFromRegistry("PaperSize");
m_centerAlign = BilzoLogs.ReadValueFromRegistry("CenterAlign");
m_printType = BilzoLogs.ReadValueFromRegistry("PrintType");
int selectedIndex = -1;
int paperSizeSelIdx = -1;
int index = 0;
foreach (string printer in System.Drawing.Printing.PrinterSettings.InstalledPrinters)
@SarasArya
SarasArya / .gitconfig
Created May 17, 2022 11:24
Git Config
[user]
name = <Your Name>
email = <your email id>
[init]
defaultBranch = main
[pull]
rebase = true
[fetch]
prune = true
[push]
@SarasArya
SarasArya / sum-of-products.js
Created October 7, 2021 09:56
Return Product for Even and 0 for Odd JS
// Given a list of integers, determine if the product of all of the integers is even or odd.
// Return the sum of all of the integers if the product of all of the integers is even.
// Return 0 if the product of all of the integers is odd.
// Note that 0 is considered even.
// Examples:
// Input: [1,2,3,4]
// Output: 10
// Explanation: 1 * 2 * 3 * 4 = 24. This is an even number. The sum of all of the integers is 10
// Input: [5,7,9]
@SarasArya
SarasArya / checkout.js
Created June 28, 2021 17:40
How to add Items to cart in Upscribe Checkout
// https://github.com/ai/nanoid/blob/030bf5dc47759a6199619b332937ba3e7a91db03/index.browser.js#L79
function nanoid(size = 21) {
let id = "";
const arr = new Uint8Array(size);
const bytes = crypto.getRandomValues(arr);
// A compact alternative for `for (var i = 0; i < step; i++)`.
while (size--) {
// It is incorrect to use bytes exceeding the alphabet size.
// The following mask reduces the random byte in the 0-255 value
@SarasArya
SarasArya / handler.js
Last active May 15, 2021 22:05
Serverless Sentry Error Handler example
// Node version 10.x AWS Lambda Serverless framework
const Sentry = require('@sentry/node'); // sentry version "@sentry/node": "^5.5.0",
Sentry.init({
dsn: 'https://randomstuff@sentry.io/1234567',
async beforeSend(event) {
console.log('\n Caught an exception \n');
return event;
},
@SarasArya
SarasArya / certbot-install-issue.md
Last active July 26, 2019 09:47
This Gist helps anyone solve the issue of pkg version mismatch with certbot. Very helpful when you want to automate the certificate generation packages.

In case you have a requirement to automate the certificate installation without docker and you have installed certificate on Ubuntu Machine 18.04 using.
sudo apt install software-properties-common.
sudo apt update.
sudo add-apt-repository ppa:certbot/certbot.
sudo apt update. sudo apt-get install python-certbot-nginx.
sudo apt install python3-pip.
sudo pip3 install certbot-dns-route53.

@SarasArya
SarasArya / serverless-offline-watch.txt
Last active May 25, 2019 17:33
Run serverless offline with restart and watch
"dev" : "nodemon --watch src/* --exec yarn sls offline --stage local"
Run it using yarn dev
Thank me later.
@SarasArya
SarasArya / server-setup.txt
Created April 10, 2019 19:16
Basic Server setup guidelines and links
ssh -i ~/Desktop/your-key-name.pem ubuntu@ec2-xx-xxx-xxx-xxx.ap-south-1.compute.amazonaws.com
Post which you will get a popup saying WARNING: UNPROTECTED PRIVATE KEY FILE!
To fix this error chmod 700 ~/Desktop/your-key-name.pem
1. Use this guide to setup a different user - https://www.digitalocean.com/community/tutorials/initial-server-setup-with-ubuntu-18-04
@SarasArya
SarasArya / lru.js
Created March 28, 2019 18:26
Create an LRU in javascript
const NEWER = Symbol("newer");
const OLDER = Symbol("older");
class LRU {
constructor(limit = 10) {
this.limit;
this.size;
this.cache = new Map();
this.newest = undefined;
this.oldest = undefined;
const rp = require('request-promise');
const urls = ['https://jsonplaceholder.typicode.com/todos/1', 'https://jsonplaceholder.typicode.com/todos/2'];
const newUrls = urls.map(url => () => rp(url));
Promise.resolve()
.then(x => newUrls[0]())
.then(x => newUrls[1]());
console.log(newUrls);