Skip to content

Instantly share code, notes, and snippets.

View aminelaadhari's full-sized avatar

Amine Laadhari aminelaadhari

  • thefabulous.co
View GitHub Profile
@keyboardr
keyboardr / HeadlessFragment.java
Last active December 31, 2021 01:05
A file template for creating a headless Fragment. The attach() methods add the fragment to the parent if it doesn't already exist and returns the attached fragment. The methods ensure that the parent implements the parent interface. If needed, parameters may be added to the attach() methods to supply fragment arguments.
#if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")package ${PACKAGE_NAME};#end
import android.app.Activity;
import android.app.Fragment;
import android.app.FragmentManager;
#parse("File Header.java")
public class ${NAME} extends Fragment {
private static final String FRAG_TAG = ${NAME}.class.getCanonicalName();
@billmote
billmote / MyApplication.java
Last active November 14, 2015 04:03
Enum variant to handle switching of environments. I had previously implemented PushConfig.java as an abstract class and had QaPushConfig.java and ProdPushConfig.java extend them, but that resulted in ugly switch-case logic everywhere I wanted to use them. Patrick refactored that implementation into what you see below.
public class MyApplication extends Application {
public static final PushConfig.Environment ENVIRONMENT = PushConfig.Environment.PROD; // can also be .QA
private static final String TAG = "MyApplication";
@Override
public void onCreate() {
super.onCreate();
final PushConfig pushConfig = ENVIRONMENT.getPushConfig();
String appId = pushConfig.etAppId;
@jorinvo
jorinvo / challenge.md
Last active April 21, 2023 17:14
This is a little challenge to find out which tools programmers use to get their everyday tasks done quickly.

You got your hands on some data that was leaked from a social network and you want to help the poor people.

Luckily you know a government service to automatically block a list of credit cards.

The service is a little old school though and you have to upload a CSV file in the exact format. The upload fails if the CSV file contains invalid data.

The CSV files should have two columns, Name and Credit Card. Also, it must be named after the following pattern:

YYYYMMDD.csv.

public class MyFragment {
boolean loaded;
private void maybeLoad() {
if (!loaded && getUserVisibleHint()) {
loaded = true;
loadMyData();
}
}
@Override
@JakeWharton
JakeWharton / build.gradle
Created March 29, 2015 06:34
A Gradle task for installing all application variants at once. Placed in the public domain.
def installAll = tasks.create('installAll')
installAll.description = 'Install all applications.'
android.applicationVariants.all { variant ->
installAll.dependsOn(variant.install)
// Ensure we end up in the same group as the other install tasks.
installAll.group = variant.install.group
}
@mpost
mpost / colors.xml
Last active January 8, 2020 02:09
This gist demonstrates how to create an animated pause/resume media playback button for Android. It uses animated vector drawables and state transitions to orchestrate the effect. Some background: https://plus.google.com/u/0/+MoritzPost/posts/3EFF8uC7jXv
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="action_pause">#FF8F00</color>
<color name="action_resume">#43A047</color>
</resources>
@bobylito
bobylito / import.js
Created March 22, 2015 11:18
Import data to Algolia with Node.js streams.
// npm install agentkeepalive batch-stream csv-parse stream-transform
var HttpsAgent = require('agentkeepalive').HttpsAgent;
var Algolia = require('algolia-search');
var stream = require( 'stream' );
var parse = require('csv-parse');
var fs = require('fs')
var transform = require('stream-transform');
var Batch = require( 'batch-stream' );
@nickbutcher
nickbutcher / 1 search_bar.xml
Last active March 26, 2022 10:03
Demonstrating morphing a search icon into a search field. To do this we use an AnimatedVectorDrawable (https://developer.android.com/reference/android/graphics/drawable/AnimatedVectorDrawable.html) made up of two paths. The first is the search icon (as a single line) the second is the horizontal bar. We then animate the 'trimPathStart' property …
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2015 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
@bryanstern
bryanstern / OkHttpStack.java
Last active April 24, 2022 03:17
An OkHttp backed HttpStack for Volley
/**
* The MIT License (MIT)
*
* Copyright (c) 2015 Circle Internet Financial
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
@shkschneider
shkschneider / Log
Last active November 21, 2021 03:51
Android Log helper (automatic class, method and line) replacing android.util.Log
package me.shkschneider.skeleton.helper;
import android.text.TextUtils;
import android.util.Log;
/**
* Improved android.util.Log.
*
* Logs class and method automatically:
* [MyApplication onCreate():34] Hello, world!