Skip to content

Instantly share code, notes, and snippets.

View gahfy's full-sized avatar

Gahfy gahfy

View GitHub Profile
public class MyDatabaseOpenHelper extends SQLiteOpenHelper {
private Context context;
public MyDatabaseOpenHelper(Context context) {
super(context, DB_NAME, null, DB_VERSION);
this.context = context;
}
}
public abstract class SQLiteOpenHelper {
//[...]
private SQLiteDatabase mDatabase;
//[...]
public void setWriteAheadLoggingEnabled(boolean enabled) {
//[...]
if (mDatabase != null && mDatabase.isOpen() && !mDatabase.isReadOnly()) {
if (enabled) {
mDatabase.enableWriteAheadLogging();
public class TestFragment extends Fragment {
// Dépendance de TestFragment envers String
private String textViewContent;
// Injection de dépendance avec une méthode setter
public void setTextViewContent(String textViewContent){
this.textViewContent = textViewContent;
}
@Override
@gahfy
gahfy / gist:da7a3d69efb72fc2d85c5133c6ed674d
Created April 9, 2017 16:38
Install build-essential package
sudo apt-get update
sudo apt-get -y upgrade
sudo apt-get -y install build-essential
@gahfy
gahfy / install-build-essential
Created April 9, 2017 16:39
Install package build-essential on Debian
sudo apt-get update
sudo apt-get -y upgrade
sudo apt-get -y install build-essential
@gahfy
gahfy / create-initial-directories
Last active April 9, 2017 16:46
Create directories for debian
sudo mkdir -p /usr/local/built-tools
sudo mkdir -p /usr/local/src
sudo mkdir -p /usr/local/var/log
sudo chown -R $LOGNAME:staff /usr/local
@gahfy
gahfy / junitLocalTestDependency.gradle
Last active April 24, 2017 18:36
JUnit 4 dependency for Android local unit tests
dependencies {
// ... Other dependencies of your project
/****************** Local tests ******************/
// JUnit 4 framework
testCompile 'junit:junit:4.12'
}
public class ArrayUtilsUnitTest {
@Test
public void remove_in_array() throws Exception {
int[] testArray = new int[]{1, 2, 3};
int[] resultArray = ArrayUtils.removeIndex(testArray, 1);
Assert.assertArrayEquals("Test int[] ArrayUtils.removeIndex(int[], int)", new int[]{1, 3}, resultArray);
}
}
public class ArrayUtilsUnitTest {
@Test
public void remove_in_array() throws Exception {
int[] testArray = new int[]{1, 2, 3};
int[] resultArray = ArrayUtils.removeIndex(testArray, 2);
Assert.assertArrayEquals("Test int[] ArrayUtils.removeIndex(int[], int)", new int[]{1, 2}, resultArray);
}
}
@gahfy
gahfy / ArrayUtils.java
Last active April 24, 2017 20:04
Method which removes an index from an array of integers
public class ArrayUtils {
/**
* Removes the specified index to the specified array of integer and returns the result
* @param array the array on which to remove the specified index
* @param index the index to remove from the specified array
* @return the result of the deletion
*/
public static int[] removeIndex(int[] array, int index){
int[] result = new int[array.length - 1];
for(int i=0; i<array.length; i++){