Skip to content

Instantly share code, notes, and snippets.

Avatar

Eric Boehs ericboehs

View GitHub Profile
@ericboehs
ericboehs / flatten_json.rb
Created Aug 19, 2021
Flatten a JSON object (for Slack)
View flatten_json.rb
require 'json'
def flatten_hash(hash)
hash.each_with_object({}) do |(k, v), h|
if v.is_a? Hash
flatten_hash(v).map { |h_k, h_v| h["#{k}.#{h_k}".to_sym] = h_v }
else
h[k] = v
end
end
@ericboehs
ericboehs / gov.va.socks.plist
Created Mar 9, 2021
LaunchAgent for continually connecting to SOCKS via autossh
View gov.va.socks.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>gov.va.socks</string>
<key>KeepAlive</key>
<dict>
<key>NetworkState</key>
<true/>
View proxy.pac
function FindProxyForURL(url, host) {
PROXY = "SOCKS5 127.0.0.1:2001;SOCKS 127.0.0.1:2001"
if (shExpMatch(host,"*.vfs.va.gov")) {
return PROXY;
}
if (shExpMatch(host,"*.vetsgov-internal")) {
return PROXY;
}
View blink-solarized.js
View s3_directory_service.rb
# frozen_string_literal: true
# This file lives in lib/active_storage/service/s3_directory_service.rb.
require 'aws-sdk-s3'
require 'active_storage/service/s3_service'
require 'active_support/core_ext/numeric/bytes'
module ActiveStorage
class Service
View assinc.rb
require 'minitest/autorun'
class TestArray < Minitest::Test
def test_array
assert_includes %(a b c), 'a'
end
def test_array_refutation
refute_includes %(a b c), 'd'
end
View yts_downloader
#! /usr/bin/env ruby
require 'cgi'
require 'net/http'
require 'json'
# Adds a movie to put.io based on search term
class MovieDownloader
attr_reader :term
@ericboehs
ericboehs / application_record.rb
Last active Sep 7, 2019
Helper method to get the URL to an ActiveStorage Blob/Variant
View application_record.rb
# frozen_string_literal: true
class ApplicationRecord < ActiveRecord::Base
self.abstract_class = true
def attached_url_for(attached, variant: nil, cloudfront_endpoint: ENV['CLOUDFRONT_ENDPOINT'], fallback_url: nil)
if attached.attached?
attached = attached.variant variant if variant
path_helper = Rails.application.routes.url_helpers.method :rails_blob_path
@ericboehs
ericboehs / index.html
Last active Aug 25, 2019
Sticky side and top nav via UIKit and position: sticky
View index.html
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/uikit/3.1.7/css/uikit.min.css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/uikit/3.1.7/js/uikit.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/uikit/3.1.7/js/uikit-icons.min.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<style>
.tm-height-100vh { height: 100vh; }
.tm-position-top-sticky {
@ericboehs
ericboehs / autocomplete.html
Last active Jul 16, 2019
Vanilla JavaScript Autocomplete
View autocomplete.html
<!-- Check out the codepen here: https://codepen.io/anon/pen/jjjJoG -->
<div class="uk-container-xsmall uk-margin-top uk-margin-auto">
<input class="tm-autocomplete-input uk-input" autocomplete="false" type="text" placeholder="Search Country...">
<ul class="tm-autocomplete" hidden></ul>
</div>