Skip to content

Instantly share code, notes, and snippets.

View vubon's full-sized avatar
🎯
Focusing

Vubon vubon

🎯
Focusing
View GitHub Profile
@vubon
vubon / response.py
Created December 3, 2017 05:01
Checking Rest API Response Time
"""
This script will check server response time in seconds.
"""
import requests
while True:
a = requests.get("your api url").elapsed.total_seconds()
print(a)
@vubon
vubon / postgres
Created December 14, 2017 08:40 — forked from mmrwoods/postgres
Postgres maintenance crontab file
# dump all databases once every 24 hours
45 4 * * * root nice -n 19 su - postgres -c "pg_dumpall --clean" | gzip -9 > /var/local/backup/postgres/postgres_all.sql.gz
# vacuum all databases every night (full vacuum on Sunday night, lazy vacuum every other night)
45 3 * * 0 root nice -n 19 su - postgres -c "vacuumdb --all --full --analyze"
45 3 * * 1-6 root nice -n 19 su - postgres -c "vacuumdb --all --analyze --quiet"
# re-index all databases once a week
0 3 * * 0 root nice -n 19 su - postgres -c 'psql -t -c "select datname from pg_database order by datname;" | xargs -n 1 -I"{}" -- psql -U postgres {} -c "reindex database {};"'
//Add in text after price to all products
function custom_text_to_price( $price, $product ) {
$price = $price . ' USD';
return $price;
}
add_filter( 'woocommerce_get_price_html', 'custom_text_to_price', 100, 2 );
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();
}
@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="admin@mail.com"
DEFAULT_PASS="nothing1234"
######### MAIN CLEAN #########
rm 'db.sqlite3'
readonly virtual='/home/vubon/personal/upwork_env/bin/activate'
source ${virtual}
@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 / 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 / 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 / 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 / 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])