Skip to content

Instantly share code, notes, and snippets.

Avatar
🐼
fuzzy logic

Josh Goodall inopinatus

🐼
fuzzy logic
View GitHub Profile
@inopinatus
inopinatus / eydeploy.rb
Created Aug 28, 2011 — forked from mutle/gist:1175364
no maintenance page unless we're migrating. who needs grep?
View eydeploy.rb
# 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 / gist:3051871
Created Jul 5, 2012
Can't remember what this does, looks like it takes Debian package status as input
View gist:3051871
#!/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
View numtoprefix.pl
#!/usr/bin/perl
use strict;
use integer;
my %sizeprefix = ();
for my $i (0..32) {
$sizeprefix{2**(32-$i)} = $i; # can't use 1<<32
}
View prefixtest.pl
#!/usr/bin/perl
use strict;
use integer;
sub dqtoint ($) {
my $dq = shift;
return unpack('N', pack('CCCC', split(/\./, $dq, 4)));
}
View aws-slack-notify.js
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'
};
@inopinatus
inopinatus / hstore_array_test.rb
Last active Dec 19, 2015
hstore array test code
View hstore_array_test.rb
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)
@inopinatus
inopinatus / rails-model-templates.rb
Last active Jul 20, 2017
Rails model templates, concept sketch
View rails-model-templates.rb
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
View stethoscope.rb
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 / ackermann.rb
Created Jun 1, 2018
Ackermann function in one line of Ruby as a hash default proc
View ackermann.rb
A = Hash.new { |a,(m,n)| a[[m,n]] = m==0 ? n+1 : n==0 ? a[[m-1,1]] : a[[m-1, a[[m, n-1]]]] } #=> {}
A[[3,4]] #=> 125
A.inspect #=> ... long
@inopinatus
inopinatus / path_resolver_dir_glob_cache.rb
Last active Jun 1, 2018
Temporary workaround for Rails globbing performance issue https://github.com/rails/rails/issues/30502
View path_resolver_dir_glob_cache.rb
# 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.