Skip to content

Instantly share code, notes, and snippets.

View Nocks's full-sized avatar
🌍
Working remotely

Enock Kwesi Addey Nocks

🌍
Working remotely
View GitHub Profile
@Nocks
Nocks / workbook.md
Created March 21, 2022 00:06 — forked from leisurelicht/workbook.md
Export queryset to Excel workbook
from django.http import HttpResponse
from .utils import queryset_to_workbook

def download_workbook(request):
    queryset = User.objects.all()
    columns = (
        'first_name',
        'last_name',
        'email',
@Nocks
Nocks / weasyprint_complex_headers.py
Created September 22, 2021 03:34 — forked from pikhovkin/weasyprint_complex_headers.py
Repeat on each page of complex headers (eg, tables) except the first page
# coding: utf-8
from weasyprint import HTML, CSS
def get_page_body(boxes):
for box in boxes:
if box.element_tag == 'body':
return box
@Nocks
Nocks / install virtualenv ubuntu 16.04.md
Created March 16, 2021 15:02 — forked from Geoyi/install virtualenv ubuntu 16.04.md
How to install virtual environment on ubuntu 16.04

How to install virtualenv:

Install pip first

sudo apt-get install python3-pip

Then install virtualenv using pip3

sudo pip3 install virtualenv 
/*
How much money each staff has processed to date?
*/
SELECT DISTINCT subquery.staff_id, subquery.staff,
SUM(subquery.payment_amount) OVER(PARTITION BY subquery.staff) AS total_amt_received
FROM (
SELECT staff.staff_id staff_id,
CONCAT(staff.first_name, ' ', staff.last_name) AS staff,
payment.amount payment_amount, payment.payment_date payment_date
/*
What are the top 10 film categories where most money have been received?
*/
SELECT DISTINCT category.category_id,
category.name category,
COUNT(category) OVER(PARTITION BY category) AS rental_count,
ROUND(AVG(payment.amount) OVER(PARTITION BY category), 2) AS avg_amt_received,
SUM(payment.amount) OVER(PARTITION BY category) AS total_amt_received
FROM film
/*
Who are the top 5 active customers who have spent most in renting films?
*/
SELECT DISTINCT customer.customer_id, CONCAT(first_name, ' ', last_name) AS customer,
SUM(payment.amount) OVER(PARTITION BY customer) AS total_amt_spent
FROM customer
JOIN payment
ON customer.customer_id = payment.customer_id
WHERE customer.active = 1
/*
What are the top 10 most rented travel films in 2005 of over two hours duration?
*/
SELECT DISTINCT subquery.film_id, subquery.title,
subquery.category,
COUNT(subquery.title) OVER(PARTITION BY subquery.title) AS rental_count
FROM (
SELECT film.film_id film_id, film.title title,
category.name category,
* { background-color: rgba(255,0,0,.2); }
* * { background-color: rgba(0,255,0,.2); }
* * * { background-color: rgba(0,0,255,.2); }
* * * * { background-color: rgba(255,0,255,.2); }
* * * * * { background-color: rgba(0,255,255,.2); }
* * * * * * { background-color: rgba(255,255,0,.2); }
* * * * * * * { background-color: rgba(255,0,0,.2); }
* * * * * * * * { background-color: rgba(0,255,0,.2); }
* * * * * * * * * { background-color: rgba(0,0,255,.2); }
@Nocks
Nocks / media-query.css
Created August 27, 2019 00:20 — forked from gokulkrishh/media-query.css
CSS Media Queries for Desktop, Tablet, Mobile.
/*
##Device = Desktops
##Screen = 1281px to higher resolution desktops
*/
@media (min-width: 1281px) {
//CSS
@Nocks
Nocks / build_triangle.js
Created August 16, 2019 09:50
For this quiz, you're going to create a function called buildTriangle() that will accept an input (the triangle at its widest width) and will return the string representation of a triangle.
/*
* Programming Quiz: Build A Triangle (5-3)
*/
// creates a line of * for a given length
function makeLine(length) {
var line = "";
for (var j = 1; j <= length; j++) {
line += "* ";
}