Skip to content

Instantly share code, notes, and snippets.

import numpy
import matplotlib.pyplot as plt
def interpolateCatmulRomeSegment(P0, P1, P2, P3, nPoints=10):
"""
P0, P1, P2, and P3 should be (x,y) point pairs that define the Catmull-Rom spline.
nPoints is the number of points to include in this curve segment.
"""
# Convert the points to numpy so that we can do array multiplication
P0, P1, P2, P3 = map(numpy.array, [P0, P1, P2, P3])
@lecho
lecho / RecyclerViewItemDevorator.java
Created July 10, 2015 19:51
Example decorator for RecyclerView form support library
package com.github.lecho.mobilization;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
@lecho
lecho / ColumnPreselectionText.java
Last active August 29, 2015 14:17
Column value pre-selection
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_line_column_dependency, container, false);
// *** TOP LINE CHART ***
chartTop = (LineChartView) rootView.findViewById(R.id.chart_top);
// Generate and set data for line chart
generateInitialLineData();
@lecho
lecho / PathCompat.java
Created August 21, 2014 17:40
PathCompat for android
package lecho.lib.hellocharts.renderer;
import lecho.lib.hellocharts.util.CasteljauComputator;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.PointF;
/**
* PathCompat uses Canvas.drawLines instead Canvas.drawPath. Supports normal lines and cubic Bezier's lines.
* Warning!: doesn't support breaks in line so line has to be continuous and doesn't support area chart.
package lecho.lib.hellocharts.util;
import android.graphics.PointF;
/**
* Iterative implementation of de Casteljau's algorithm for cubic Bezier's curves.
*
*/
public class CasteljauComputator {
private static final int DEFAULT_CURVE_DEGREE = 3;// By default cubic.
@lecho
lecho / CohenSutherlandComputator.java
Created August 13, 2014 17:16
CohenSutherlandComputator - clipping algorithm
package lecho.lib.hellocharts.util;
import android.graphics.RectF;
/**
* Cohen-Sutherland algorithm implementation based on wikipedia article.
*
* {@link http://en.wikipedia.org/wiki/Cohen-Sutherland_algorithm}
*
*/
//Automatically calculates Y axis values.
private Axis calculateYAxis(int numberOfSteps) {
if (numberOfSteps < 2) {
throw new
IllegalArgumentException("Number or steps have to be grater or equal 2");
}
List<Float> values = new ArrayList<Float>();
final float range = mData.getMaxYValue() - mData.getMinYValue();
final float tickRange = range / (numberOfSteps - 1);
final float x = (float) Math.ceil(Math.log10(tickRange) - 1);
public class TimePickerDialogFragment extends DialogFragment implements TimePickerDialog.OnTimeSetListener {
private static final String DIALOG_HOUR = "my.package:INITIAL_HOUR";
private static final String DIALOG_MINUTE = "my.package:INITIAL_MINUTE";
//My custom listener
private OnTimePickedListener mListener;
private int mDialogRequestCode;
//Use dialogRequestCode to discriminate dialogs in OnTimePickedListener#onTimePicked method. I think you could also use dialog tag string instead of integer variable.
public static TimePickerDialogFragment newInstance(int hour, int minute, int dialogRequestCode, OnTimePickedListener listener) {
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.7.0'
}
}
@lecho
lecho / SplineInterpolation.java
Created November 24, 2013 14:15
Spline interpolation in java.
/*
* Copyright (C) 2012 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software