Skip to content

Instantly share code, notes, and snippets.

View walterdavis's full-sized avatar

Walter Lee Davis walterdavis

View GitHub Profile
var Marquee = Class.create({
initialize: function(element) {
this.element = $(element);
this.paused = false;
// If everything fits don't bother with all this mess
if(this.element.scrollWidth == this.element.clientWidth) return;
// Defaults to scrolling through all content in 40 seconds.
// 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
<?php
// only run this if the form has been submitted
if(isset($_POST['files'])){
// where are the PDFs stored on your server?
$source_directory = '/data/www/scripty/pdfs/';
$files = array();
// loop over the chosen PDFs
foreach($_POST['files'] as $key => $val){
// protect against malicious forms -- strip off anything besides a filename
$safe_val = array_pop(preg_split('/\//', $val, -1, PREG_SPLIT_NO_EMPTY));
# routes.rb
match 'ads/:id/present/*path.:format', :to => 'ads#present'
# ads_controller.rb
def present
@ad = Ad.find(params[:id])
path = "#{params[:path]}.#{params[:format]}"
send_data(@ad.get_file(path), :filename => path, :disposition => 'inline')
end
@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 {