Skip to content

Instantly share code, notes, and snippets.

View dennisfaust's full-sized avatar

Dennis Faust dennisfaust

View GitHub Profile
@dennisfaust
dennisfaust / Pingdom_http_custom_check
Created April 14, 2011 20:53
Pingdom supports http custom checks via XML. This is a ruby code snippet which checks a file's timestamp and returns OK if it's recent enough. http://royal.pingdom.com/2008/07/14/new-pingdom-feature-custom-monitoring-type/
#!/usr/bin/ruby
# Pingdom_http_custom_check
# DFF - 2011
# put this in {Apache Files}/cgi-bin/
# make sure to chmod +x the file
# Your ruby interpreter might not be where mine is. Check the above.
#
require 'cgi'
too_old=360
@dennisfaust
dennisfaust / Mongodb_secondary_lag
Created July 15, 2011 00:08
Script to create a MongoDB Collectd Plugin - Works with RightScale's monitoring and alerts
#!/bin/bash -ex
#
# Description: Graph how old the last sync was between primary and secondary mongo instances.
#
# Base code and idea thanks to: Edward M. Goldberg
#
# any mistakes courtesy of: Dennis Faust
#
if [ $RS_DISTRO = ubuntu ]; then
plugin_dir="/etc/collectd/conf"
@dennisfaust
dennisfaust / apache_basic_rewrite
Created July 26, 2011 23:07
Apache Basic Authentication for a Rewrite Condition Not a Directory
# Apache Basic Authentication for A Rewrite Condition not a Directory
#
# NOTE: Locations work off of URLs not directories
#
# Put this in your virtualhost block
#
<Location /YOUR_URL_PATH/>
AuthType Basic
AuthName "Authorization Required."
AuthUserFile /etc/httpd/conf/htpasswd
@dennisfaust
dennisfaust / DesEncrypter.scala
Created February 23, 2012 22:08
Triple DES (3DES) Encryption for Scala - adapted from exampledepot java
import com.sun.org.apache.xml.internal.security.utils.Base64
import javax.crypto._
import javax.crypto.spec._
import java.security.spec._
import java.io._
import java.security.{NoSuchAlgorithmException, InvalidAlgorithmParameterException}
import javax.management.openmbean.InvalidKeyException
import com.sun.org.apache.xml.internal.security.exceptions.Base64DecodingException
import play.api.Logger
@dennisfaust
dennisfaust / etc_init_god.conf
Created November 8, 2012 19:37
Using Upstart to keep God process monitor up under RVM
# god upstart service
description "God process monitoring"
# When to start and stop the service
start on runlevel [2345]
stop on runlevel [016]
# Automatically restart process if crashed
kill timeout 20
respawn
@dennisfaust
dennisfaust / ruby_redis_connect.rb
Created November 8, 2012 22:55
Ruby/Redis Connection - redis-rb doesn't throw an exception until you try to do something...
#
# Check: http://redis-rb.keyvalue.org/v2.2.0/
#
if Redis_connect
case Rails.env
when "production"
opts = {:host => "YOUR HOST NAME OR IP", :port => "6379", :thread_safe => true }
when "staging"
opts = {:host => "YOUR HOST NAME OR IP", :port => "6379", :thread_safe => true }
else
@dennisfaust
dennisfaust / gist:7030268
Created October 17, 2013 18:54
Rspec for Testing Static Pages in a Ruby on Rails Site
describe "StaticPages", type: :feature do
header_links = [
{ name: 'Sign Up', link: '/signup', text: 'Contacts associated with purchases' },
{ name: 'Log In', link: '/login', text: 'Forgot your user name or password?' }
]
footer_links = [
{ name: 'Home', link: '/', text: 'Easily and efficiently track'},
{ name: 'Plans & Pricing', link: '/plan', text: 'Standard Features'},
@dennisfaust
dennisfaust / delayed_job_formatted_logger
Created December 20, 2013 01:57
Formatted log entries from Delayed Job without banging your head...
#
# config/delayed_job_config.rb
#
Delayed::Worker.logger = Logger.new(Rails.root.join('log', 'delayed_job.log'))
# The base logger is terrible. It only puts what you send. Nothing else. So I had to dig this up and add it.
class DJFormatter
def call(severity, time, progname, msg)
formatted_severity = sprintf("%-5s","#{severity}")
"#{Time.now.utc} [#{progname} #{formatted_severity} pid:#{$$}] #{msg.strip}\n"
@dennisfaust
dennisfaust / gist:d657f130c0fe1865ac9b
Last active August 29, 2015 14:03
Query String, Hash and Params back and forth...
# To and from hash and params (Rails 4)
str = 'nonce=2147483647&version=2.0&client_id=8iR5q'
h = Rack::Utils.parse_query str
params = ActiveSupport::HashWithIndifferentAccess.new(h)
# back to string:
query_str = params.to_query
Rack::Utils.parse_query(query_str) == Rack::Utils.parse_query(str)
@dennisfaust
dennisfaust / gist:725e81aa02ea2a9f90e7
Created August 20, 2014 20:51
Ruby: Use a method directly from a module...
module Moddy
def show_me
puts "Yop"
end
end
Class.new.extend(Moddy).show_me
Yop
# this may come in handy also: