Skip to content

Instantly share code, notes, and snippets.

View umayrh's full-sized avatar

Umayr Hassan umayrh

View GitHub Profile
@oscarychen
oscarychen / postgres_ltree.sql
Created March 11, 2023 02:07
Postgres Ltree Cheatsheet
CREATE EXTENSION ltree;
CREATE TABLE test (path ltree);
-- Top
-- / | \
-- Science Hobbies Collections
-- / | \
-- Astronomy Amateurs_Astronomy Pictures
@henryivesjones
henryivesjones / postgresql_date_timestamp_interval_cheat_sheet.md
Created February 14, 2023 16:56
PostgreSQL DATE, TIMESTAMP, and INTERVAL cheat sheet

PostgreSQL DATE, TIMESTAMP, and INTERVAL cheat sheet

Working with DATE, TIMESTAMP, and INTERVAL in PostgreSQL can be confusing. In this article I will go over the three date/time related data types, and the two most useful date/time functions: DATE_PART and DATE_TRUNC. Finally, I will provide some real life examples of how these types and functions can be used within queries.

Types

PostgreSQL Date/Time Documentation

DATE

The DATE type contains the year, month, and day of a date. It is not possible to do any type of time related functions on a DATE without first converting it to a TIMESTAMP. Subtracting two DATE values from one another results in an INT representing the # of days between.

TIMESTAMP

The TIMESTAMP type contains a year, month, day, hour, minute, second, and microsecond. This is the type that I most often use.

@aasumitro
aasumitro / volt-pro.css
Created October 21, 2021 09:13
volt-pro
@import url(https://fonts.googleapis.com/css?family=Nunito+Sans:300,400,600,700&display=swap);.datepicker{display:none}.datepicker.active{display:block}.datepicker-dropdown{position:absolute;top:0;left:0;z-index:20;padding-top:4px}.datepicker-dropdown.datepicker-orient-top{padding-top:0;padding-bottom:4px}.datepicker-picker{display:inline-block;border-radius:4px;background-color:#fff}.datepicker-dropdown .datepicker-picker{box-shadow:0 2px 3px rgba(46,54,80,.1),0 0 0 1px rgba(46,54,80,.1)}.datepicker-picker span{display:block;flex:1;border:0;border-radius:4px;cursor:default;text-align:center;-webkit-touch-callout:none;-webkit-user-select:none;-ms-user-select:none;user-select:none}.datepicker-main{padding:2px}.datepicker-footer{box-shadow:inset 0 1px 1px rgba(46,54,80,.1);background-color:#d1d5db}.datepicker-controls,.datepicker-grid,.datepicker-view,.datepicker-view .days-of-week{display:flex}.datepicker-grid{flex-wrap:wrap}.datepicker-view .days .datepicker-cell,.datepicker-view .dow{flex-basis:14.28571%}.da

2 critical problems in Flask app performance

  1. CPU usage
  2. Database Optimization queries (overloaded database)

SOLUTIONS

Logging Database Performance and Optimizing queries

Before we can optimize queries , we need to know which is time-consuming

@leongjinqwen
leongjinqwen / heroku-deployment.md
Created November 13, 2020 12:08
Step by step deploy your app to Heroku

Heroku Deployment

  1. Create an app on Heroku
  2. Create a free Postgres Heroku instance.
  3. Set a new git remote to your Heroku git link
  4. Copy your Heroku git link from Heroku's website
  5. Go back to the root of your project directory and type
git remote add production <your heroku git link>
@leongjinqwen
leongjinqwen / flask-blueprint.md
Created January 21, 2020 11:26
summary on how flask-blueprint works

Flask Blueprint

Documentation: https://flask.palletsprojects.com/en/1.0.x/blueprints/

A Blueprint object works similarly to a Flask application object, but it is not actually an application. Rather it is a blueprint of how to construct or extend an application.

Defining a Blueprint

# instagram_web/blueprints/users/views.py

from flask import Blueprint
@rmed
rmed / app.py
Last active July 4, 2024 14:05
Dynamic Flask-WTF fields
# -*- coding: utf-8 -*-
# app.py
from flask import Flask, render_template
from flask_sqlalchemy import SQLAlchemy
from flask_wtf import FlaskForm
from wtforms import Form, FieldList, FormField, IntegerField, SelectField, \
StringField, TextAreaField, SubmitField
from wtforms import validators
@warpgate3
warpgate3 / gist:c1309f54e0564827f44d07bace610f15
Created November 29, 2018 06:51
functional index to_char on the postgresql (to_char, immutable issue)
CREATE OR REPLACE FUNCTION my_to_char(some_time timestamp)
RETURNS text
AS
$BODY$
select to_char($1, 'yyyy-mm-dd');
$BODY$
LANGUAGE sql
IMMUTABLE;
CREATE INDEX fc_op_vist_idx_function_med_dt ON table (my_to_char(MED_DT, 'YYYY-MM'));
@mrispoli24
mrispoli24 / setting-up-heroku-and-cloudflare.md
Created October 15, 2018 18:41
Setting up Heroku and Cloudflare (the right way)

Setting up Heroku and Cloudflare (the right way)

The following outlines how to setup Heroku + Cloudflare with a full SSL certificate. What this means is that communication between the browser and the Cloudflare CDN is encrypted as well as communication between Cloudflare and Heroku’s origin server. Follow these steps exactly and the setup is a breeze.

Step 1: Set up domain names in Heroku

First you want to add the root domain and the www domain to heroku. You do this by clicking into your production application, then going to settings and then scrolling down to Domains and certificates.

Here you will add <your_domain>.com and www.<your_domain>.com. This will give you two CNAME records. They will look something like <your_domain>.com.herokudns.com and www.<your_domain>.com.herokudns.com.

Step 2: Add CNAME records to Cloudfare.

@lieldulev
lieldulev / cpt4.csv
Created May 3, 2018 17:36
CPT 4 Codes, CSV format
com.medigy.persist.reference.type.clincial.CPT.code label
0003T Cervicography
0008T Upper gi endoscopy w/suture
0010T Tb test, gamma interferon
0016T Thermotx choroid vasc lesion
0017T Photocoagulat macular drusen
0018T Transcranial magnetic stimul
0019T Extracorp shock wave tx, ms
0020T Extracorp shock wave tx, ft
0021T Fetal oximetry, trnsvag/cerv