Skip to content

Instantly share code, notes, and snippets.

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

J. Fernando Sánchez balkian

🏠
Working from home
View GitHub Profile
import pymongo
import logging
import sys
from sqlalchemy.exc import IntegrityError
from pymongo import MongoClient
from tweeply.models import TweeplyMessage, Credential, User, Database
from tweeply.utils import update_config
logging.basicConfig()
logger = logging.getLogger(__name__)
@balkian
balkian / progres.py
Created April 16, 2015 17:25
Print progress in python
import sys
# \r is carriage return, writes the following text to the beginning of the line
sys.stdout.write('\r<And your message>')
SELECT count(*) AS C, payload->'retweeted_status'->>'id' AS cat, payload->'retweeted_status'->>'text' AS Tweet FROM messages WHERE jsonb_typeof(payload) = 'object' and payload->>'text' not like '%http%' GROUP BY cat, Tweet ORDER BY C DESC;
# Works just fine
SELECT count(*) AS C, payload->'retweeted_status'->>'id' AS cat, payload->'retweeted_status'->>'text' AS Tweet, payload->'retweeted_status'->'User'->>'screen_name' AS User FROM messages WHERE jsonb_typeof(payload) = 'object' and payload->>'text' not like '%http%' GROUP BY cat, Tweet, User ORDER BY C DESC;
# Doesn't work
# ------------
# ERROR: column "messages.payload" must appear in the GROUP BY clause or be used in an aggregate function
# LINE 1: ...t, payload->'retweeted_status'->>'text' AS Tweet, payload->'...
@balkian
balkian / convert
Created April 13, 2015 19:09
convert json to jsonb in postgres
alter table t alter column j type jsonb using j::text::jsonb;
mashable big_picture theonion time breakingnews bbcbreaking espn harvardbiz gizmodo techcrunch wired smashingmag wsj whitehouse rollingstone cnn whitehouse tweetmeme peoplemag foxnews huffingtonpost newsweek slate reuters incmagazine eonline usatoday good gawker msnbc_breaking life latimes telegraphnews abc7 bbc_world washingtonpost msnbc guardiannews
FROM ubuntu:14.04
RUN apt-get update -y
RUN apt-get install -y curl
RUN apt-get install -y diffstat
RUN apt-get install -y git
RUN apt-get install -y python
RUN apt-get install -y python3
RUN apt-get install -y tmux
RUN apt-get install -y vim
{% set f=open_file("xls") %}
{% set sheet=f.sheet_by_index(0) %}
{% if not baseuri %}
{% set baseuri="default" %}
{% endif %}
{
"@context": [
"http://demos.gsi.dit.upm.es/eurosentiment/static/context.jsonld",
{
"@base": "{{ baseuri }}",
@balkian
balkian / Makefile
Last active August 29, 2015 14:17
Some automation to submit to a journal (e.g. Elsevier). It detects the main latex file and eps files used.
# Some automation to submit to a journal (e.g. Elsevier).
# It detects the main latex file and eps files used.
# Author: @balkian
# TODO: Only import the tex files used in the main file, and their images.
AUX_DIR=.aux
LATEX=$(basename $(shell grep -l '\\begin{document' *.tex))
LETTER=letter
COVER=cover
HIGHLIGHTS=highlights
@balkian
balkian / kemsirve.py
Last active September 19, 2015 12:17
Get a notification when a kemsirve/kimsufi server is available
from __future__ import print_function
import requests
try:
import Tkinter as tk
import tkMessageBox as tkm
except Exception:
import tkinter as tk
from tkinter import messagebox as tkm
@balkian
balkian / tweeply.py
Created March 18, 2015 23:25
Python property that mirrors the content of a dictionary. To convenienty add to a subclass of dict and then do: my_object.my_property
class MessageProperty(property):
def __init__(self, path, *args, **kwargs):
property.__init__(self, *args, **kwargs)
self.path = path
def _target(self, dic):
path = self.path
dest = dic
lastkey = path[-1]
for p in path[:-1]: