Skip to content

Instantly share code, notes, and snippets.

View frankiesardo's full-sized avatar

Francesco Sardo frankiesardo

View GitHub Profile
(require '[clojure.java.shell :as shell]
'[clojure.string :as str])
(defn- current-tag []
(let [{:keys [exit out]} (shell/sh "git" "describe" "--tags")]
(when (zero? exit)
(str/trim out))))
(def version
(if-let [tag (current-tag)]
@frankiesardo
frankiesardo / QuickReturn.java
Last active December 14, 2015 22:49
A refactored version of LarsWerkman's QuickReturnListView. It should provide an easier to use API and an easier to understand library.
public class QuickReturn {
private final static int ANIMATION_DURATION_MILLIS = 250;
private final ListView listView;
private final View quickReturnView;
private final View headerPlaceholder;
private int itemCount;
private int itemOffsetY[];
@frankiesardo
frankiesardo / NetworkButton.java
Last active December 18, 2015 18:18
An Android Button that automatically enables itself when the internet connectivity is on and disables when is off.
public class NetworkButton extends Button {
// See Otto's sample application for how BusProvider works. Any mechanism
// for getting a singleton instance will work.
Bus bus = BusProvider.get();
public NetworkButton(Context context, AttributeSet attrs) {
super(context, attrs);
}
@frankiesardo
frankiesardo / Icicle.java
Last active December 20, 2015 23:08
Annotation Processing and Code Generation
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.SOURCE)
public @interface Icicle { }
public void process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
for (TypeElement annotation : annotations) {
Set<? extends Element> elements = roundEnv.getElementsAnnotatedWith(annotation);
}
}
apply plugin: 'java'
apply plugin: 'idea'
configurations {
provided
}
idea.module {
scopes.PROVIDED.plus += configurations.provided
}
Element fieldParentClass = element.getEnclosingElement();
Name fieldName = element.getSimpleName();
TypeMirror fieldType = element.asType();
for (Map.Entry<TypeElement, Set<? extends Element>> entry : elementsByContainingClass.entrySet()) {
generateHelperWithClass(entry.getKey()).andElements(entry.getValue());
}
if (element.getModifiers().contains(Modifier.FINAL) ||
element.getModifiers().contains(Modifier.STATIC) ||
element.getModifiers().contains(Modifier.PRIVATE)) {
error(element, "Field must not be private, static or final");
}
Class<?> helper = Class.forName(helperClassName);
Method helperMethod = helper.getMethod(methodName, classOfTheObjectToHelp, Bundle.class);
helperMethod.invoke(null, objectToHelp, bundle);