Skip to content

Instantly share code, notes, and snippets.

View wsantos's full-sized avatar

Waldecir Santos wsantos

View GitHub Profile
@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...

@wsantos
wsantos / gist:3229755
Created August 1, 2012 18:52
Export direct from mysql console to csv
# Export
SELECT id, field1, field2, field3
INTO OUTFILE '/tmp/data.csv'
FIELDS TERMINATED BY ','
OPTIONALLY ENCLOSED BY '"'
ESCAPED BY '\\'
LINES TERMINATED BY '\n'
FROM data_table
WHERE field1 = 0;
@wsantos
wsantos / robot.js
Created December 10, 2012 23:37
Blackwin
//FightCode can only understand your robot
//if its class is called Robot
var Robot = function(robot) {
};
Robot.prototype.onIdle = function(ev) {
var robot = ev.robot;
robot.ahead(100);
@wsantos
wsantos / gist:5689075
Last active December 17, 2015 23:29
Future study - refactore
import tornado.auth
from tornado import httpclient
from tornado import httputil
from tornado.httputil import url_concat
from tornado.options import options
from tornado import escape
from tornado.concurrent import Future
from tornado import gen
import logging
import urllib
@wsantos
wsantos / gist:5796726
Created June 17, 2013 13:07
Twitter Tornado sample
class AuthTwitterLoginHandler(LoginHandler, tornado.auth.TwitterMixin):
@tornado.web.asynchronous
@gen.engine
def get(self):
my_url = (self.request.protocol + "://" + self.request.host +
"/auth/twitter?next=" +
tornado.escape.url_escape(self.get_argument("next", "/")))
if self.get_argument("oauth_token", None):
user = yield gen.Task(self.get_authenticated_user)
@wsantos
wsantos / gist:303c541cb18557702862
Created August 21, 2014 22:42
Body processor.
class RequestHandler
@processed_body.setter
def processed_body(self, value):
self._processed_body = value
@property
def processed_body(self):
if not hasattr(self, "_processed_body"):
self._processed_body = self.get_processed_body()
@wsantos
wsantos / gist:ef0f3ab3a5dabbfbc2ff
Created July 28, 2015 21:59
delete merged branches - remote
git branch -r --merged | ⏎ ✭ ✱ ◼
awk -F'/' '/^ *origin/{if(!match($0, /(>|master)/)){print $2}}' |
xargs git push origin --delete
@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 / 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 / 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.