Skip to content

Instantly share code, notes, and snippets.

@m-khooryani
m-khooryani / Program.cs
Created June 9, 2020 16:10
Longest substring with K unique characters
class Program
{
static void Main(string[] args)
{
Console.WriteLine(LongestSubstringWithKUniqueChars("abcba", 2));
}
private static string LongestSubstringWithKUniqueChars(string s, int k)
{
if (k == 0)
@cvan
cvan / css-ios-pwa-viewport.css
Created April 3, 2020 22:14
CSS for env(safe-area-inset-top) for iOS "Add to Homescreen" / PWA; standalone styles
@supports (padding-top: constant(safe-area-inset-top)) {
body {
padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
}
@media (display-mode: fullscreen) {
body {
padding: 0;
}
import React from 'react';
import ProgressiveImage from 'react-progressive-graceful-image';
import styled from 'styled-components';
const PlcHolder = styled.img`
background: linear-gradient(
to right,
rgb(246, 247, 248) 0%,
rgb(237, 238, 241) 20%,
rgb(246, 247, 248) 40%,
// 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', () => {

CockroachDB and Docker Compose

This is the first in a series of tutorials on CockroachDB and Docker Compose

  • Information on CockroachDB can be found here.
  • Information on Docker Compose can be found here
  1. Install Docker Desktop

Because we already have an official CockroachDB docker image, we will use that in our docker-compose.yml file. We recommend you use one of the current tags instead of latest.

@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
// 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
});
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
@jamesseanwright
jamesseanwright / lazy-routes.tsx
Created July 17, 2019 16:40
Lazy route loading with React.lazy and Suspense
import * as React from 'react';
import Nav from './Nav.jsx';
import { Router } from './routing';
const routes = new Map<string, React.ComponentType>([
['/', () => <p>Pick an Ipsum!</p>],
['/lorem', React.lazy(() => import('./pages/Lorem'))],
['/bacon', React.lazy(() => import('./pages/Bacon'))],
['/hipster', React.lazy(() => import('./pages/Hipster'))],
['/office', React.lazy(() => import('./pages/Office'))],
import * as React from 'react';
const Lorem = React.lazy(() => import('./pages/Lorem'));
const App = () => (
<React.Suspense fallback={<div className="loading-spinner" />}>
<Lorem />
</React.Suspense>
);