Skip to content

Instantly share code, notes, and snippets.

View walterdavis's full-sized avatar

Walter Lee Davis walterdavis

View GitHub Profile
@walterdavis
walterdavis / .git-autocomplete.bash
Last active May 29, 2019 18:03
Auto-complete for git commands and branches. "Install" by adding `. ~/.git-autocomplete.bash` (without back-ticks) to your .bash_profile.
# 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
// 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
<!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%;
require 'nokogiri'
require 'json'
html = <<-HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
curly
<link rel=”stylesheet” type=”text/css” href=”Resources/seasonal.php” />
corrected:
<link rel="stylesheet" type="text/css" href="Resources/seasonal.php" />
<?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>
<?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>
@walterdavis
walterdavis / document.rb
Created October 4, 2017 01:16
Shrine setup
include FileUploader::Attachment.new(:file)

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
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?