Skip to content

Instantly share code, notes, and snippets.

Dennis Faust dennisfaust

Block or report user

Report or block dennisfaust

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
dennisfaust / sidekiq_unique_jobs_hash_compactor.rb
Created Jul 12, 2017
sidekiq-unique-jobs gem not deleting expired keys in its uniquejobs hash
View sidekiq_unique_jobs_hash_compactor.rb
# Even worse:
class SidekiqUniqueJobsHashCompactor
include Sidekiq::Worker
sidekiq_options queue: "slow"
def perform
# Skip if there are jobs queued...
return unless { |q| q.size > 100 }.blank?
dennisfaust / session_cookie_manipulation.rb
Last active Mar 2, 2017
Manipulating Rails 3 Session Cookies in Minitest
View session_cookie_manipulation.rb
View gist:9404dd81bb533472a8bbd1b06e12027a
$ set -o vi
$ bind '"\ee": emacs-editing-mode'
Then hit Esc-e
$ bind -P| grep edit
edit-and-execute-command can be found on "\C-x\C-e".
emacs-editing-mode is not bound to any keys
vi-editing-mode is not bound to any keys
dennisfaust / nullstring_example.go
Created Nov 5, 2015 Custom null.string validator example
View nullstring_example.go
// NewNotBlankValidator - given field must be declared as a null.* type. This checks to make sure the
// field value is its zero or null, or filled in but NOT set to empty String
// e.g. {value="", err=false} is not valid.
func NewNotBlankValidator(db *gorm.DB) validator.Func {
return func(v *validator.Validate, topStruct reflect.Value, currentStruct reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool {
switch fieldKind {
case reflect.String:
if field.String() == "" && field.IsValid() {
return false
dennisfaust / gist:f181a8444ded0daef0b8
Created Dec 4, 2014
Convert types on Scala Collections
View gist:f181a8444ded0daef0b8
// TODO: Save this snippet for converting collections:[({type l[_] = collection.immutable.HashMap[UserInformationKind, String]})#l]
dennisfaust / gist:725e81aa02ea2a9f90e7
Created Aug 20, 2014
Ruby: Use a method directly from a module...
View gist:725e81aa02ea2a9f90e7
module Moddy
def show_me
puts "Yop"
# this may come in handy also:
dennisfaust / gist:d657f130c0fe1865ac9b
Last active Aug 29, 2015
Query String, Hash and Params back and forth...
View gist:d657f130c0fe1865ac9b
# To and from hash and params (Rails 4)
str = 'nonce=2147483647&version=2.0&client_id=8iR5q'
h = Rack::Utils.parse_query str
params =
# back to string:
query_str = params.to_query
Rack::Utils.parse_query(query_str) == Rack::Utils.parse_query(str)
dennisfaust / delayed_job_formatted_logger
Created Dec 20, 2013
Formatted log entries from Delayed Job without banging your head...
View delayed_job_formatted_logger
# config/delayed_job_config.rb
Delayed::Worker.logger ='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}")
"#{} [#{progname} #{formatted_severity} pid:#{$$}] #{msg.strip}\n"
dennisfaust / gist:7030268
Created Oct 17, 2013
Rspec for Testing Static Pages in a Ruby on Rails Site
View gist:7030268
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 / ruby_redis_connect.rb
Created Nov 8, 2012
Ruby/Redis Connection - redis-rb doesn't throw an exception until you try to do something...
View ruby_redis_connect.rb
# Check:
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 }
You can’t perform that action at this time.