Skip to content

Instantly share code, notes, and snippets.

View arash16's full-sized avatar
💭
Coding..

Arash Shakery arash16

💭
Coding..
View GitHub Profile

Keybase proof

I hereby claim:

  • I am arash16 on github.
  • I am arash16 (https://keybase.io/arash16) on keybase.
  • I have a public key whose fingerprint is B513 AC6B 61D1 1F45 93C8 8FE6 AE79 A9BA 3518 BC72

To claim this, I am signing this object:

export default function asyncDataWrapper(originalAsyncData) {
return async function(ctx) {
try {
return await originalAsyncData.call(this, ctx);
}
catch (e) {
// statusCode=1 is connectivity error (assigned inside API-Layer)
if (process.client && e.statusCode === 1) {
window.addEventListener('online', () => {
// reload the page when connection is back
const cache = {};
export function makePlaceholder(width, height) {
const key = `${width}x${height}`;
if (!cache[key]) {
cache[key] = 'data:image/svg+xml;base64,' + window.btoa(
`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${width} ${height}">
<rect width="${width}" height="${height}" fill="#f0f0f0"/>
</svg>`
);
}
// Simplified Sample Code for limiting nuxt ssr per user
const { RateLimiterMemory } = require("rate-limiter-flexible");
const { cpuFree } = require('os-utils');
// each user has 1SSR per minute
const ipRateLimiter = new RateLimiterMemory({
points: 1, // 1 SSR
duration: 60, // Per minute
});
@arash16
arash16 / 0-blue-green-deployment.sh
Last active February 25, 2023 17:46
Sample minimal blue/green deployment strategy codes used on cafebazaar.ir
# this is a minimal sample code used for ci pipelines to implement blue/green deployment
// this code is executed in the context of each tab
import {Workbox} from 'workbox-window';
if ('serviceWorker' in navigator) {
const wb = new Workbox('/sw.js');
wb.addEventListener('waiting', () => {
console.log('A new service worker has installed');
wb.addEventListener('controlling', () => {
[
{
"id": 1,
"name": "0 \u0631\u0633\u06cc\u062f\u06af\u06cc \u0628\u0647 \u062a\u062e\u0644\u0641",
"children": [
{
"id": 3,
"name": "\u0627\u0637\u0644\u0627\u0639\u0627\u062a \u062a\u0648\u0636\u06cc\u062d\u06cc \u06af\u0645\u0631\u0627\u0647\u200c\u06a9\u0646\u0646\u062f\u0647 ",
"description": "\ufeff\u0648\u062c\u0648\u062f \u0627\u0637\u0644\u0627\u0639\u0627\u062a \u06af\u0645\u0631\u0627\u0647\u200c\u06a9\u0646\u0646\u062f\u0647 \u0648 \u063a\u06cc\u0631 \u0648\u0627\u0642\u0639\u06cc \u062f\u0631 \u0627\u0637\u0644\u0627\u0639\u0627\u062a \u062a\u0648\u0636\u06cc\u062d\u06cc \u0628\u0631\u0646\u0627\u0645\u0647: \n\u0628\u0631\u0646\u0627\u0645\u0647\u200c\u0647\u0627 \u0646\u0628\u0627\u06cc\u062f \u062f\u0627\u0631\u0627\u06cc \u0627\u0637\u0644\u0627\u0639\u0627\u062a\u06cc \u063a\u0644\u0637 \u0648 \u06af\u0645\u0631\u0627\u0647\u200c\u06a9\u0646\u0646\u062f\u0647 \u062f\u0631 \u0645\u062d\u062a\u0648\u0627\u
/*
export AWS_ACCESS_KEY=key
export AWS_SECRET_ACCESS_KEY=secret
export AWS_BUCKET_NAME=bucket
yarn init
yarn add aws-sdk
node server.js
*/
@arash16
arash16 / data.json
Last active December 28, 2022 11:38
An updated gist description
{
"comments": [
{ "user": "arash16", "text": "hello world" },
{ "user": "arash16", "text": "hello 2" },
{ "user": "arash16", "text": "hello 2" },
{ "user": "arash16", "text": "hello 5" },
{ "user": "arash16", "text": "hello 7" }
]
}
SENDGRID_KEY=sendgrid-api-key
SECRET=secret-to-sign-subscription-links