Skip to content

Instantly share code, notes, and snippets.

View DoonDoony's full-sized avatar
🐈

Doon DoonDoony

🐈
View GitHub Profile
@DoonDoony
DoonDoony / .spaceship_config
Last active October 4, 2023 04:55
oh-my-zsh spaceship theme HOW TO
SPACESHIP_PROMPT_ORDER=(
battery
user
conda
aws
package
docker
node
ruby
elixir
@DoonDoony
DoonDoony / decorator_response_ok.py
Last active October 14, 2018 14:17
Python Function Decorator Example #1
from urllib.parse import urljoin
import urllib3
from urllib3.exceptions import HTTPError
def response_ok(func):
def validate(*args, **kwargs):
result = func(*args, **kwargs)
if result.status != 200:
@DoonDoony
DoonDoony / memoized-getter.js
Last active October 29, 2018 15:43
A code snipper for memoized getter performance test
// Required only nodejs
const { performance } = require('perf_hooks');
const obj = {
get memoizedGetter() {
delete this.memoizedGetter;
return this.memoizedGetter = [...Array(5e+7).keys()].reduce((prev, num) => prev + num, 0);
},
get commonGetter() {
return [...Array(5e+7).keys()].reduce((prev, num) => prev + num, 0);
@DoonDoony
DoonDoony / lazy-loading-with-io.html
Created March 28, 2019 01:34
Implement a image lazy loading with Intersection Observer API
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"
name="viewport">
<meta content="ie=edge" http-equiv="X-UA-Compatible">
<title>Document</title>
<style>
div.image-box {
@DoonDoony
DoonDoony / infinite-scrolling-with-intersection-observer-api.html
Last active March 28, 2019 03:10
Implement 'Infinite Scrolling' with Intersection Observer API with "Cats"!
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Infinite Scrolling 🤞</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/meyer-reset/2.0/reset.css">
<style>
@DoonDoony
DoonDoony / read_timeout.py
Created April 23, 2019 05:49
Test handling ReadTimeout Exception
import requests
import logging
from requests.exceptions import ReadTimeout, ConnectionError
logger = logging.getLogger(__name__)
url = 'https://www.google.com:81'
data = { 'username': 'DoonDoony', 'address': '...' }
retries = 3
@DoonDoony
DoonDoony / class_decorator.py
Created April 23, 2019 05:50
Simple Python Class Decorator
import sys
import logging
logging.basicConfig(stream=sys.stdout, level=logging.DEBUG)
class logger:
def __init__(self, function):
self.function = function
self.logger = logging.getLogger(__name__)
@DoonDoony
DoonDoony / pycharm_python_console_shell_plus_script.py
Last active January 20, 2024 15:50
Using `shell_plus` in pycharm django console
# 💡 NOTE: This only works if you are pretend to using `Django Console` feature in Pycharm
# Paste codes below into `Build, Execution, Deployment > Console > Django Console > Starting Script`
# requirements: `django_extensions`, `IPython`
import sys
import django
from IPython.core.getipython import get_ipython
from django_extensions.management.notebook_extension import load_ipython_extension
@DoonDoony
DoonDoony / prepare-commit-msg
Created October 11, 2019 06:04
prepare-commit-msg hook for jira id prefixed commit message
#!/usr/bin/env python
from __future__ import print_function
import re
import sys
GIT_HEAD_REF = '.git/HEAD'
ticket_number = re.compile(r'\b[A-Z]{2,}-[0-9]+')
branch_ticket_number = re.compile(r'\b[a-z]{2,}-[0-9]+')
@DoonDoony
DoonDoony / smtp.py
Created October 19, 2019 09:07
Send mail via Gmail account
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
mail_content = 'Hi there!'
sender_address = "mailer@example.com"
sender_password = "very_secret_password"
receiver_address = "kind.person@example.com"