Skip to content

Instantly share code, notes, and snippets.

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

4gray

:octocat:
Focusing
View GitHub Profile
<?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 / lightbox.rb
Created July 23, 2016 11:28 — forked from melborne/lightbox.rb
Jekyll Lightbox Image Plugin
# A Liquid tag for Jekyll sites that allows embedding Lightbox images.
# by: kyoendo
# Source URL: https://gist.github.com/4035604
#
# Example usage: {% lightbox 2012/abc.png, Title of Image, Alt Title %}
module Jekyll
class LightboxTag < Liquid::Tag
def initialize(tag_name, text, token)
super
@text = text
@4gray
4gray / ID.js
Created March 2, 2017 15:26
ID - a unique ID/name generator for JavaScript
// Generate unique IDs for use as pseudo-private/protected names.
// Similar in concept to
// <http://wiki.ecmascript.org/doku.php?id=strawman:names>.
//
// The goals of this function are twofold:
//
// * Provide a way to generate a string guaranteed to be unique when compared
// to other strings generated by this function.
// * Make the string complex enough that it is highly unlikely to be
// accidentally duplicated by hand (this is key if you're using `ID`
<div ng-class="condition ? 'class-if-true' : 'class-if-false'">