Skip to content

Instantly share code, notes, and snippets.

View reganto's full-sized avatar

Morteza Selseleh reganto

View GitHub Profile
@mberneti
mberneti / retryDynamicImport.ts
Last active June 10, 2025 08:42
This utility function retryDynamicImport enhances React’s lazy loading mechanism by adding retry logic with a versioned query parameter. It retries importing a component multiple times in case of failure, which can be useful for bypassing browser cache or dealing with intermittent network issues. It can be used as a drop-in replacement for React…
// Usage:
// Replace React.lazy(() => import('x'));
// with retryDynamicImport(() => import('x'));
import { ComponentType, lazy } from 'react';
const MAX_RETRY_COUNT = 15;
const RETRY_DELAY_MS = 500;
// Regex to extract the module URL from the import statement
@reganto
reganto / captcha.py
Created April 6, 2020 06:18
A simple captcha with python
from random import choice
from operator import add, mul, sub
def captcha():
try_count = 0
while True:
numbers = [number for number in range(1, 5)]
operators_functions = [add, mul, sub]
operators_functions_litrals_map = {add: "+", mul: "*", sub: "-"}
@reganto
reganto / substitute.py
Created February 18, 2019 08:41
Substitute indices in Python strings
# substitute indices in Python strings
def substitute(entry, i, j):
entry = list(entry)
entry[i], entry[j] = entry[j], entry[i]
return ''.join(entry)
# call sample
##
## How to install mcrypt in php7.2 / php7.3
## Linux / MacOS / OSX
##
## https://lukasmestan.com/install-mcrypt-extension-in-php7-2/
#
@cloverstd
cloverstd / main.py
Created October 22, 2016 09:31
Handle file upload by Tornado and Nginx Upload Module
#!/usr/bin/env python
# encoding: utf-8
import tornado.ioloop
import tornado.web
import tornado.log
import tornado.httpserver
from tornado.options import define, options
import logging
import tornado.gen
@cloverstd
cloverstd / app.py
Created September 27, 2016 12:48
Tornado forward HTTP Form upload
import tornado.gen
import tornado.web
import tornado.ioloop
import tornado.httpclient
import tornado.tcpclient
class ProxyHandler(tornado.web.RequestHandler):
@tornado.gen.coroutine
@oanhnn
oanhnn / using-multiple-github-accounts-with-ssh-keys.md
Last active June 13, 2025 09:23
Using multiple github accounts with ssh keys

Problem

I have two Github accounts: oanhnn (personal) and superman (for work). I want to use both accounts on same computer (without typing password everytime, when doing git push or pull).

Solution

Use ssh keys and define host aliases in ssh config file (each alias for an account).

How to?

  1. Generate ssh key pairs for accounts and add them to GitHub accounts.
@ccampbell
ccampbell / server.py
Last active February 11, 2021 10:31
Simple static webserver using tornado
#!/usr/bin/env python
import os
import tornado.web
from tornado.ioloop import IOLoop
from tornado.options import define, options
from tornado.escape import xhtml_escape
# config options
define('port', default=8080, type=int, help='port to run web server on')
define('debug', default=True, help='start app in debug mode')
@cloverstd
cloverstd / app.py
Last active November 4, 2019 21:33
微信二维码扫描登录
#!/usr/bin/env python
# encoding: utf-8
import tornado.ioloop
import tornado.httpclient
import tornado.web
import tornado.gen
import json
import tornado.websocket
import Queue
@cloverstd
cloverstd / cache.py
Last active October 27, 2021 05:35
tornado cache
# coding: utf-8
try:
import cPickle as pickle
except ImportError:
import pickle
try:
import hashlib
sha1 = hashlib.sha1