Skip to content

Instantly share code, notes, and snippets.

@mlanett
mlanett / Find and Kill Queries.sql
Last active Feb 12, 2020
Find and Kill Queries
View Find and Kill Queries.sql
-- @link https://gist.github.com/rgreenjr/3637525
-- Find queries and optionally kill them.
SELECT pid, age(clock_timestamp(), query_start), usename, waiting, state, query
-- , pg_terminate_backend(pid)
FROM pg_stat_activity
WHERE query LIKE '%Health%'
AND query NOT LIKE 'SELECT pid,%' -- Don't kill this kill query or it will stop killing queries…
AND state != 'idle' -- Idle connections are innocent.
AND usename != 'rdsadmin' -- Can't kill these, don't try.
@mlanett
mlanett / singleton.rb
Created Dec 12, 2014
Singleton fields in Ruby
View singleton.rb
def assert condition
raise unless condition
end
#
# @fields at the class level are singleton fields.
# Singleton fields may be initialized but this is not required.
# Singleton fields can only be accessed by singleton methods.
# Singleton fields are not inherited by subclasses (although singleton methods *are* inherited).
#
@mlanett
mlanett / classy.rb
Last active Aug 29, 2015
Class fields in Ruby
View classy.rb
def assert condition
raise unless condition
end
#
# @@fields are class fields, shared by all instances and all subclasses.
# Class fields MUST be initialized.
# Class fields can be accessed by instance methods.
# Class fields can be accessed by singleton methods.
#
@mlanett
mlanett / fix-bash.sh
Created Sep 29, 2014
Patch Bash to avoid Shellshock exploits (Mac OS X)
View fix-bash.sh
cd /tmp
mkdir bash-fix
cd bash-fix
curl https://opensource.apple.com/tarballs/bash/bash-92.tar.gz | tar zxf -
cd bash-92/bash-3.2
curl https://ftp.gnu.org/pub/gnu/bash/bash-3.2-patches/bash32-052 | patch -p0
@mlanett
mlanett / rails http status codes
Last active Apr 15, 2021
HTTP status code symbols for Rails
View rails http status codes
HTTP status code symbols for Rails
Thanks to Cody Fauser for this list of HTTP responce codes and their Ruby on Rails symbol mappings.
Status Code Symbol
1xx Informational
100 :continue
101 :switching_protocols
102 :processing
@mlanett
mlanett / rspec_helper.rb
Created Sep 22, 2014
Helper to clear redis before/after examples in rspec.
View rspec_helper.rb
=begin
Include in your rspec config like so:
RSpec.configure do |spec|
spec.include RSpec::RedisHelper, redis: true
end
This helper will clean redis around each example.
=end
@mlanett
mlanett / fluent.rb
Last active Aug 29, 2015
Meta-programming for a fluent keyword.
View fluent.rb
# Copyright (c) 2014 Mark Lanett.
# Permission is hereby granted, free of charge, to deal in this software without restriction of any sort.
module Fluent
def self.included(base)
base.extend(ClassSingletonMethods)
end
module ClassSingletonMethods