Skip to content

Instantly share code, notes, and snippets.

View 4gray's full-sized avatar
:octocat:
Focusing

4gray

:octocat:
Focusing
View GitHub Profile
@4gray
4gray / gist:8614247
Created January 25, 2014 10:01
DownloadManager [Android]
/**
* Start Download
*/
public void startDownload(String link, String filename) {
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).mkdirs();
DownloadManager mManager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
DownloadManager.Request mRqRequest = new DownloadManager.Request(Uri.parse(link));
mRqRequest.setDescription("Download file...");
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="red_50">#fde0dc</color>
<color name="red_100">#f9bdbb</color>
<color name="red_200">#f69988</color>
<color name="red_300">#f36c60</color>
<color name="red_400">#e84e40</color>
<color name="red_500">#e51c23</color>
<color name="red_600">#dd191d</color>
<color name="red_700">#d01716</color>
@4gray
4gray / recyclerView.md
Last active August 29, 2015 14:14 — forked from grantland/post.md

RecyclerView item onClick

RecyclerView does not have an OnItemClickListener like it's predecessor, ListView. However, detecting item clicks is pretty simple.

Set an OnClickListener in your ViewHolder creation:

private class MyAdapter extends RecyclerView.Adapter<MyAdapter.ViewHolder>  {

    public static class ViewHolder extends RecyclerView.ViewHolder
Toolbar toolbar = (Toolbar)findViewById(R.id.toolbar);
//Title and subtitle
toolbar.setTitle("MY toolbar");
toolbar.setSubtitle("Subtitle");
//Menu
toolbar.inflateMenu(R.menu.toolbar_menu);
toolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
/**
* Programmatically logs a user in
*
* @param string $username
* @return bool True if the login was successful; false if it wasn't
*/
function programmatic_login( $username ) {
if ( is_user_logged_in() ) {
wp_logout();
<?php
add_action('admin_menu', 'plugin_admin_add_page');
function plugin_admin_add_page() {
add_options_page('Custom Plugin Page', 'Custom Plugin Options Page', 'manage_options', 'page_slug', 'plugin_options_page'); //settings menu page
}
function plugin_options_page() {
//HTML and PHP for Plugin Admin Page
echo "<h2>The Custom Plugin Options Page</h2>";
}
<?php
add_action('admin_menu', 'plugin_admin_add_page');
function plugin_admin_add_page() {
//http://codex.wordpress.org/Function_Reference/add_menu_page
add_menu_page( 'custom menu title', 'custom menu', 'manage_options', 'dbexplorer/adminpage.php');
}
function my_enqueue($hook) {
//only for our special plugin admin page
if( 'dbexplorer/adminpage.php' != $hook )

Launch Sublime Text 2 from the Mac OS X Terminal

Sublime Text 2 ships with a CLI called subl (why not "sublime", go figure). This utility is hidden in the following folder (assuming you installed Sublime in /Applications like normal folk. If this following line opens Sublime Text for you, then bingo, you're ready.

open /Applications/Sublime\ Text\ 2.app/Contents/SharedSupport/bin/subl

You can find more (official) details about subl here: http://www.sublimetext.com/docs/2/osx_command_line.html

Installation

@4gray
4gray / limit-string
Created May 6, 2016 12:51
Limit the length of a string with AngularJS
{{ string | limitTo: 20 }}{{string.length > 20 ? '...' : ''}}
@4gray
4gray / gist:684cf38a4bebdecb0f444d37510bacb7
Created May 6, 2016 13:22
Disable object highlighting (CSS)
:not(input):not(textarea),
:not(input):not(textarea)::after,
:not(input):not(textarea)::before {
-webkit-user-select: none;
user-select: none;
cursor: default;
}
input, button, textarea, :focus {
outline: none; // You should add some other style for :focus to help UX/a11y
}