Skip to content

Instantly share code, notes, and snippets.

View aoriani's full-sized avatar

André Oriani aoriani

View GitHub Profile
@aoriani
aoriani / RangedInputFilter.java
Created September 5, 2013 02:30
An Android Input filter that validates the range of an input. The ones on stackoverflow does not seem to understand the meaning of the parameters of the filter method
class RangedInputFilter implements InputFilter {
private int fieldSize;
private int min, max;
RangedInputFilter(int fieldSize, int min, int max) {
this.fieldSize = fieldSize;
if (min > max) {
throw new IllegalArgumentException("Min value should be less or equal to max");
@aoriani
aoriani / gcparser.py
Created June 30, 2014 02:28
Parses GC entry in logcat to generate GC metrics for a process
#!/usr/bin/python
import json
import re
import sys
#TODO use raw strings
DALVIK_VM_LINE = re.compile("^.*/dalvikvm\(\s*(\d+)\)\s*:\s*(.*)$")
DALVIK_HEAP_GROW_LINE = re.compile("^.*/dalvikvm-heap\(\s*(\d+)\).*Grow\sheap.*$")
class GCStats:
@aoriani
aoriani / framer_cofeescript
Created July 13, 2015 08:59
Diego's frame.js cofeescript
# Set background
bg = new BackgroundLayer backgroundColor: "#f5f5f5"
bg.sendToBack()
# Variables
favIn = true
checkIn = true
collapsed = true
@aoriani
aoriani / tweet_ip.py
Created November 23, 2015 04:16
A simple python script that tweets the external public IP to a private Twitter account. The idea is to create an alternative to dynamic DNS services. In practice you only need the IP of your remote host. The script is going to be run daily by cron. The beauty of Twitter API is that it prevents duplicated message. Thus you will only get a new tw…
#!/usr/bin/env python
import sys
import tweepy
import urllib2
CONSUMER_KEY = "<your consumer key>"
CONSUMER_SECRET = "<your consumer secret>"
ACCESS_TOKEN = "<your access token>"
ACCESS_TOKEN_SECRET = "<your access secret>"
@aoriani
aoriani / basics.swift
Created January 12, 2016 07:34
Notes from Introduction to Swift - WWDC 2014
#!/usr/bin/env xcrun swift -i
//No, it doesn't compile
//Hello World
println("Hello Worl")
//Variables
var aInt: Int = 1
@aoriani
aoriani / REST.swift
Created February 6, 2016 03:33
Implementing get Requests with swift
//
// REST.swift
// CoconutTests
//
// Created by Andre Oriani on 2/5/16.
// Copyright © 2016 Walmartlabs. All rights reserved.
//
import Foundation
@aoriani
aoriani / BarcodeViewController.swift
Created February 29, 2016 02:43
A simple barcode implementation code snippet for iOS 9
//
// ViewController.swift
// BarcodeReader
//
// Created by Andre Oriani on 2/28/16.
// Copyright © 2016 Orion. All rights reserved.
//
import UIKit
import AVFoundation
@aoriani
aoriani / fix_photo_date.sh
Created May 2, 2016 05:03
Set the creation and modification date to reflect exif information
for a in *
do
date=$(exiftool -s -s -s -DateTimeOriginal ${a} |cut -d":" -f1,2,3,4 | tr -d ":" | tr -d " ")
touch -mt ${date} ${a}
touch -t ${date} ${a}
done
@aoriani
aoriani / ViewController.swift
Created January 17, 2017 08:54
Small example of property animations Raw
//
// ViewController.swift
// Animations
//
// Created by Andre Oriani on 1/16/17.
// Copyright © 2017 Orion. All rights reserved.
//
import UIKit
@aoriani
aoriani / TintBindingAdapter.java
Created January 9, 2018 22:04
Binding adapter to tint ImageViews
@SuppressLint("NewApi")
@BindingAdapter("android:tint")
public static void setTintCompat(ImageView imageView, @ColorInt int color) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
imageView.setImageTintList(android.databinding.adapters.Converters.convertColorToColorStateList(color));
} else {
final Drawable originalDrawable = imageView.getDrawable();
if (originalDrawable instanceof VectorDrawableCompat) {
VectorDrawableCompat vectorDrawableCompat = (VectorDrawableCompat) originalDrawable;
vectorDrawableCompat.setTint(color);