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
require "ipaddr" | |
require "resolv" | |
require "uri" | |
class UrlChecker | |
SCHEME_REGEX = Regexp.new(/\Ahttps?/) | |
HOST_REGEX = Regexp.new(/.+\..+/) | |
IPV4_REGEX = Regexp.new(/(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}/) | |
IPV6_REGEX = Regexp.new(/(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))/) | |
PRIVATE_RANGES = %w[127.0.0.0/8 192.168.0.0/16 172.16.0.0/12 10.0.0.0/8 100.64 |
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
#!/usr/bin/env ruby | |
root = "/tmp/intercom" | |
IntercomClient.conversations.all.each do |c| | |
puts c.id | |
FileUtils.mkdir_p(path = "#{root}/conversations/#{c.id.to_s.first(4)}") | |
File.open("#{path}/#{c.id}.json", "w") { |f| f.puts IntercomClient.conversations.find(id: c.id).to_json } | |
end |
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
# Drop this in config/initializers/active_record.rb | |
class ActiveRecord::ActiveRecordError | |
def initialize(message = nil) | |
if message.respond_to?(:gsub) | |
super(message.gsub(/dearmor\(.*\)/im, '[FILTERED]')) | |
else | |
super(message) | |
end | |
end | |
end |
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
# Place this in your .bashrc | |
# Covers several corner cases such as nested apostrophes, history extraction in screens/subshells, Slack being down, etc. | |
# Strings to replace with your own credentials: | |
## {your email address} (1 instance) | |
## {slack webhook url} (1 instance) | |
## {your computer name} (2 instances) | |
slack() { | |
# Get slack message when a command exits | |
# Example usage: python long_job.py; slack |
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
require 'aws-sdk-dynamodb' | |
require 'erb' | |
DB = Aws::DynamoDB::Client.new | |
Views = Hash[Dir['views/*'].map {|v| [ File.basename(v, '.html.erb').to_sym, ERB.new(File.read(v)) ] }] | |
def list(event:, context:) | |
@rows = DB.scan({ table_name: ENV['TABLE_NAME'] }).result.items | |
{ headers: { 'Content-type' => 'text/html' }, statusCode: 200, body: render { Views[:table].result(binding) } } | |
end |
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
FROM lambci/lambda:build-ruby2.5 | |
WORKDIR /var/task | |
CMD bundle install --path vendor/bundle |
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
# Ruby on Rails Development Environment | |
FROM ruby:2.5.0 | |
# Set up Linux | |
RUN apt-get update | |
RUN apt-get install -y build-essential inotify-tools libpq-dev nodejs postgresql-client | |
WORKDIR /app | |
EXPOSE 3000 |
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
{ | |
"Version": "2012-10-17", | |
"Statement": [ | |
{ | |
"Action": [ | |
"autoscaling:CompleteLifecycleAction", | |
"autoscaling:RecordLifecycleActionHeartbeat" | |
], | |
"Effect": "Allow", | |
"Resource": "*" |
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
# A user session class, a simplified mix of the following code samples: | |
# * https://github.com/blog/1661-modeling-your-app-s-user-session | |
# * http://www.jonathanleighton.com/articles/2013/revocable-sessions-with-devise/ | |
class Session < ActiveRecord::Base | |
# Uncomment if you use Hobo Fields, else add these yourself | |
# fields do | |
# session_id :string, :index => true, :unique => true | |
# accessed_at :datetime | |
# user_ip :string |
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
#!/usr/bin/env ruby | |
require 'sidekiq' | |
require 'sidekiq/cli' | |
# Default to running one process per core | |
def process_count | |
return ENV['SK_PROCESS_COUNT'].to_i unless ENV['SK_PROCESS_COUNT'].to_i == 0 | |
case RbConfig::CONFIG['host_os'] |