Skip to content

Instantly share code, notes, and snippets.

@flavioamieiro
flavioamieiro / get_wordcloud.py
Created August 20, 2014 01:10
Get wordcloud from a document in PyPLN
#!/usr/bin/env python2
# just give this script a document id (as in `$ python get_wordcloud.py 1`, for example)
# and it will download the wordcloud from PyPLN.
#
# Replace PYPLN_URL by the desired host.
import base64
import sys
import pypln.api
@flavioamieiro
flavioamieiro / netvibes_unread_sidebar.js
Created August 27, 2014 19:56
Shows only feeds with unread items in netvibes' sidebar
window.setInterval( function() {
Array.prototype.slice.call(document.getElementsByClassName('nv-treeview-feed'), 0).map(
function (el, idx, arr) {
// if you're running on chromium you may need to use innerText
if (el.children[0].children[2].innerHTML == 0) {
el.hidden = true;
} else {
el.hidden = false;
}
}
@flavioamieiro
flavioamieiro / firefox_url_extractor.py
Last active August 29, 2015 14:16
This script gets urls from tabs in a firefox session.
#!/usr/bin/env python3
import json
def get_session_from_file(filename):
with open(filename, 'r') as fp:
session = json.load(fp)
return session
def get_tabs_from_session(session):
return session['windows'][0]['tabs']
[2015-06-25 18:20:55,521: ERROR/MainProcess] Task pypln.backend.workers.elastic_indexer.ElasticIndexer[76b5682a-660b-480f-b533-48f619246362] raised unexpected: SerializationError({u'mimetype': 'application/pdf', u'upload_date': datetime.datetime(2015, 6, 25, 16, 20, 54, 169000), u'forced_decoding': False, u'language': 'un', u'text': u'This is a minimal pdf.\n1', u'filename': u'minimal_pdf.pdf_1435249254.17', u'length': 12876, u'file_id': '558c2a66798ebd634b0b249f', u'file_metadata': {'UserProperties': 'no', 'Tagged': 'no', 'Form': 'none', 'Producer': 'pdfTeX-1.40.15', 'Creator': 'TeX', 'Encrypted': 'no', 'JavaScript': 'no', 'Suspects': 'no', 'Optimized': 'no', 'PDF version': '1.5', 'ModDate': 'Thu Jun 25 18:17:25 2015', 'Page size': '612 x 792 pts (letter)', 'CreationDate': 'Thu Jun 25 18:17:25 2015', 'Pages': '1', 'Page rot': '0'}, u'contents': '%PDF-1.5\n%\xd0\xd4\xc5\xd8\n3 0 obj\n<<\n/Length 105 \n/Filter /FlateDecode\n>>\nstream\nx\xda%\x8c\xbb\n\x800\x0c\x00\xf7~E\xc6vh$\xe9{\x15tp\xce&\x0e\x82\x8
@flavioamieiro
flavioamieiro / tasks.py
Created July 24, 2015 12:37
Send documents to pypln with celery
import glob
from celery import Celery
import pymongo
import pypln.api
import settings
app = Celery('tasks', backend="mongodb")
client = pymongo.MongoClient()
database = client["send_to_pypln"]
int ledPin = 13;
int fib(int n){
return (n <= 1) ? 1 : (fib(n-1) + fib(n-2));
}
void blink(int interval){
digitalWrite(ledPin, HIGH);
delay(interval);
digitalWrite(ledPin, LOW);
# Implementation of the sieve of Eratostenes.
# Calculates all the prime numbers in a range up to the specified limit.
import math
import sys
def process(squareRoot, list):
"""This function calculates all the prime numbers in a range (from 2 to the
limit you specify).
Takes as arguments:
squareRoot - the square root of the highest number rounded down
#!/usr/bin/python
import math
import sys
def is_prime(n):
"""
Tells if a number is a prime
This uses the fact that prime numbers greater than 2 and 3 can always
be written in the form 6k+1 or 6k-1. That is, they are always 'next'
@flavioamieiro
flavioamieiro / tweet.py
Created March 20, 2012 03:08
Script para buscar o título da página e formatar um tweet
#!/usr/bin/python3
#-*- coding: utf-8 -*-
import sys
import re
import urllib.request
from html.parser import HTMLParser
def usage():
sys.stderr.write("usage: {0} <url>\n".format(sys.argv[0]))
@flavioamieiro
flavioamieiro / gist:3603445
Created September 2, 2012 19:17
Imprime total linhas nos arquivos de cada diretório a partir do atual.
find . -type d | while read DIR
do
echo "$DIR"
find "$DIR" -maxdepth 1 -type f -exec wc -l {} \; | awk '{loc += $1} END {print loc}'
done