Skip to content

Instantly share code, notes, and snippets.

Walter Lee Davis walterdavis

Block or report user

Report or block walterdavis

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@walterdavis
walterdavis / .git-autocomplete.bash
Last active May 29, 2019
Auto-complete for git commands and branches. "Install" by adding `. ~/.git-autocomplete.bash` (without back-ticks) to your .bash_profile.
View .git-autocomplete.bash
# bash/zsh completion support for core Git.
#
# Copyright (C) 2006,2007 Shawn O. Pearce <spearce@spearce.org>
# Conceptually based on gitcompletion (http://gitweb.hawaga.org.uk/).
# Distributed under the GNU General Public License, version 2.0.
#
# The contained completion routines provide support for completing:
#
# *) local and remote branch names
# *) local and remote tag names
View show-more.js
// find all the divs with the class name 'more', and hide them
$$('div.more').invoke('hide');
// "listen" for clicks on any link with the class name 'more', and respond...
$(document).on('click', 'a.more', function(evt, elm){
// first, stop any normal reaction, like scrolling back to the top of the browser window
evt.stop();
// starting from the link that was clicked, look up to its containing element...
// then select the following div with the class name 'more', and if it's hidden, show it, or vice-versa
elm.up().next('div.more').toggle();
// toggle the text inside the link that was clicked
View read-more.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Read more...</title>
<script src="//ajax.googleapis.com/ajax/libs/prototype/1.7/prototype.js"></script>
<style>
body, html {
width: 100%;
height: 100%;
View nokogiri_example.rb
require 'nokogiri'
require 'json'
html = <<-HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
View example.html
curly
<link rel=”stylesheet” type=”text/css” href=”Resources/seasonal.php” />
corrected:
<link rel="stylesheet" type="text/css" href="Resources/seasonal.php" />
View sitemap.xml
<?xml version="1.0" encoding="UTF-8"?>
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<sitemap>
<loc>http://example.org/sitemap3.xml</loc>
</sitemap>
</sitemapindex>
View sitemap.xml
<?xml version="1.0" encoding="UTF-8"?>
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<sitemap>
<loc>http://example.org/sitemaps/site.xml</loc>
</sitemap>
<sitemap>
<loc>http://example.org/sitemaps/books.xml</loc>
</sitemap>
<sitemap>
<loc>http://example.org/sitemaps/pages.xml</loc>
View document.rb
include FileUploader::Attachment.new(:file)
View refactoring_to_partials.md

Refactoring a view with partials

Rails gives you a lot of functionality for free if you know how to name things and where to place them in the file tree.

For example, look at the following stages of refactoring a list of child elements to the parent element, in the #show page.

Stage 1

class Article < ActiveRecord::Base
View ability.rb
class Ability
include CanCan::Ability
def initialize(user)
user ||= User.new # guest user (not logged in)
can :read, :search
can [:send_feedback, :feedback], :feedback
if user.admin?
You can’t perform that action at this time.