Skip to content

Instantly share code, notes, and snippets.

@carlosefonseca
carlosefonseca / TweetNow
Created October 11, 2011 22:21
Automator service to tweet something from LaunchBar or something like it
Automator > Service
===================
* Put the code bellow inside a "Run Shell Script" action
** Change the paths to TTYtter and growl
** TTYtter: http://www.floodgap.com/software/ttytter/
** growl.sh: http://hints.macworld.com/dlfiles/growl_sh.txt
cat > ~/Library/Caches/tn.cache
AAA=`wc -m ~/Library/Caches/tn.cache | awk '{print $1}'`
@carlosefonseca
carlosefonseca / connectIM.scpt
Created September 26, 2012 20:31
Connects/Disconnects a certain IM account (like for work) on both Adium and Messages. A context-aware app runs the scripts automatically when I arrive at home/work
tell application "System Events"
if (name of processes) contains "Adium" then
tell application "Adium"
set acc to (some account whose name is "#####")
tell acc
set enabled to true
go online
end tell
end tell
@carlosefonseca
carlosefonseca / AppWrapperAppleScript.scptd
Created November 28, 2012 17:40
Concatenate Two iPhone 5 Images.
set theScript to quoted form of POSIX path of (path to resource "compositeImages.py" in directory "Scripts")
on open these_items
set theScript to quoted form of POSIX path of (path to resource "compositeImages.py" in directory "Scripts")
set f1 to (quoted form of POSIX path of (first item of these_items))
set f2 to (quoted form of POSIX path of (item 2 of these_items))
choose file name with prompt "Destination:" default name "Images.png" without invisibles
set theFile to quoted form of POSIX path of result
@carlosefonseca
carlosefonseca / kml_check_points.py
Created February 12, 2013 18:06
Given a KML with multiple point placemarks and a line at the end, compares all placemarks with the line and checks if the line contains a point that is close enough to each point. Returns a √ or an X for each placemark and the distance to the closest point on the line.
#!/usr/bin/python
# -*- coding: utf-8 -*-
import math
import sys
from bs4 import BeautifulSoup
def distance_on_unit_sphere(lat1, long1, lat2, long2):
# Convert latitude and longitude to
@carlosefonseca
carlosefonseca / kml_mergelines.py
Created February 12, 2013 18:11
Takes a KML with multiple LineString's and merges them into one, sequentially.
#!/usr/bin/env python
import codecs
from bs4 import BeautifulSoup
import sys
contents = open(sys.argv[1]).read()
soup = BeautifulSoup(contents, features="xml")
allLineStrings = soup.find_all("LineString")
@carlosefonseca
carlosefonseca / magicJSON.py
Last active December 15, 2015 12:49
Formats and orders the keys in JSON data. If input is stdin, it will colorize the data via pygmentize (if available) and output to stdout. --no-color can be passed as argument to skip pygmentize. If a path is passed as argument, it will override the file with a formated version.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import json
import codecs
import sys
import locale
from subprocess import Popen, PIPE, STDOUT
import argparse
package com.example.SectionedAdapterTest;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Adapter;
import android.widget.BaseAdapter;
import java.util.ArrayList;
import java.util.List;
abstract public class SectionedAdapter extends BaseAdapter {
@carlosefonseca
carlosefonseca / DownloadURL.java
Last active December 15, 2015 23:59
Dead simple async downloader of URLs to file or string, with support for shortened links, a progressdialog and a completion handler.
public static class DownloadResult {
public void onFile(String path) {};
public void onString(String string){};
public void onFail() {};
}
/**
* This class handles the download of stuff from the tubes.
* It's an extension of AsyncTask, so it will download asynchronously.
@carlosefonseca
carlosefonseca / 500pxStatusBoard.html
Last active July 31, 2016 09:20
Displays a 500px photo slideshow. Made for Panic's Status Board.
<!doctype html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>A 500px photo</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<style type="text/css">
img {
width: 100%
}
.photo, a.photo {
@carlosefonseca
carlosefonseca / Applescript code.applescript
Created April 30, 2013 12:29
Automator Service that receives Image files, asks for a width and resizes the image to that width, and resizes a copy of the original to the double of the entered width, saving this with a @2x sufix. Uses Acorn. Applescript appended for reading, .workflow appended for usage (open to install).
property enteredWidth : 0
property newPath : ""
on run {input, parameters}
repeat with fileAlias in input
try
display dialog "Enter width for 1x of " & (POSIX path of fileAlias) & ":" default answer ""
set dialogInfo to result
set enteredWidth to (text returned of dialogInfo as integer)
set the newPath to my replace_chars((POSIX path of fileAlias), ".png", "@2x.png")