Skip to content

Instantly share code, notes, and snippets.

View vubon's full-sized avatar
🎯
Focusing

Vubon vubon

🎯
Focusing
View GitHub Profile
@vubon
vubon / pyenv.sh
Created January 28, 2019 07:07
CentOS 7 , Install Pyenv
yum install -y gcc gcc-c++ make git patch openssl-devel zlib-devel readline-devel sqlite-devel bzip2-devel
curl -L https://raw.githubusercontent.com/yyuu/pyenv-installer/master/bin/pyenv-installer | bash
echo 'export PATH="$HOME/.pyenv/bin:$PATH"' >> .zshrc
echo 'eval "$(pyenv init -)"' >> .zshrc
echo 'eval "$(pyenv virtualenv-init -)"' >> .zshrc
exec $SHELL - l
pyenv install 3.6.0
pyenv global 3.6.0
@vubon
vubon / dispatch_table.py
Created January 8, 2019 18:16
Dispatch Table example with O(n) and O(1) complexity
"""
## ==== Never create O(n), if you can O(1) ===== #
“A dispatch table is a table of pointers to functions or methods.”
Link: https://en.wikipedia.org/wiki/Dispatch_table?fbclid=IwAR392A7zZELtQxij7w5iHurjdKJxuYbdyOc6_iVBh7pqvr4oeEUr0xLUNpk
"""
import datetime
def monday_task():
@vubon
vubon / models.py
Last active January 29, 2022 06:01
Django BRIN index in PostgreSQL Database
from django.contrib.postgres.indexes import BrinIndex
from django.db import models
class SampleData(models.Model):
created_at = models.DateTimeField()
class Meta:
"""
You must need to use PostgreSQL DB unless you can't use BrinIndex
"""
@vubon
vubon / script.py
Created November 8, 2018 10:01
Generate Excel Sheet of Django user
import csv
from django.contrib.auth.models import User
def run():
with open("users.xls", "w", newline='') as csvfile:
writer = csv.writer(csvfile)
writer.writerow(['Username', 'Full Name', 'Email address'])
users = User.objects.filter(is_active=True, is_staff=False)
for user in users:
writer.writerow([user.username, user.first_name + user.last_name, user.email])
@vubon
vubon / Datetime.py
Created October 13, 2018 18:07
Python Date time object creation and filter data with Django ORM
"""
python manage.py runscript <script name> --script-args <args>
"""
import datetime
from contact.v2.models import TestModel
from django.utils import timezone
def run():
start_date = (timezone.now().date() - timezone.timedelta(days=1)).strftime('%Y-%m-%d') + 'T20:00:00'
@vubon
vubon / Dockerfile
Created August 29, 2018 10:28
Dockerfile with alpine 3.6 python
FROM alpine:3.6
ENV PYTHONUNBUFFERED 1
WORKDIR /usr/src/national_id
ADD requirements.txt /usr/src/national_id/
RUN apk add --no-cache python3 && \
python3 -m ensurepip && \
rm -r /usr/lib/python*/ensurepip && \
pip3 install --upgrade pip setuptools && \
if [ ! -e /usr/bin/pip ]; then ln -s pip3 /usr/bin/pip ; fi && \
if [[ ! -e /usr/bin/python ]]; then ln -sf /usr/bin/python3 /usr/bin/python; fi && \
@vubon
vubon / finding_date.py
Last active July 22, 2018 01:32
Finding date in two dates range by Python
from datetime import date, timedelta, datetime
start_date = date(2018,1,1)
end_date = datetime.now()
every_month = 28
def finding_date(start_date, end_date, every_month):
start_month = start_date.month
end_months = (end_date.year-start_date.year)*12 + end_date.month
has_month = []
has_not = 0
@vubon
vubon / finding.py
Created July 21, 2018 23:36
Finding last date from a dates range by Python
from datetime import date, timedelta, datetime
def month_in_range(start_date, end_date):
"""Get the last day of every month in a range between two datetime values.
Return a generator
"""
start_month = start_date.month
end_months = (end_date.year-start_date.year)*12 + end_date.month
date_obj = []
for month in range(start_month, end_months + 2):
@vubon
vubon / db_reset.sh
Created May 23, 2018 03:17
Reset Database by bash script
#!/usr/bin/env bash
DEFAULT_USER="admin"
DEFAULT_EMAIL="[email protected]"
DEFAULT_PASS="nothing1234"
######### MAIN CLEAN #########
rm 'db.sqlite3'
readonly virtual='/home/vubon/personal/upwork_env/bin/activate'
source ${virtual}
import 'package:flutter/material.dart';
// for generation QR Code
import 'package:qr_flutter/qr_flutter.dart';
class QRCodeGenerator extends StatefulWidget{
@override
_QRCodeGenerator createState() => new _QRCodeGenerator();
}