Skip to content

Instantly share code, notes, and snippets.

View jessejohnson's full-sized avatar
😌

Jesse Jojo Johnson jessejohnson

😌
View GitHub Profile
try:
import simplejson as json
except ImportError:
try:
import json
except ImportError:
raise ImportError
import datetime
from bson.objectid import ObjectId
from werkzeug import Response
Provider Singleton Instantiable Configurable
Constant Yes No No
Value Yes No No
Service Yes No No
Factory Yes Yes No
Decorator Yes No? No
Provider Yes Yes Yes

Constant

import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
public abstract class EndlessRecyclerOnScrollListener extends RecyclerView.OnScrollListener {
public static String TAG = EndlessRecyclerOnScrollListener.class.getSimpleName();
private int previousTotal = 0; // The total number of items in the dataset after the last load
private boolean loading = true; // True if we are still waiting for the last set of data to load.
private int visibleThreshold = 5; // The minimum amount of items to have below your current scroll position before loading more.
int firstVisibleItem, visibleItemCount, totalItemCount;
//var csv is the CSV file with headers
function csvJSON(csv){
var lines=csv.split("\n");
var result = [];
var headers=lines[0].split(",");
for(var i=1;i<lines.length;i++){
@jessejohnson
jessejohnson / mixins.py
Last active August 29, 2015 14:22 — forked from dbrgn/mixins.py
class DynamicFieldsMixin(object):
"""
A serializer mixin that takes an additional `fields` argument that controls
which fields should be displayed.
Usage::
class MySerializer(DynamicFieldsMixin, serializers.HyperlinkedModelSerializer):
class Meta:
model = MyModel
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="false"
android:color="@color/flat_disabled_text"/>
<item android:color="@color/flat_normal_text"/>
</selector>
@jessejohnson
jessejohnson / ContentFragment.java
Created November 27, 2015 07:59
A trivial Endless Scrolling RecyclerView
/**
* Created by odette on 10/28/15.
*/
public class ContentFragment extends Fragment {
public static ContentFragment newInstance(){
return fragment;
}
@jessejohnson
jessejohnson / formatLargeInteger.java
Created November 8, 2016 11:34
format large numbers like on Twitter, etc.
private String formatLargeInteger(int largeInt){
if(largeInt < 10000){
//ie. 0 - 9,999
return String.valueOf(largeInt);
}else if(largeInt >= 10000 && largeInt < 1000000){
//ie. 10,000 - 999,999
String s = String.valueOf(largeInt);
return s.substring(0, s.length() - 3) + "K"; //10K - 999K
}else {
//ie. 1,000,000 - inf
@jessejohnson
jessejohnson / install.sh
Created November 28, 2016 14:21 — forked from wdullaer/install.sh
Install Latest Docker and Docker-compose on Ubuntu
# Ask for the user password
# Script only works if sudo caches the password for a few minutes
sudo true
# Install kernel extra's to enable docker aufs support
# sudo apt-get -y install linux-image-extra-$(uname -r)
# Add Docker PPA and install latest version
# sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 36A1D7869245C8950F966E92D8576A8BA88D21E9
# sudo sh -c "echo deb https://get.docker.io/ubuntu docker main > /etc/apt/sources.list.d/docker.list"
emptyView.postDelayed(new Runnable() {
@Override
public void run() {
emptyView.setEmptyStatus(getString(R.string.video_is_still_loading));
}
}, 10000); //wait for 10 seconds before begging :(