Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View smartworld-dm's full-sized avatar
🏠
Working from home

Smart World smartworld-dm

🏠
Working from home
View GitHub Profile
import asyncio
async def worker(name, number_of_hours):
for i in range(number_of_hours):
await asyncio.sleep(1)
print(f"@20 - Worker {name} is working {i + 1} hours...")
async def workers():
# Schedule three calls *concurrently*:
print('@10 - 3 workers will start working')
@smartworld-dm
smartworld-dm / decorators.py
Created May 1, 2020 02:58 — forked from canokay/decorators.py
Django Custom View Decorators
from django.http import HttpResponseRedirect
from django.core.exceptions import PermissionDenied
from django.urls import reverse
from django.shortcuts import render
from django.shortcuts import redirect
def role_required(allowed_roles=[]):
def decorator(view_func):
def wrap(request, *args, **kwargs):
@smartworld-dm
smartworld-dm / pytz-time-zones.py
Created March 25, 2020 10:55 — forked from heyalexej/pytz-time-zones.py
list of pytz time zones
>>> import pytz
>>>
>>> for tz in pytz.all_timezones:
... print tz
...
...
Africa/Abidjan
Africa/Accra
Africa/Addis_Ababa
Africa/Algiers
def validate_iso8601_date(date_str):
regex = r'^([0-9]{4})-?(1[0-2]|0[1-9])-?(3[01]|0[1-9]|[12][0-9])$'
match_iso8601_date = re.compile(regex).match
try:
if match_iso8601_date( date_str ) is not None:
return True
except:
pass
@smartworld-dm
smartworld-dm / nginx.conf
Created October 15, 2019 09:55 — forked from baskaran-md/nginx.conf
NginX allow POST on static pages.
# ...
server {
listen 80;
server_name localhost;
location / {
root html;
index index.html index.htm;
}
@smartworld-dm
smartworld-dm / commandline.txt
Created October 1, 2019 07:56 — forked from sandervm/commandline.txt
Generate Django secret key commandline
$ python -c 'import random; print "".join([random.choice("abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)") for i in range(50)])'
@smartworld-dm
smartworld-dm / middleware.py
Created June 29, 2019 19:20 — forked from rbtsolis/middleware.py
Django Access the Request or User Object Inside the Models and Signals
# 1) Create a middlewares/middlewares.py file and copy this:
import threading
class RequestMiddleware:
def __init__(self, get_response, thread_local=threading.local()):
self.get_response = get_response
self.thread_local = thread_local
# One-time configuration and initialization.
@smartworld-dm
smartworld-dm / invoice_pdf.css
Created January 10, 2019 11:19
invoice design css
body {
background-color: black;
padding: 0;
margin: 0;
width: 100%;
height: 100%;
font-family: 'Proxima Nova Soft', 'Helvetica Neue', sans-serif;
}
.main {
@smartworld-dm
smartworld-dm / disable-gpu-mac.md
Created December 16, 2018 04:00 — forked from marpontes/disable-gpu-mac.md
Pass --disable-gpu down to Electron apps on mac (Slack, Whatsapp, Trello, ...)

On my Macbook Pro (OS X El Capitan) I was having issues on Electron based apps. These apps had visual issues/glitches like blank screens, visual components showing only when hovering or transparent menus.

By opening with these comands, the problems disappeared.

open /Applications/Slack.app/ --args --disable-gpu
open /Applications/Trello.app/ --args --disable-gpu
open /Applications/Whatsapp.app/ --args --disable-gpu
@smartworld-dm
smartworld-dm / rm_mysql.md
Created December 10, 2018 23:03 — forked from vitorbritto/rm_mysql.md
Remove MySQL completely from Mac OSX

Remove MySQL completely

  1. Open the Terminal

  2. Use mysqldump to backup your databases

  3. Check for MySQL processes with: ps -ax | grep mysql

  4. Stop and kill any MySQL processes

  5. Analyze MySQL on HomeBrew:

brew remove mysql