Skip to content

Instantly share code, notes, and snippets.

@mrclay
mrclay / .htaccess
Created March 7, 2012 15:01
Remove PHP extension from URLs
<IfModule mod_rewrite.c>
RewriteEngine on
# Redirect /index.php (and /index) to /
RewriteCond %{THE_REQUEST} ^GET\ /(.*/)?index(\.php)?(\?.*)?\ HTTP/
RewriteRule ^ http://%{HTTP_HOST}/%1 [L,R=301]
# Redirect /foo.php to /foo
RewriteCond %{THE_REQUEST} ^GET\ /(.*)\.php(\?.*)?\ HTTP/
RewriteRule ^ http://%{HTTP_HOST}/%1 [L,R=301]
@fenda
fenda / .htaccess (file extension)
Last active June 6, 2023 13:27
remove file extension from url
# The following will allow you to use URLs such as the following:
#
# example.com/link
# example.com/link/
#
# Which will actually serve files such as the following:
#
# example.com/link.html
# example.com/link.php
#
@ssinss
ssinss / EndlessRecyclerOnScrollListener.java
Last active January 19, 2024 08:52
Endless RecyclerView OnScrollListener
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;
@quynguyen3490
quynguyen3490 / GPSTracking.java
Created April 4, 2015 05:50
Get Current Location Android
package com.quynguyenblog.mymap;
import android.app.AlertDialog;
import android.app.Service;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
@yqritc
yqritc / gist:ccca77dc42f2364777e1
Last active January 25, 2025 17:43
Equal column spacing for Android RecyclerView GridLayoutManager by using custom ItemDecoration

ItemOffsetDecoration

public class ItemOffsetDecoration extends RecyclerView.ItemDecoration {

    private int mItemOffset;

    public ItemOffsetDecoration(int itemOffset) {
        mItemOffset = itemOffset;
    }
@aballano
aballano / WrapHeightViewPager.java
Created October 23, 2015 23:50
Dynamic view pager which sets it´s height to the maximum size of it´s children if set to wrap_content.
import android.content.Context;
import android.support.v4.view.ViewPager;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.MotionEvent;
import android.view.View;
/**
* Created by Shyish on 11/10/2015.
*/
@cxyxlxdm
cxyxlxdm / GridSpacingItemDecoration.md
Last active April 19, 2024 08:43
Add column spacing in RecyclerView with GridLayoutManager

Android Recyclerview GridLayoutManager column spacing Here is the question, the first answer does not work well in my project,and it makes the spacing bigger between item and item. the second answer is quite perfect.But if RecyclerView has headers,it does not work well. Then I fixed it.

import android.graphics.Rect;
import android.support.v7.widget.RecyclerView;
import android.view.View;

/**
@statickidz
statickidz / nearby-coordinates.sql
Last active July 23, 2025 19:36
Ordering with SQL by nearest latitude & longitude coordinates (MySQL & SQLite)
---
METHOD 1
This should roughly sort the items on distance in MySQL, and should work in SQLite.
If you need to sort them preciser, you could try using the Pythagorean theorem (a^2 + b^2 = c^2) to get the exact distance.
---
SELECT *
FROM table
ORDER BY ((lat-$user_lat)*(lat-$user_lat)) + ((lng - $user_lng)*(lng - $user_lng)) ASC
@lisawray
lisawray / ColumnItemDecoration.java
Last active May 29, 2023 21:11
Equal column spacing in a RecyclerView with GridLayoutManager
package com.example.columnspacing
import android.graphics.Paint;
import android.graphics.Rect;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;
@nshCore
nshCore / .htaccess
Created December 20, 2016 09:01
.htaccess to remove .html and .php
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/$ $1.php
RewriteRule ^([^/]+)/([^/]+)/$ /$1/$2.php
RewriteRule ^([^/]+)/$ $1.html
RewriteRule ^([^/]+)/([^/]+)/$ /$1/$2.html
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ /$1/ [R=301,L]