Skip to content

Instantly share code, notes, and snippets.

@chemouna
chemouna / RecyclerViewAssertions.java
Last active November 19, 2021 07:16
Some assertions to help with testing recyclerview with espresso.
import android.support.test.espresso.NoMatchingViewException;
import android.support.test.espresso.ViewAssertion;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import com.google.common.truth.Truth;
import java.util.ArrayList;
import org.hamcrest.Matcher;
import org.junit.Assert;
@dsernst
dsernst / comparing-git-add-all.md
Last active January 25, 2024 17:00
Compare `git add .` vs `git add -A`

git add . vs git add -A

Both of these will stage all files, including new files (which git commit -a misses) and deleted files.

The difference is that git add -A also stages files in higher directories that still belong to the same git repository. Here's an example:

/my-repo
  .git/
 subfolder/
@antoniolg
antoniolg / HomeActivity.kt
Last active April 11, 2024 11:03
Snackbar extensions on Kotlin, to create a useful small DSL.
class HomeActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_home)
setSupportActionBar(toolbar)
fab.setOnClickListener {
it.snack("Snack message") {
action("Action") { toast("Action clicked") }
@rossharper
rossharper / ParameterizedKotlinTest.kt
Created February 20, 2016 21:51
Parameterized JUnit4 test example in Kotlin
@RunWith(Parameterized::class)
class KotlinTest(val paramOne: Int, val paramTwo: String) {
companion object {
@JvmStatic
@Parameterized.Parameters
fun data() : Collection<Array<Any>> {
return listOf(
arrayOf(1, "I"), // First test: (paramOne = 1, paramTwo = "I")
arrayOf(1999, "MCMXCIX") // Second test: (paramOne = 1999, paramTwo = "MCMXCIX")
@bkase
bkase / prnsaaspfruicc.md
Created March 3, 2016 22:58
Production-Ready(?) Native Single-Atom-State Purely Functional Reactive Composable UI Components, or PRNSAASPFRUICC

Production-Ready(?) Native Single-Atom-State Purely Functional Reactive Composable UI Components, or PRNSAASPFRUICC

The native UI toolkits on Android and iOS are frustratingly imperative. Unfortunately, there has been little architecture evolution (unlike the web). However, nothing(ish) is stopping us from bolting something "nice" on top. By nice I mean single-atom-state purely functional reactive composable UI components. In this post, I'll explain what this title means, the inspiration behind the design of the framework, an example component, and dive a little into the framework's implementation.

Right now, there only exists a Kotlin (Android) implementation, but a Swift port will be relatively straightforward and will happen soon.

Let's break down the title:

  • "Production-Ready"
@gcollazo
gcollazo / atomstars.bash
Created March 4, 2016 13:34
Update your Atom starred packages.
# The atom cli tool provides a command for installing packages
# that you have previously starred. Once you all you pakackages
# are starred installing is super easy `apm stars --install`.
# This little command unstars all packages in your profile
# and start only the ones you have installed.
# For this to work you need jq `brew install jq`.
alias atomstars='apm unstar $(apm stars --json | jq -r ".[].name") && apm star --installed'
@baconpat
baconpat / RecycleViewMatcher.java
Created March 30, 2016 01:13
RecycleViewMatcher (updated for scrolling)
package com.foo.RecyclerViewMatcher;
import android.content.res.Resources;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import org.hamcrest.Description;
import org.hamcrest.Matcher;
import org.hamcrest.TypeSafeMatcher;
@lfmingo
lfmingo / headers-okhttp-retrofit2.java
Created March 30, 2016 18:56
Add headers in http request using okhttp interceptor with retrofit 2
OkHttpClient.Builder httpClient = new OkHttpClient.Builder();
httpClient.addInterceptor(new Interceptor() {
@Override
public Response intercept(Interceptor.Chain chain) throws IOException {
Request original = chain.request();
Request request = original.newBuilder()
.header("User-Agent", "Your-App-Name")
.header("Accept", "application/vnd.yourapi.v1.full+json")
.method(original.method(), original.body())
@OleksandrKucherenko
OleksandrKucherenko / version-up.sh
Last active May 2, 2024 13:04
Calculate Next Suitable Version Tag for Your Git based project
#!/usr/bin/env bash
# shellcheck disable=SC2155
## Copyright (C) 2017, Oleksandr Kucherenko
## Last revisit: 2023-09-30
## Version: 2.0.2
## License: MIT
## Fix: 2023-10-01, prefix for initial INIT_VERSION was not applied
## Fix: 2023-10-01, correct extraction of latest tag that match version pattern
## Added: 2023-09-30, @mrares prefix modification implemented
@wolivera
wolivera / read_write_json_file.rake
Last active February 22, 2019 12:12
Task to read, write and save a JSON file in Ruby
namespace :json do
# Usage: rake json:set_fields[file_name]
desc "Set some sample fields to an existing JSON file"
task :set_fields, [:file_name] => :environment do |t, args|
file_name = args[:file_name]
file_folder = Rails.root.join('app','assets','sample') # Step over the right folder
file = File.read(file_folder.join(file_name + ".json")) # Get the JSON file
fields = JSON.parse(form) # Get the JSON data to parse
updated_fields = set_fields(fields) # Set required to ruby Hash