Skip to content

Instantly share code, notes, and snippets.

View abatilo's full-sized avatar

Aaron Batilo abatilo

View GitHub Profile
@RunWith(AndroidJUnit4.class) public class FragmentTest {
// Setup an ActivityTestRule as such that the Activity is not launched until we say so
@Rule public ActivityTestRule<EmptyActivity> rule =
new ActivityTestRule<>(EmptyActivity.class, true, false);
private Fragment fragment;
private EmptyActivity activity;
@Before public void setup() {
@RunWith(AndroidJUnit4.class) public class FragmentTest {
// Setup an ActivityTestRule as such that the Activity is not launched until we say so
@Rule public ActivityTestRule<EmptyActivity> rule =
new ActivityTestRule<>(EmptyActivity.class, true, false);
private Fragment fragment;
private EmptyActivity activity;
@Before public void setup() {
@abatilo
abatilo / EmptyActivity.java
Created February 27, 2017 00:01
An empty activity used only for hosting a fragment to UI test with Espresso
public class EmptyActivity extends AppCompatActivity {
@Override protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
<TextView
android:width="match_parent"
android:height="match_parent"
android:text="Hello world!"
/>
#!/usr/bin/racket
#lang racket
(define sum
(lambda (x)
(if (null? x)
0
(if (cons? x)
(if (number? (car x))
(+ (car x) (sum (cdr x)))
(+ (sum (car x)) (sum (cdr x))))
@abatilo
abatilo / Solution.java
Created January 28, 2017 03:23
Binary watch
import java.util.*;
public class Solution {
private int numberOfOneBits(int num) {
int count = 0;
while (num != 0) {
if ((num & 1) == 1) {
++count;
}
num >>= 1;
}
@abatilo
abatilo / last.sh
Created January 22, 2017 07:08
This script will print all java files found recursively from the current directory, and then print the ones that have not been involved in a git commit in some number of months
#!/bin/bash
# This script will print all java files found recursively from the current directory, and then print the ones that
# have not been involved in a git commit in some number of months
#
# Based on:
# https://hackerific.net/2016/04/30/git-file-age-a-script-to-show-when-files-were-last-modified-in-git/
find . -name *.java | xargs -I § git log -1 --pretty="format:%ct %cr %h §;" § | tr ';' '\n' | sort | cut -f 2- | grep "month"
import java.util.*;
public class Solution {
public boolean repeatedSubstringPattern(String str) {
int length = str.length();
if (length <= 1) return false;
List<Integer> factors = new ArrayList();
// Factor
for (int i = 1; i * 2 <= length; ++i) {
@abatilo
abatilo / abs.c
Created July 12, 2016 20:58
Timing different abs implementations for Aaron
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#include <math.h>
double absd(double n) {
unsigned long *gg = (unsigned long int *)&n;
*(gg) &= 0x7FFFFFFFFFFFFFFFull;
return n;
}
@abatilo
abatilo / gist:4e7e0fc873fd0edd0f03e0aa8c77cb10
Created May 30, 2016 17:42 — forked from lqd/gist:1c841dea193698bf50fefa19c6b3fb99
Some of my favorite development streams and shows
Why coding streams/shows are interesting to me: in some livestreams, the experience is very similar to pair programming,
but those people are experts. In VODs, it's more about problem solving and learning skills and approaches. The devs are really good
at what they do and there is *always* a lot to learn.
In no particular order:
1) Handmade Hero
About the author: Casey Muratori. Worked at RAD.
Description and why I like it: It kinda started the whole thing for me. Casey is coding a complete game and engine on stream,
from scratch, one hour a day. He knows what he's doing on so many of the domains of game development and regular programing,