Skip to content

Instantly share code, notes, and snippets.

View lordcodes's full-sized avatar
⌨️
Coding

Andrew Lord lordcodes

⌨️
Coding
View GitHub Profile
@lordcodes
lordcodes / explainme.gradle
Created November 2, 2015 21:21
Gradle function to print out the contents of an object
def void explainMe(it) {
println "Examining $it.name:"
println "Meta:"
println it.metaClass.metaMethods*.name.sort().unique()
println "Methods:"
println it.metaClass.methods*.name.sort().unique()
println "Properties:"
println it.properties.entrySet()*.toString()
.sort().toString().replaceAll(", ","\n")
}
@lordcodes
lordcodes / fix_resources.gradle
Last active November 2, 2015 21:25
Gradle code to fix issue in Robolectric when running tests on a library project. Based on an answer here (https://github.com/robolectric/robolectric/issues/1796), but altered to store the libraries in the build directory and to pull the package name from your build variants
import static groovy.io.FileType.FILES
// This task discovers the manifest files for the .aars that we depend on and
// adds them to project.ext.manifestFiles for use in later tasks.
task discoverManifestFiles(dependsOn: 'prepareDebugDependencies') << {
def aars = new File(project.buildDir.absolutePath + "/intermediates/exploded-aar")
def manifestFiles = new ArrayList<File>()
// Iterate through the exploded-aars directory, finding the manifests
@lordcodes
lordcodes / build-fix-robolectric-properties.gradle
Last active January 18, 2016 23:36
Workaround for test resources file not being found by Robolectric. You will need to add: "apply from: 'build-test-fixes.gradle'" to your main build.gradle file.
// Workaround for missing test resources when run unit tests within android studio.
// This copy the test resources next to the test classes for each variant.
// Tracked at https://github.com/nenick/AndroidStudioAndRobolectric/issues/7
// Original solution comes from https://code.google.com/p/android/issues/detail?id=136013#c10
gradle.projectsEvaluated {
// Base path which is recognized by android studio.
def testClassesPath = "${buildDir}/intermediates/classes/test/"
// Copy must be done for each variant.
def variants = android.applicationVariants.collect()
@lordcodes
lordcodes / CustomRobolectricTestRunner.java
Last active February 18, 2016 21:14
Robolectric Gradle test runner so that Config annotation isn't required on each of your test classes.
public class CustomRobolectricTestRunner extends RobolectricGradleTestRunner {
private static final int MAX_SDK_LEVEL = 21;
public CustomRobolectricTestRunner(Class<?> testClass) throws InitializationError {
super(testClass);
}
@Override
public Config getConfig(Method method) {
@lordcodes
lordcodes / current-git-branch.gradle
Last active January 11, 2024 03:54
Gradle function to get the current Git branch
def getCurrentGitBranch() {
def gitBranch = "Unknown branch"
try {
def workingDir = new File("${project.projectDir}")
def result = 'git rev-parse --abbrev-ref HEAD'.execute(null, workingDir)
result.waitFor()
if (result.exitValue() == 0) {
gitBranch = result.text.trim()
}
} catch (e) {
@lordcodes
lordcodes / current-git-commit.gradle
Created October 27, 2016 21:57
Gradle function to get the current Git commit
def getCurrentGitCommitHash() {
def gitCommit = "Unknown commit"
try {
def workingDir = new File("${project.projectDir}")
def result = 'git rev-parse --short HEAD'.execute(null, workingDir)
result.waitFor()
if (result.exitValue() == 0) {
gitCommit = result.text.trim()
}
} catch (e) {
@lordcodes
lordcodes / .gitignore
Created November 20, 2016 00:28
.gitignore for Unity projects
# Unity project files
/[Ll]ibrary/
/[Tt]emp/
/[Oo]bj/
/[Bb]uild/
*.unityproj
# Autogenerated VS/MD solution and project files
ExportedObj/
*.csproj
@lordcodes
lordcodes / YourClass.cs
Created November 20, 2016 18:26
How to document a method within your C# library's public API
namespace YourNamespace {
/// <summary>
/// Put a description of the class here.
/// </summary>
public class YourClass {
/// <summary>
/// Put a description of the method here.
/// </summary>
/// <param name="key">Put a description of the parameter here.</param>
@lordcodes
lordcodes / YourClassTest.cs
Last active November 20, 2016 20:39
Format for writing a C# Unity test class
namespace YourNamespace.UnitTests {
using UnityEngine;
using NUnit.Framework;
public class YourClassTest {
private YourClass yourClass;
[SetUp]
@lordcodes
lordcodes / install-unity.sh
Last active November 21, 2016 21:37
Script to install the Unity Mac Editor, written for use on Travis.
#! /bin/sh
BASE_URL=http://netstorage.unity3d.com/unity
HASH=649f48bbbf0f
VERSION=5.4.1f1
download() {
url="$BASE_URL/$HASH/$package"
echo "Downloading from $url: "