Skip to content

Instantly share code, notes, and snippets.

View alcides's full-sized avatar

Alcides Fonseca alcides

View GitHub Profile
@alcides
alcides / screen_resolution.py
Created May 1, 2009 16:27
Get screen resolution
import sys,os
# Defaults
SCREEN_WIDTH=300
SCREEN_HEIGHT=300
if sys.platform == "win32":
# Windows sucks, but has an API
from win32api import GetSystemMetrics
Rede de Casa:
Router NetGear (ZON)
- Rede wireless (Phantasien)
- Macbook (Atreyu)
- Router Fonera
--- Rede wireless (IvoryTower)
------ Desktop (Bastian)
------ Disco Externo (Falkor)
class ReverseDict(object):
""" Creates a reverse dictionary, and keeps the connection. Only key access works. """
def __init__(self,dic):
self.dic = dic
def __getitem__(self,p):
for k in self.dic:
if self.dic[k] == p:
return k
# here we have a simple dictionary
SELECT tasks_after_deadline, tasks_open, tasks_after_deadline/tasks_open as ratio
FROM (
SELECT COUNT( * ) as tasks_after_deadline
FROM `gestor_actionitem`
WHERE `due_date` < NOW( )
AND `done` =0
LIMIT 0 , 30
)tab, (
SELECT COUNT( * ) as tasks_open
FROM `gestor_actionitem`
@alcides
alcides / mysql_to_sqlite3.sh
Created June 21, 2009 12:45
Script para converter um mysql dump numa base de dados SQLite3
#!/bin/sh
# MySQL dump to SQLite generator.
# Based on http://stackoverflow.com/questions/489277/script-to-convert-mysql-dump-sql-file-into-format-that-can-be-imported-into-sqlit
# Improved by Alcides Fonseca (http://alcidesfonseca.com)
if [ "x$1" == "x" ]; then
echo "Usage: $0 <dumpname>"
// Prototype extra javascript stuff
// http://alcides.ideias3.com
Position.GetWindowSize = function(w) {
var width, height;
w = w ? w : window;
this.width = w.innerWidth || (w.document.documentElement.clientWidth || w.document.body.clientWidth);
this.height = w.innerHeight || (w.document.documentElement.clientHeight || w.document.body.clientHeight);
return this;
I want to build a really simple script to use on Windows. I know
nothing about Windows programming.
Scenario:
I've got a shitty DSL line that doesn't have much bandwidth.
I want to prioritise certain applications. I've got some services
on my Linux box that I want to turn off when a user on a particular
Windows machine is running certain applications.
Plan:
import java.io._
import java.net.{URLConnection, URL}
import scala.xml._
val username = "alcides"
val password = "youwish"
val conn = new URL("http://twitter.com/statuses/friends_timeline.xml").openConnection
@alcides
alcides / layout.erb
Created August 14, 2009 21:19
Sinatra TLA
<% if @links != nil %>
<% if (@links != nil) && (@links["Link"] != nil) %>
<div class="adds">
Sponsored by:
<ul>
<% for link in @links["Link"] %>
<li><%= link["BeforeText"][0] %> <a href="<%= link["URL"][0] %>"><%= link["Text"][0] %></a> <%= link["AfterText"][0] %></li>
<% end %>
</ul>
</div>
#!/usr/bin/env python
# -*- coding: Latin-1 -*-
# importações gerais
import sys, Tkinter, thread, cgi, webbrowser
from os import curdir, sep
from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
# o programa pode ser chamado com um argumento que será a porta onde irá correr o servidor web.