Skip to content

Instantly share code, notes, and snippets.

View mlanett's full-sized avatar

Mark Lanett mlanett

View GitHub Profile
@mlanett
mlanett / fluent.rb
Last active August 29, 2015 14:06
Meta-programming for a fluent keyword.
# 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
@mlanett
mlanett / fix-bash.sh
Created September 29, 2014 18:43
Patch Bash to avoid Shellshock exploits (Mac OS X)
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 / classy.rb
Last active August 29, 2015 14:11
Class fields in Ruby
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 / singleton.rb
Created December 12, 2014 22:44
Singleton fields in Ruby
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 / Find and Kill Queries.sql
Last active October 18, 2022 02:42
Find and Kill Queries
SELECT pid,
age(clock_timestamp(), query_start),
usename,
state,
-- get rid of newlines, runs of spaces
regexp_replace(query, E'[\\n\\r ]+', ' ', 'g' ) as query
-- , pg_terminate_backend(pid) -- UNCOMMENT TO KILL
FROM pg_stat_activity
#!/usr/bin/env python
# Derived from https://github.com/apangin/jstackmem/blob/master/jstackmem.py
import bisect
import re
import subprocess
import sys
if len(sys.argv) < 2:
print("Calculate stack memory used by a Java process")
print("Usage: python jstackmem.py <pid>")
@mlanett
mlanett / rspec_helper.rb
Created September 22, 2014 04:23
Helper to clear redis before/after examples in rspec.
=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 / rails http status codes
Last active December 6, 2024 20:12
HTTP status code symbols for Rails
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