Skip to content

Instantly share code, notes, and snippets.

View wsantos's full-sized avatar

Waldecir Santos wsantos

View GitHub Profile
@wsantos
wsantos / main.js
Created April 11, 2024 22:03 — forked from kdzwinel/main.js
List all undefined CSS classes
/*
This script attempts to identify all CSS classes mentioned in HTML but not defined in the stylesheets.
In order to use it, just run it in the DevTools console (or add it to DevTools Snippets and run it from there).
Note that this script requires browser to support `fetch` and some ES6 features (fat arrow, Promises, Array.from, Set). You can transpile it to ES5 here: https://babeljs.io/repl/ .
Known limitations:
- it won't be able to take into account some external stylesheets (if CORS isn't set up)
- it will produce false negatives for classes that are mentioned in the comments.
@wsantos
wsantos / migratemigrations2django2.py
Created February 27, 2021 09:30 — forked from benjaoming/migratemigrations2django2.py
Adds required keyword on_delete to ForeignKey and OneToOneField in Django migrations
#!/usr/bin/python3
"""
This script adds on_delete to Django migrations. It works on multi-line
definitions of ForeignKey/OneToOneField which may be in your codebase if you
have black'ened the migration files.
It's not perfect, but it doesn't create syntax errors and you can run black on
the code again afterwards.
First version:
@wsantos
wsantos / gist:8afe5b80a524e9af1d4b26bcf9b41ed8
Created May 21, 2018 15:16 — forked from hest/gist:8798884
Fast SQLAlchemy counting (avoid query.count() subquery)
def get_count(q):
count_q = q.statement.with_only_columns([func.count()]).order_by(None)
count = q.session.execute(count_q).scalar()
return count
q = session.query(TestModel).filter(...).order_by(...)
# Slow: SELECT COUNT(*) FROM (SELECT ... FROM TestModel WHERE ...) ...
print q.count()
@wsantos
wsantos / gist:3179221
Created July 25, 2012 22:55 — forked from pithyless/gist:1208841
Install Python 2.7 (homebrew + pip + virtualenv) on Mac OS X Lion

Install Python

$ brew install readline sqlite gdbm
$ brew install python --universal --framework
$ python --version
Python 2.7

Symlinks...