Skip to content

Instantly share code, notes, and snippets.

@rcarmo
rcarmo / inbox.py
Created January 6, 2011 11:29
This snippet walks through your mailbox and tallies message sizes, flagged and unread status using the Python Scripting Bridge and Mail.app. It isn't speedy, but it appears to be light on system resources.
from ScriptingBridge import *
import os, sys, re
pattern = re.compile("^(INBOX|Sent*|Draft*)")
class Census:
"""Tallies mail info"""
def __init__(self, pattern):
self.app = SBApplication.applicationWithBundleIdentifier_("com.apple.mail")
self.accounts = dict([(a.name(),a) for a in self.app.accounts()])
@rcarmo
rcarmo / iPad-like CSS3 popup
Created April 12, 2011 16:41
a variation on Russell's iPad-like popup menu with a few gradient tweaks and a simple drop shadow
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>HTML5 iPad Popup Menu</title>
<meta name="viewport" content="width=device-width, maximum-scale=1.0" />
<style>
body{
@rcarmo
rcarmo / parser.py
Created April 19, 2011 22:01
A github RSS feed sanitizer
#!/usr/bin/env python
# encoding: utf-8
"""
parser.py
A github RSS feed sanitizer, whereby we mean "sane" - i.e., that groups updates
per project and not as a mess of completely unrelated events.
Created by Rui Carmo on 2011-01-06. Still incomplete.
@rcarmo
rcarmo / userContent.css
Created August 16, 2011 20:42
Custom ad blocking CSS
/*
* This file can be used to apply a style to all web pages you view
* Rules without !important are overruled by author rules if the
* author sets any. Rules with !important overrule author rules.
*/
/* You can find the latest version of this ad blocking css at:
* http://www.floppymoose.com
* hides many ads by preventing display of images that are inside
* links when the link HREF contans certain substrings.
@rcarmo
rcarmo / manifest.py
Created August 18, 2011 15:43
Generate an HTML5 manifest automatically with bottle.py
@route('/app.manifest')
def manifest():
""" Generate an HTML 5 offline manifest automatically """
last = 0
lines = []
response.content_type = "ext/cache-manifest"
for (path, dirs, files) in os.walk('app'):
last = max(max(map(lambda x: os.path.getmtime(os.path.join(path, x)), files)),last)
map(lambda x: lines.append(os.path.join(os.path.relpath(path,'app'), x)), filter(lambda x: os.path.splitext(x)[1] in ['.css','.js','.png'], files))
response.headers['Last-Modified'] = time.strftime("%a, %d %b %Y %H:%M:%S GMT", time.gmtime(last))
@rcarmo
rcarmo / archive-twitter.py
Created September 16, 2011 12:20
High-fidelity Twitter Archive (includes metadata and avatars)
#!/usr/bin/python
'''Dump'''
import os, sys, codecs, json, urllib, base64, gzip, datetime, time
import tweepy, session
attrs = {
'status': ['author', 'contributors', 'coordinates', 'created_at', 'favorited', 'geo', 'id', 'id_str', 'in_reply_to_screen_name', 'in_reply_to_status_id', 'in_reply_to_status_id_str', 'in_reply_to_user_id', 'in_reply_to_user_id_str', 'place', 'retweet_count', 'retweeted', 'source', 'source_url', 'text', 'truncated', 'user'],
'user': [ 'default_profile', 'default_profile_image', 'description', 'id', 'id_str','location', 'name', 'profile_image_url', 'protected', 'screen_name', 'time_zone', 'url', 'utc_offset', 'verified'],
@rcarmo
rcarmo / webkit-fs.py
Created September 20, 2011 16:48
Fullscreen webkit or PDF windows across any number of displays
from Quartz import *
from AppKit import *
from Foundation import *
import WebKit
import objc
import time
windows = {}
views = {}
@rcarmo
rcarmo / ansistrm.py
Created January 12, 2012 23:24 — forked from vsajip/ansistrm.py
Python logging: colourising terminal output
#
# Copyright (C) 2010, 2011 Vinay Sajip. All rights reserved.
#
import logging
import os
class ColorizingStreamHandler(logging.StreamHandler):
# color names to indices
color_map = {
'black': 0,
@rcarmo
rcarmo / wasabi.php
Created February 8, 2012 15:01
O Tal Canal
<?php
echo "<pre>
Adoro a tua luz, a tua cor, o teu sinal
Mas o que mais adoro em ti é o Tal Canal
Adoro a tua voz, a tua escrita, a tua oral
Mas o que mais adoro em ti é o Tal Canal
Adoro o teu olhar, teu gaguejar, teu ar fatal
Mas o que mais adoro em ti é o Tal Canal
Adoro a tua grelha, a tua taxa, o teu jornal
@rcarmo
rcarmo / Tweet.scpt
Created March 14, 2012 15:04
Tweet the current playing track in iTunes, complete with Grooveshark URL (use as Quicksilver trigger)
-- get properties of the playing track
tell application "iTunes"
set thisTrack to current track
set trackAlbum to the album of thisTrack
set trackYear to the year of thisTrack
set trackName to the name of thisTrack
set trackArtist to the artist of thisTrack
end tell
--
-- change the status message to your liking here: