Skip to content

Instantly share code, notes, and snippets.

Avatar

Walter Lee Davis walterdavis

View GitHub Profile
View active_support.js
// requires Prototype.js, as do many great things
/**
* ActiveSupport for JavaScript library, version '0.1'
* (c) 2007 Nicolas Sanguinetti
*
* ActiveSupport for JavaScript is freely distributable under the terms of an
* MIT-style license. For details, see our web site:
* http://code.google.com/p/active-support-for-javascript/
*
View warnings.rb
class Post < ApplicaationRecord
attribute :warnings, array: true, default: Set.new
def has_warnings?
publishing_checklist.any?
end
private
def publishing_checklist
@walterdavis
walterdavis / short_unique_tokens_in_ruby.md
Last active May 5, 2022 22:57 — forked from mbajur/.md
How to create small, unique tokens in Ruby
View short_unique_tokens_in_ruby.md
@walterdavis
walterdavis / combo-boxes.md
Last active February 15, 2022 20:55
A combo box, in this setting, is a `<select>` that offers the ability to edit its contents, directly within the current form.
View combo-boxes.md

For example, the list of options is "Foo", "Bar", and "Baz". At the bottom of the list (always at the bottom) the user sees "Add..." as a new option. When she selects that option, the <select> disappears, replaced in place with a focused <input type="text"> ready to accept a new option. It's important to note that this pattern is only usable in cases where the input is stored as a string, and you want to enforce a limited but extensible vocabulary of options. A possible example of this is colors, where you don't want to just let people enter anything, otherwise you would end up with "Gray" and "Grey" and possibly "grey".

app/javascripts/controllers/combo_controller.js

import { Controller } from "stimulus";

export default class extends Controller {
  static targets = ['picker'];
View link-shortener-rails.rb
View video.rb
# == Schema Information
#
# Table name: videos
#
# id :bigint not null, primary key
# created_at :datetime not null
# updated_at :datetime not null
# title :text
# youtube_id :string
# leader_id :bigint
@walterdavis
walterdavis / richtext.css
Created January 7, 2020 13:17
Trix Heading
View richtext.css
trix-toolbar .trix-dialog--heading {
max-width: 190px;
}
.trix-content h1, .trix-content h2, .trix-content h3, .trix-content h4, .trix-content h5, .trix-content h6 {
line-height: 1.2;
margin: 0;
}
.trix-content h1 {
View .git-completion.sh
# 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
@walterdavis
walterdavis / file_upload.php
Last active December 14, 2019 05:16
Catch a file upload with PHP
View file_upload.php
<?php
define('FILES_BASE',dirname(__FILE__) . '/_files');
$message = '';
if(isset($_FILES['menu']['name']) && !empty($_FILES['menu']['name'])){
$basename = safe_name(basename($_FILES['menu']['name']));
$ext = strtolower(substr($basename,strrpos($basename,'.') + 1));
$tmpdir = uniqid( 'file_' );
$file_destination_dir = FILES_BASE . '/' . $tmpdir;
$uploadfile = $file_destination_dir . '/' . $basename;
View test_mail.php
<?php
header('Content-type: text/plain');
error_reporting(E_ALL);
ini_set('display_errors', true);
$from = 'you@yourdomain.com';
$to = 'you@yourdomain.com';
if(mail($to, 'test message from PHP', phpinfo(), array("From: $from"), "-f$from")){
print('Mail sent successfully');