Skip to content

Instantly share code, notes, and snippets.

@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 / 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")
@carlosefonseca
carlosefonseca / Terminal-Pull DB from Android app.applescript
Last active December 17, 2015 02:59
Pull Android app's database file from device to computer and open. Different versions for iTerm and Terminal. You can use it by running the command line "osascript pathtoscript.scpt packagename dbfilename.db" (make an alias for it) or by setting the properties on the top of the file and saving the script as an app.
(*
Pull Android app's database file from device to computer and open. Terminal version.
You can use it by running the command line
osascript pathtoscript.scpt packagename dbfilename.db
(make an alias for it) or by setting the properties on the top of the file and saving as an app.
*)
property package : "pt.company.app"
property dbname : "databasename.db"
@carlosefonseca
carlosefonseca / IdeaCommentsCommand.py
Created May 10, 2013 14:19
Comments a line and moves the cursor to the next line (only if no selection), just like InteliJ IDEA.
import sublime, sublime_plugin
class IdeaCommentCommand(sublime_plugin.TextCommand):
def run(self, edit):
self.view.run_command("toggle_comment")
if self.view.sel()[0].a == self.view.sel()[0].b:
(row,col) = self.view.rowcol(self.view.sel()[0].begin())
target = self.view.text_point(row+1, col)
self.view.sel().clear()
self.view.sel().add(sublime.Region(target))
@carlosefonseca
carlosefonseca / Append images
Last active December 18, 2015 00:29
Receives a couple images and creates a new one with the two images side by side. Automator > New service > Receive selected image files > Run shell script (Pass input as arguments)
/usr/local/bin/convert +append $1 $2 $(dirname $1)/merged.png
package pt.beware.remotelogging;
import android.content.Context;
import com.carlosefonseca.common.utils.CodeUtils;
import com.carlosefonseca.common.utils.Log;
import java.lang.reflect.Array;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
@carlosefonseca
carlosefonseca / ipaversion.sh
Last active December 27, 2015 12:39
Output the version and build of an iOS .ipa file.
#!/usr/bin/env bash
plist="/tmp/BAMInfo.plist"
zippath=`unzip -l $1 | egrep -o "Payload/.*app/Info.plist"`
unzip -p $1 $zippath > $plist
version=`/usr/libexec/PlistBuddy -c "Print CFBundleShortVersionString" $plist`
@carlosefonseca
carlosefonseca / Add lines as Reminders
Last active January 3, 2016 21:59
Add selected lines of text as new reminders. Asks for what list. Use as Automator service script. Requires http://applescript.bratis-lover.net/library/string/ to be a Script Library.
on run {input, parameters}
set input to (first item of input)
tell script "_string" to set input to trimBoth(input)
set lst to every paragraph of input
tell application "Reminders"
activate
set aList to (name of lists)
set theList to some list whose name is (first item of (choose from list aList))
@carlosefonseca
carlosefonseca / wkt2kml.py
Created September 17, 2013 22:58
Converts WKT to KML.
#!/usr/bin/env python
# coding=utf-8
import sys
import re
import simplekml
import argparse
import random
def splitByLines(wkt):
@carlosefonseca
carlosefonseca / json2gfmtable.py
Last active June 24, 2016 04:41
Creates a GitHub Flavored Markdown table from a JSON array passed to the stdin. Accepts a list of column names as the argument for column ordering and filtering.
#!/usr/bin/env python3
# coding=utf-8
import json
import sys
# only reads from stdin
j = json.loads(sys.stdin.read())
# reads a list of column names from the argument "col1,col2" etc