Skip to content

Instantly share code, notes, and snippets.

mlanett / Find and Kill Queries.sql
Last active Feb 12, 2020
Find and Kill Queries
View Find and Kill Queries.sql
-- @link
-- 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 / singleton.rb
Created Dec 12, 2014
Singleton fields in Ruby
View singleton.rb
def assert condition
raise unless condition
# @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 / classy.rb
Last active Aug 29, 2015
Class fields in Ruby
View classy.rb
def assert condition
raise unless condition
# @@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 /
Created Sep 29, 2014
Patch Bash to avoid Shellshock exploits (Mac OS X)
cd /tmp
mkdir bash-fix
cd bash-fix
curl | tar zxf -
cd bash-92/bash-3.2
curl | patch -p0
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 / rspec_helper.rb
Created Sep 22, 2014
Helper to clear redis before/after examples in rspec.
View rspec_helper.rb
Include in your rspec config like so:
RSpec.configure do |spec|
spec.include RSpec::RedisHelper, redis: true
This helper will clean redis around each example.
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)
module ClassSingletonMethods