Skip to content

Instantly share code, notes, and snippets.

Brad Fults h3h

Block or report user

Report or block h3h

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@h3h
h3h / object_attrlist.rb
Last active Aug 29, 2015
Accessing multiple attributes/methods of an object with a concise syntax.
View object_attrlist.rb
module Attrlist
def /(attrlist)
attrlist.map { |a| send(a) }
end
end
class Time
include Attrlist
end
@h3h
h3h / routes.rb
Last active Aug 29, 2015
Getting the first segments of currently defined static routes
View routes.rb
Rails.application.routes.set.
map { |r| r.optimized_path[1..-1].split('/').first }.
uniq.
compact.
reject { |s| s.include?('*') || s.include?(':') }
@h3h
h3h / README.md
Last active Aug 29, 2015
Adding to/from GeoJSON Conversions to Sequel Queries
View README.md

SQL for INSERT:

INSERT INTO geographies (type, name, geometry)
VALUES (
  'Location',
  'Vintage Heart Coffee',
  ST_GeomFromGeoJSON('{"type": "Point", "coordinates": [30.2642, -97.7277]}')
);
-- INSERT 0 1
@h3h
h3h / yep.rb
Created Aug 10, 2014
Random Plausible HTML Tags
View yep.rb
def random_plausible_html_tags(num=5)
num.times.map { [*('a'..'z')].sample(rand(6) + 1).join }
end
View circular_enumerator.rb
# Utility converter to make a circular enumerator, wrapping around to the
# beginning of a list after it has exhausted all entries.
#
# Example:
#
# >> e = CircularEnumerator([1,2,3,4,5])
# => #<Enumerator: [1, 2, 3, 4, 5]:each>
#
# >> 10.times.map { e.next }
# => [1, 2, 3, 4, 5, 1, 2, 3, 4, 5]
@h3h
h3h / time_utilities.rb
Last active Aug 29, 2015
Parse ISO-8601 time strings and respect the embedded time zone.
View time_utilities.rb
require 'active_support/core_ext/time'
require 'active_support/values/time_zone'
module TimeUtilities
# Parses an ISO-8601 time string with a time zone and keeps the time zone in
# the Time object returned, unlike Ruby Core.
#
# Examples:
#
@h3h
h3h / background_validation.js.coffee
Created Oct 20, 2014
Automatic Per-field Background Validation for Forms
View background_validation.js.coffee
# Automatic Per-field Background Validation for Forms
#
# Usage:
#
# 1. Add a 'bg-validatible' class to your <form>
# 2. Add data-bg-validation-url-template="/validation/{field_id}" to your <form>
# 3. Add data-bg-validation-success-message="Looks good!" to your <form> or each validatible element
# 4. Add data-bg-validation-output="relative_selector_to_field" to the <form> or each validatable element
# 5. Add data-bg-validation-field="some_field_id" to each validatable field
# 6. (Optionally) Add a data-bg-validation-include="other_id,other2_id" attribute to the validatable field to send
View ruby-upgrade-2.1.5.sh
#!/bin/bash -e
number_of_cores=`sysctl -n hw.ncpu`
brew update && \
brew upgrade ruby-build libxml2 libxslt libiconv
brew link --force libiconv && \
bundle config --global build.nokogiri "--with-xml2-include=/usr/local/include --with-xml2-lib=/usr/local/lib --with-xslt-dir=/usr/local/opt/libxslt --with-iconv-include=/usr/local/include --with-iconv-lib=/usr/local/lib" && \
bundle config --global jobs `expr $number_of_cores - 1` && \
rbenv install 2.1.5 && \
@h3h
h3h / explanation.md
Last active Aug 29, 2015
HR 4681 Section 309
View explanation.md

TL;DR

Congress (House & Senate) just passed (amidst the release of the torture report and the Gruber hearing) an amendment to the annual intelligence agencies’ budget bill (HR 4681, Section 309) that makes it legal to:

  • Collect all electronic communications from everyone in the world
  • Store all of that data for at least 5 years
  • Store the data indefinitely if it’s encrypted or evidence of a crime (presumably until a supercomputer can break the encryption, assuming that hadn’t happened within 5 years)
  • Disseminate the data (presumably at the inteliigence agencies’ own discretion, e.g. to your local police or the DEA)
View time-ext.rb
class Time
def within?(time_period)
self >= Time.now && self <= Time.now + time_period
end
end
# >> (Time.now + 55.hours).within? 2.days
# false
# >> (Time.now + 45.hours).within? 2.days
# true
You can’t perform that action at this time.