Skip to content

Instantly share code, notes, and snippets.

View walterdavis's full-sized avatar

Walter Lee Davis walterdavis

View GitHub Profile
// 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/
*
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

How to create small, unique tokens in Ruby

That is is basically a "fork" of blog article i'm constantly returning to. It seems that the blog is down:

My choice: Dave Bass’s rand().to_s() trick

Dave Bass proposed this which I picked up for my implementation (here for an 8-chars token):

@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.

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'];
# == 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
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 {
# 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
<?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;
<?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');