Skip to content

Instantly share code, notes, and snippets.

View lalbuquerque's full-sized avatar

Lucas Albuquerque lalbuquerque

View GitHub Profile
@doc """
Breaks a pipeline expression into a list.
The AST for a pipeline (a sequence of applications of `|>`) is similar to the
AST of a sequence of binary operators or function applications: the top-level
expression is the right-most `:|>` (which is the last one to be executed), and
its left-hand and right-hand sides are its arguments:
quote do: 100 |> div(5) |> div(2)
#=> {:|>, _, [arg1, arg2]}
In the example above, the `|>` pipe is the right-most pipe; `arg1` is the AST
for `100 |> div(5)`, and `arg2` is the AST for `div(2)`.
@doc """
Pipe operator.
This operator introduces the expression on the left-hand side as
the first argument to the function call on the right-hand side.
## Examples
iex> [1, [2], 3] |> List.flatten()
[1, 2, 3]
The example above is the same as calling `List.flatten([1, [2], 3])`.
The `|>` operator is mostly useful when there is a desire to execute a series
of operations resembling a pipeline:
@lalbuquerque
lalbuquerque / AppDataCleaner.java
Last active March 13, 2016 22:46
An util class for cleaning app data before running an Android automated test
public class AppDataCleaner {
public static void clearApplicationData(Context context) {
File cache = new File(context.getFilesDir().getAbsolutePath());
File appDir = new File(cache.getParent());
if (appDir != null && appDir.exists()) {
String[] children = appDir.list();
for (String s : children) {
if (s.equals("shared_prefs")) {
clearSharedPreferences(new File(appDir, s), context);
@lalbuquerque
lalbuquerque / LocationHandler
Last active April 22, 2016 16:08
Try to get location by GPS first and then, if it is disabled, by Network
private Location getLocation(){
long MIN_DISTANCE_CHANGE_FOR_UPDATES = 10L;
long MIN_TIME_BW_UPDATES = 1;
Location location;
try {
mLocationManager = (LocationManager) mContext.getSystemService(Context.LOCATION_SERVICE);
boolean isGPSEnabled = mLocationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
@lalbuquerque
lalbuquerque / build.gradle
Last active March 8, 2016 14:15
Add Espresso dependencies to your project with separated dependencies file :)
testCompile testDependencies.junit
testCompile testDependencies.hamcrest
//Provides AndroidJUnitRunner
androidTestCompile (testDependencies.runner) {
exclude group: 'com.android.support', module: 'appcompat'
exclude group: 'com.android.support', module: 'support-v4'
exclude module: 'recyclerview-v7'
exclude module: 'support-annotations'
}
/**
* As we use app compat it seems Solo#setNavigationDrawer is not doing well (drawer does not open, but the button is clicked)
* Same result for clickOnView(getView(android.R.id.home))
*
* This code opens the navigation drawer on the main thread
* Be aware : you need to provide your DrawerLayout id (you can do it in params)
*/
public void openCompatNavigationDrawer() {
getInstrumentation().runOnMainSync(new Runnable() {
@Override