This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module HashFieldsHelper | |
def flatten_hash(hash, ancestor_names = []) | |
hash.map do |k, v| | |
case v | |
when Hash | |
flatten_hash(v, ancestor_names + [k]) | |
when Array | |
v.map { |item| flatten_hash(item, ancestor_names + [k, '']) }.inject(:merge) | |
else | |
{flat_hash_key(ancestor_names + [k]) => v.to_s} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Controller } from "@hotwired/stimulus" | |
// Connects to data-controller="table-sortable-headers" | |
export default class extends Controller { | |
static targets = [ "sortingHeader", "sortableRow", "sortableTbody" ]; | |
static values = { | |
sortColumn: { type: String, default: "" }, | |
sortDirection: { type: String, default: "" } | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%%= form_for([<%= model_resource_name %>]) do |form| %> | |
<%%= show_errors_for form.object %> | |
<% attributes.each do |attribute| -%> | |
<div class="mb-3"> | |
<% if attribute.password_digest? -%> | |
<%%= form.label :password, class: "form-label" %> | |
<%%= form.password_field :password, class: "form-control", required: form.object.new_record? %> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module FixEncoding | |
def FixEncoding.remove_bom(str) | |
if str.byteslice(0..2) == "\xEF\xBB\xBF".b | |
return str.byteslice(3..-1) | |
else | |
return str | |
end | |
end | |
def FixEncoding.has_utf8?(str) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module FixEncoding | |
def FixEncoding.fix_encoding(str) | |
# The "b" method returns a copied string with encoding ASCII-8BIT | |
str = str.b | |
# Strip UTF-8 BOM if it's at start of file | |
if str =~ /\A\xEF\xBB\xBF/n | |
str = str.gsub(/\A\xEF\xBB\xBF/n, '') | |
end | |
if str =~ /([\xc0-\xff][\x80-\xbf]{1,3})+/n | |
# String has actual UTF-8 characters |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# words that indicate last name | |
# | |
# da | |
# de | |
# de la | |
# del | |
# di | |
# dos | |
# la | |
# van der |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module AudioTime | |
# AIFF stores the samples per second as an IEEE 80-bit float, big-endian. | |
# This code will convert it to a 32-bit integer. This is not generalized | |
# code for this operation as it ignores the sign bit, part of the mantissa, | |
# etc. | |
def AudioTime.ieee80_to_long(raw_number) | |
discard, mantissa, hidden, exponent, sign = raw_number.reverse.unpack('b80').first.unpack('a32 a31 a1 a15 a1') | |
# Get the real exponent - the exponent is really exponent + 1 | |
exponent = [exponent].pack('b15').unpack('v').first - 16382 | |
# Now, use the exponent to pull the proper bits from the mantissa. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- | |
Note that when showing this line if the object is marked_for_destruction? it | |
should be hidden. | |
--> | |
<tr class="line_item subform fields" id="line_item_<%= f.object.id %>"> | |
<td> | |
<%= f.text_field :field_1, required: true %> | |
</td> | |
<td> | |
<%= f.text_field :field_2, required: true %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Based on Stripe's jquery.payment, offers a simple set of utilities | |
// for handling credit card numbers, expirations, and CVC/CVV2 codes | |
// | |
// cc_format_card_number(field) | |
// cc_format_card_expiry(field) | |
// cc_format_card_cvc(field) | |
// | |
// "field" may be either the actual DOM element reference or a string | |
// with the ID of the DOM element. This will add event handlers to | |
// the field to handle input. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This function takes a string that is in Latin-1 (ISO-8859-1), UTF-8, or plain ASCII and returns the string properly encoded as UTF-8. In addition, any Microsoft smart quotes (stupid quotes) are replaced with plain ASCII equivalents. This is useful for reading CSV files or other text files from a web upload and getting to a "known good" state. |
NewerOlder