Skip to content

Instantly share code, notes, and snippets.

View gonz's full-sized avatar

Gonz Saavedra gonz

  • Montevideo, Uruguay
View GitHub Profile
@gonz
gonz / sort.js
Created December 22, 2015 20:44
JS sort
function getSortedIndexes(table) {
var indexes = [];
for (var i = 0; i < table.headers.length; i += 1) {
indexes.push(i);
}
return indexes.sort((function (t) {
return function (a, b) {
@gonz
gonz / gist:ceb549e495c7f4d1d74b
Created February 3, 2015 15:20
Pipeline JSON
var prototype1 = {
"version": "0.1",
"return": "result",
"steps": [{
"for_each": {
"items": "std", // FIXME
"for_each_item": [{
"classify": {
"module_id": "cl_8naYeRdA",
"text": "item",
# -*- coding: utf-8 -*-
from __future__ import print_function
import sys
import os
from os.path import join, abspath
import shutil
sourcedir = abspath(sys.argv[1])
@gonz
gonz / gist:10044002
Created April 7, 2014 20:16
MultiSerializerViewSetMixin
class MultiSerializerViewSetMixin(object):
def get_serializer_class(self):
"""
Look for serializer class in self.serializer_action_classes, which
should be a dict mapping action name (key) to serializer class (value),
i.e.:
class MyViewSet(ViewSet):
serializer_class = MyDefaultSerializer
serializer_action_classes = {
@gonz
gonz / run_local_ansible.sh
Created December 19, 2013 16:53
Run ansible locally vagrant provisioner
#!/bin/sh
set -e
if [ ! -f /usr/local/bin/ansible-playbook ]
then
sudo apt-get update
sudo apt-get -y install python-setuptools python-dev
sudo easy_install pip
sudo pip install ansible
fi
ansible-playbook /vagrant/provisioning/vagrant.yml -i /vagrant/provisioning/development --connection=local
@gonz
gonz / gist:8008641
Created December 17, 2013 17:12
iterator split_every
def split_every(n, iterable):
i = iter(iterable)
piece = list(islice(i, n))
while piece:
yield piece
piece = list(islice(i, n))
@gonz
gonz / fix_django_params.py
Created November 21, 2013 21:30
In django PUT and DELETE request doesn't get from params parsed in django, IMO they should be handled exaclty like a POST request and end up in request.POST (yes I know it's a bad name...). request.GET stores query/url params and request.POST form/body params.
"""
In django PUT and DELETE request doesn't get from params parsed in django, IMO
they should be handled exaclty like a POST request and end up in request.POST
(yes I know it's a bad name...).
request.GET stores query/url params and request.POST form/body params.
"""
from django.http import QueryDict
@gonz
gonz / scrapy.py
Last active December 27, 2015 02:49
from twisted.internet import reactor
from scrapy.crawler import Crawler
from scrapy.settings import CrawlerSettings
from scrapy import log as scrapy_log, signals
def _start_crawling(spider, log_level='INFO'):
crawler = Crawler(CrawlerSettings(settings))
crawler.configure()
crawler.crawl(spider)
@gonz
gonz / db.yml
Created October 30, 2013 17:41
- name: Update default locale to 'en_US.utf8'
command: update-locale LC_ALL="en_US.utf8"
sudo: True
- name: Install db packages
apt: pkg=$item state=installed
with_items:
- postgresql-9.1
- postgresql-contrib-9.1
- postgresql-server-dev-9.1
@gonz
gonz / gist:6156840
Created August 5, 2013 15:31
python/js flymake syntax check
(when (load "flymake" t)
;; python syntax check
(defun flymake-pyflakes-init ()
(let* ((temp-file (flymake-init-create-temp-buffer-copy
'flymake-create-temp-inplace))
(local-file (file-relative-name
temp-file
(file-name-directory buffer-file-name)))
(pycheck-bin (concat my-emacs-bin-directory