Skip to content

Instantly share code, notes, and snippets.

@carlosefonseca
carlosefonseca / mergecode.py
Created March 11, 2014 17:29
Adds code files into markdown
#!/usr/bin/env python3
# coding=utf-8
import sys
import re
import os
import shutil
if len(sys.argv) < 2:
@carlosefonseca
carlosefonseca / ArraysInsideDictionaries.swift
Created June 13, 2014 16:37
Demonstration of a difference in Swift's Arrays when compared to NS[Mutable]Arrays
// Playground - noun: a place where people can play
import UIKit
var d1 = Dictionary<String, NSMutableArray>()
var d2 = Dictionary<String, String[]>()
d1["A"] = NSMutableArray(object: "A1")
d1 // ["A": ["A1"]]
@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
//
// JKInterpolationMath.h
//
// Created by Carlos Fonseca on 08/11/15.
// Copyright © 2015 Carlos Fonseca. All rights reserved.
//
import Foundation
func JKLinearInterpolation(t:Float, start:Float, end:Float) -> Float
@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 / 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 / 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 {