Skip to content

Instantly share code, notes, and snippets.

View stympy's full-sized avatar

Benjamin Curtis stympy

View GitHub Profile
@stympy
stympy / slack.sh
Created July 12, 2019 10:24 — forked from naveenarun/slack.sh
Function for sending a verbose slack message (containing path, command, error code, and custom message) after a process or series of processes exit
# 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
@stympy
stympy / handler.rb
Created December 27, 2018 15:38
Get a list of things from DynamoDB and render them in Lambda using Ruby
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
@stympy
stympy / Dockerfile
Last active December 1, 2018 02:31
Example project for using Ruby on AWS Lambda via the Serverless Framework
FROM lambci/lambda:build-ruby2.5
WORKDIR /var/task
CMD bundle install --path vendor/bundle
@stympy
stympy / Dockerfile
Last active February 3, 2018 12:25 — forked from dogweather/Dockerfile
Docker dev environment for Ruby on Rails
# 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
@stympy
stympy / instance-iam-policy.json
Last active April 14, 2022 17:29
Cleanly scaling in instances that are running Sidekiq
{
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"autoscaling:CompleteLifecycleAction",
"autoscaling:RecordLifecycleActionHeartbeat"
],
"Effect": "Allow",
"Resource": "*"
@stympy
stympy / 1 app-models-session.rb
Created March 23, 2017 13:13 — forked from KieranP/1 app-models-session.rb
A Ruby on Rails implementation of a Database and Cookie hybrid session storage for Devise that supports session revocation and storage of session ip and user agent for security (similar to Github)
# 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
@stympy
stympy / skcluster.rb
Created February 8, 2017 20:53
Sidekiq cluster control script and systemd service
#!/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']

Keybase proof

I hereby claim:

  • I am stympy on github.
  • I am ben_curtis (https://keybase.io/ben_curtis) on keybase.
  • I have a public key whose fingerprint is FC63 ED9F FA43 9CD2 F58C 578C 3DDD 5CC4 C993 CF11

To claim this, I am signing this object:

@stympy
stympy / get_secrets.rb
Created October 12, 2016 19:15
Using KMS + S3 to store application secrets
begin
es3 = Aws::S3::Encryption::Client.new(kms_key_id: ENV['KMS_KEY_ID'])
YAML.load(es3.get_object(bucket: "yourbucket", key: "secrets.yml").body.read).each do |k, v|
ENV[k] ||= v # Don't override local ENV settings
end
rescue ArgumentError
# Raised when no KMS_KEY_ID was found in ENV, so there's nothing to do
rescue Aws::S3::Errors::NoSuchKey
# No secrets file was found, so there's nothing to do
end
@stympy
stympy / reload-cores.sh
Created March 2, 2016 21:37
Handy bits and bobs for recovering from a SolrCloud disaster
#!/usr/bin/bash
# We're only processing one solr collection named notices
for x in `seq 1 8`; do
curl "http://localhost:8983/solr/admin/cores?action=UNLOAD&core=notices_shard${x}_replica3
rm -rf /var/lib/solr/data/notices_shard${x}_replica3/*
mkdir -p /var/lib/solr/data/notices_shard${x}_replica3/data