Skip to content

Instantly share code, notes, and snippets.

View inopinatus's full-sized avatar
🐼
fuzzy logic

Josh Goodall inopinatus

🐼
fuzzy logic
View GitHub Profile
@inopinatus
inopinatus / eydeploy.rb
Created August 28, 2011 08:57 — forked from mutle/gist:1175364
no maintenance page unless we're migrating. who needs grep?
# no maint page unless migrations are required
def conditionally_enable_maintenance_page
super if required_downtime_stack?
if c.migrate?
info "~> testing necessity for migrations & maintenance page"
if `cd #{c.release_path} && bundle exec rake db:migrate:status`.scan(/^\s*down/).size > 0
info "~> migrations pending, maintenance page required"
@inopinatus
inopinatus / hstore_accessor.rb
Last active June 29, 2024 17:26
hstore accessor class method for AR
# include from an initializer
module HstoreAccessor
def self.included(base)
base.extend(ClassMethods)
end
module ClassMethods
def hstore_accessor(hstore_attribute, *keys)
Array(keys).flatten.each do |key|
@inopinatus
inopinatus / gist:3051871
Created July 5, 2012 06:46
Can't remember what this does, looks like it takes Debian package status as input
#!/usr/bin/perl -l
# written in "hasty" perl, my apologies.
use Data::Dumper;
use strict;
use vars qw($p $m $n $d $k $h $l);
# excuse to abuse the schwartzian later on
#!/usr/bin/perl
use strict;
use integer;
sub dqtoint ($) {
my $dq = shift;
return unpack('N', pack('CCCC', split(/\./, $dq, 4)));
}
@inopinatus
inopinatus / numtoprefix.pl
Created July 5, 2012 06:51
inetnum to prefix
#!/usr/bin/perl
use strict;
use integer;
my %sizeprefix = ();
for my $i (0..32) {
$sizeprefix{2**(32-$i)} = $i; # can't use 1<<32
}
@inopinatus
inopinatus / hstore_array_test.rb
Last active December 19, 2015 09:09
hstore array test code
require 'bundler'
Bundler.setup(:default)
require 'active_record'
require 'minitest/autorun'
require 'logger'
ActiveRecord::Base.establish_connection(adapter: 'postgresql', database: 'testapp_development')
ActiveRecord::Base.logger = Logger.new(STDOUT)
console.log('Loading function');
const https = require('https');
const url = require('url');
const slack_url = 'https://hooks.slack.com/services/...';
const slack_req_opts = url.parse(slack_url);
slack_req_opts.method = 'POST';
slack_req_opts.headers = {
'Content-Type': 'application/json'
};
Stethoscope.url = "/stethoscope_myapp_ae53unit"
Stethoscope.check :database do |resp|
resp[:last_migration] = ActiveRecord::Migrator.current_version
resp[:pg_version] = ActiveRecord::Base.connection.select_value('SELECT version()')
end
Stethoscope.check :release do |resp|
resp[:version] = "#{MyApp.config.version} (#{Rails.env})"
resp[:git_revision] = `git rev-parse HEAD`.chomp
@inopinatus
inopinatus / rails-model-templates.rb
Last active July 20, 2017 22:42
Rails model templates, concept sketch
require "active_record"
require "sqlite3"
require "minitest/autorun"
require "logger"
require "pp"
ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: ":memory:")
ActiveRecord::Base.logger = Logger.new(STDOUT)
ActiveRecord::Schema.define do
@inopinatus
inopinatus / path_resolver_dir_glob_cache.rb
Last active June 1, 2018 23:30
Temporary workaround for Rails globbing performance issue https://github.com/rails/rails/issues/30502
# frozen_string_literal: true
# config/initializers/path_resolver_dir_glob_cache.rb
#
# Work around glob performance woes for JS requests in development, c.f
# https://github.com/rails/rails/issues/30502, by
# prepending ActionView::PathResolver#find_template_paths to use a
# result cache. Cache invalidation via fs listeners.
# Use at your own peril.