Skip to content

Instantly share code, notes, and snippets.

View ichux's full-sized avatar
🏠
Working from home

Chukwudi Nwachukwu ichux

🏠
Working from home
View GitHub Profile
@ichux
ichux / drop-triggers-functions.sql
Last active September 19, 2018 09:13
single call to drop specific triggers and functions in Postgres
-- get functions
SELECT 'DROP FUNCTION IF EXISTS ' || ROUTINE_NAME || ' CASCADE;'
FROM information_schema.routines
WHERE routine_type = 'FUNCTION'
AND specific_schema = 'public'
AND ROUTINE_NAME IN ('ichux')
UNION
-- get triggers
SELECT 'DROP TRIGGER IF EXISTS ' || TRIGGER_NAME || ' ON ' || event_object_table || ';'
FROM information_schema.triggers
@ichux
ichux / 1-get-functions.sql
Last active September 19, 2018 09:28
get all the triggers declared on a postgres table
SELECT routine_name FROM information_schema.routines
WHERE routine_type='FUNCTION' AND specific_schema='public' ORDER BY routine_name
@ichux
ichux / first_and_last_day.sql
Last active September 22, 2018 20:02
Get the first and last date of the present month in Postgres
WITH first_day AS (SELECT date_trunc('MONTH', NOW()) :: DATE),
last_day AS (SELECT (date_trunc('MONTH', (SELECT * FROM first_day)) + INTERVAL '1 MONTH' -
INTERVAL '1 DAY') :: DATE)
SELECT first_day.*, last_day.*
FROM first_day,
last_day;
@ichux
ichux / list_months.sql
Created October 2, 2018 03:14
lists all the months in a given year interval et al
SELECT month_day1 :: DATE AS month_starts,
(month_day1 + INTERVAL '1 month' - INTERVAL '1 day') :: DATE AS month_ends,
(month_day1 + INTERVAL '1 month') :: DATE AS next_month_starts,
(month_day1 + INTERVAL '1 month') :: DATE - month_day1 :: DATE AS days
FROM generate_series(DATE '2018-01-01', DATE '2018-12-01', INTERVAL '1 month') AS month_day1;
@ichux
ichux / first_last.sql
Created October 2, 2018 03:15
row_to_json to get all the first and last days of the current month
WITH first_day AS (SELECT date_trunc('MONTH', NOW()) :: DATE AS first_date),
last_day AS (SELECT (date_trunc('MONTH', (SELECT * FROM first_day)) + INTERVAL '1 MONTH' -
INTERVAL '1 DAY') :: DATE AS last_date)
SELECT row_to_json(first_last)
FROM (SELECT first_day.*, last_day.*
FROM first_day,
last_day) first_last;
@ichux
ichux / changes.sh
Last active November 4, 2018 20:29
Change files permission on Mac
stat -f "%Lp" ~/Downloads/Visual_Debugging.mp4
chmod 644 from step 1
find . -iname '*.mp4' -type f -exec chmod 644 {} \;
@ichux
ichux / sm25.py
Last active November 5, 2018 09:32
send localmails
import email.utils
import smtplib
from email.mime.text import MIMEText
# Create the message
msg = MIMEText('Hello SMTPD!')
msg['To'] = email.utils.formataddr(("Local Mail", "localmail@localhost"))
msg['From'] = email.utils.formataddr(('Chukwudi Nwachukwu', 'chukwudinwachukwu@localhost'))
msg['Subject'] = 'Local mail using SMTP'
@ichux
ichux / douploads.py
Created November 6, 2018 11:26
The file that receives the upload
from flask import Flask, render_template, request, redirect, url_for
from werkzeug import secure_filename
app = Flask(__name__)
@app.route('/')
def index():
return render_template('index.html')
@ichux
ichux / dynamic.js
Created January 2, 2019 11:49
remove dynamic ids
let interates = document.querySelectorAll('div[id^=epom-]');
for (let count = 0; count < interates.length; count++) {
interates[count].innerHTML='';
}
@ichux
ichux / breakdown.py
Created October 27, 2019 09:32
breakdown into individual component
import re
text = "This is a whole new chapter in this coding skill set. And I do hope if turns out well"
breakdown = {}
for word in re.sub('\W', ' ', text).split():
breakdown[word] = breakdown.get(word, 0) + 1