Skip to content

Instantly share code, notes, and snippets.

View chemouna's full-sized avatar

Mouna Cheikhna chemouna

  • San Francisco, CA
View GitHub Profile
@chemouna
chemouna / dutch_flag_problem.py
Created June 3, 2020 16:31
Dutch National Flag Problem
import random
colours_in_order = 'Red White Blue'.split()
def dutch_flag_sort(items): # O(n) time, O(1) space
lo, mid, hi = 0, 0, len(items) - 1
while mid <= hi:
colour = items[mid]
if colour == 'Red':
@chemouna
chemouna / get_contact_first_name.java
Last active November 4, 2015 11:30
It's pretty hard to find the exact query to do to get a contact's name , So here's how :
String[] nameProjection = new String[] {
ContactsContract.CommonDataKinds.StructuredName.GIVEN_NAME,
ContactsContract.CommonDataKinds.StructuredName.FAMILY_NAME
};
final Cursor nameCursor = context.getContentResolver()
.query(ContactsContract.Data.CONTENT_URI, nameProjection,
ContactsContract.Data.LOOKUP_KEY + " = ? AND "+ ContactsContract.Data.MIMETYPE + " = ? ",
new String[] { contactLookupKey, ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE },
null, null);
@chemouna
chemouna / OrientationChangeAction.java
Created September 2, 2015 19:28
A ViewAction (espresso) that changes the orientation of the screen
/**
* An Espresso ViewAction that changes the orientation of the screen
*/
public static class OrientationChangeAction implements ViewAction {
private final int orientation;
private OrientationChangeAction(int orientation) {
this.orientation = orientation;
}
@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;
@chemouna
chemouna / BufferedDiskBasedCache
Created April 14, 2014 17:14
A faster implementation of DiskBaseCache of volley
import android.os.SystemClock;
import com.android.volley.Cache;
import com.android.volley.VolleyLog;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.EOFException;
import java.io.File;
import java.io.FileInputStream;