<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Ruby on Major Hayden</title><link>https://major.io/tags/ruby/</link><description>Recent content in Ruby on Major Hayden</description><generator>Hugo</generator><language>en</language><managingEditor>major@mhtx.net (Major Hayden)</managingEditor><webMaster>major@mhtx.net (Major Hayden)</webMaster><copyright>All content licensed &lt;a href="https://creativecommons.org/licenses/by-sa/4.0/"&gt;CC BY-SA 4.0&lt;/a&gt;</copyright><lastBuildDate>Wed, 05 Aug 2026 12:23:48 -0500</lastBuildDate><atom:link href="https://major.io/tags/ruby/index.xml" rel="self" type="application/rss+xml"/><item><title>Quickly post gists to GitHub Enterprise and github.com</title><link>https://major.io/p/use-gist-gem-github-enterprise-github-com/</link><pubDate>Fri, 08 Aug 2014 21:13:07 +0000</pubDate><author>major@mhtx.net (Major Hayden)</author><guid>https://major.io/p/use-gist-gem-github-enterprise-github-com/</guid><description>&lt;p&gt;&lt;a href="https://major.io/wp-content/uploads/2014/08/github.png"&gt;&lt;img src="https://major.io/wp-content/uploads/2014/08/github-150x150.png" alt="GitHub Logo" width="150" height="150" class="alignright size-thumbnail wp-image-5124" srcset="https://major.io/wp-content/uploads/2014/08/github-150x150.png 150w, https://major.io/wp-content/uploads/2014/08/github-300x300.png 300w, https://major.io/wp-content/uploads/2014/08/github.png 560w" sizes="(max-width: 150px) 100vw, 150px" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;The &lt;a href="https://github.com/defunkt/gist"&gt;gist gem&lt;/a&gt; from GitHub allows you to quickly post text into a GitHub gist. You can use it with the public github.com site but you can also &lt;a href="https://github.com/defunkt/gist#github-enterprise"&gt;configure it&lt;/a&gt; to work with a GitHub Enterprise installation.&lt;/p&gt;
&lt;p&gt;To get started, add two aliases to your &lt;code&gt;~/.bashrc&lt;/code&gt;:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;alias gist=&amp;#34;gist -c&amp;#34;
alias workgist=&amp;#34;GITHUB_URL=https://github.mycompany.com gist -c&amp;#34;
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The &lt;code&gt;-c&lt;/code&gt; will copy the link to the gist to your keyboard whenever you use the gist tool on the command line. Now, go through the login process with each command after sourcing your updated &lt;code&gt;~/.bashrc&lt;/code&gt;:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;source ~/.bashrc
gist --login
(follow the prompts to auth and get an oauth token from github.com)
workgist --login
(follow the prompts to auth and get an oauth token from GitHub Enterprise)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;You&amp;rsquo;ll now be able to use both aliases quickly from the command line:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;cat boring_public_data.txt | gist
cat super_sensitive_company_script.sh | workgist
&lt;/code&gt;&lt;/pre&gt;</description></item><item><title>Getting apache, PHP, and memcached working with SELinux</title><link>https://major.io/p/getting-apache-php-and-memcached-working-with-selinux/</link><pubDate>Thu, 08 Sep 2011 03:55:00 +0000</pubDate><author>major@mhtx.net (Major Hayden)</author><guid>https://major.io/p/getting-apache-php-and-memcached-working-with-selinux/</guid><description>&lt;p&gt;&lt;img src="https://major.io/wp-content/uploads/2011/09/selinux-penguin-125.png" alt="1"&gt;&lt;/p&gt;
&lt;p&gt;I&amp;rsquo;m using SELinux more often now on my Fedora 15 installations and I came up against a peculiar issue today on a new server. My PHP installation is configured to store its sessions in memcached and I brought over some working configurations from another server. However, each time I accessed a page which tried to initiate a session, the page load would hang for about a minute and I&amp;rsquo;d find this in my apache error logs:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;[Thu Sep 08 03:23:40 2011] [error] [client 11.22.33.44] PHP Warning:
Unknown: Failed to write session data (memcached). Please verify that
the current setting of session.save_path is correct (127.0.0.1:11211)
in Unknown on line 0
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;I ran through my usual list of checks:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;netstat showed memcached bound to the correct ports/interfaces&lt;/li&gt;
&lt;li&gt;memcached was running and I could reach it via telnet&lt;/li&gt;
&lt;li&gt;memcached-tool could connect and pull stats from memcached&lt;/li&gt;
&lt;li&gt;double-checked my php.ini&lt;/li&gt;
&lt;li&gt;tested memcached connectivity via a PHP and ruby script - they worked&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Even after all that, I still couldn&amp;rsquo;t figure out what was wrong. I ran strace on memcached while I ran a curl against the page which creates a session and I found something significant - memcached wasn&amp;rsquo;t seeing any connections whatsoever at that time. A quick check of the lo interface with tcpdump showed the same result. Just before I threw a chair, I remembered one thing:&lt;/p&gt;
&lt;p&gt;&lt;em&gt;SELinux.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;A quick check for AVC denials showed the problem:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;# aureport --avc | tail -n 1
4021. 09/08/2011 03:23:38 httpd system_u:system_r:httpd_t:s0 42 tcp_socket name_connect system_u:object_r:memcache_port_t:s0 denied 31536
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;I&amp;rsquo;m far from being a guru on SELinux, so I leaned on audit2allow for help:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;# grep memcache /var/log/audit/audit.log | audit2allow

#============= httpd_t ==============
#!!!! This avc can be allowed using one of the these booleans:
# httpd_can_network_relay, httpd_can_network_memcache, httpd_can_network_connect

allow httpd_t memcache_port_t:tcp_socket name_connect;
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The boolean we&amp;rsquo;re looking for is &lt;code&gt;httpd_can_network_memcache&lt;/code&gt;. Flipping the boolean can be done in a snap:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;# setsebool -P httpd_can_network_memcache 1
# getsebool httpd_can_network_memcache
httpd_can_network_memcache --&amp;gt; on
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;After adjusting the boolean, apache was able to make connections to memcached without a hitch. My page which created sessions loaded quickly and I could see data being stored in memcached. If you want to check the status of all of the apache-related SELinux booleans, just use getsebool:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;# getsebool -a | grep httpd | grep off$
allow_httpd_anon_write --&amp;gt; off
allow_httpd_mod_auth_ntlm_winbind --&amp;gt; off
allow_httpd_mod_auth_pam --&amp;gt; off
allow_httpd_sys_script_anon_write --&amp;gt; off
httpd_can_check_spam --&amp;gt; off
httpd_can_network_connect_cobbler --&amp;gt; off
httpd_can_network_connect_db --&amp;gt; off
httpd_can_network_relay --&amp;gt; off
httpd_can_sendmail --&amp;gt; off
httpd_dbus_avahi --&amp;gt; off
httpd_enable_ftp_server --&amp;gt; off
httpd_enable_homedirs --&amp;gt; off
httpd_execmem --&amp;gt; off
httpd_read_user_content --&amp;gt; off
httpd_setrlimit --&amp;gt; off
httpd_ssi_exec --&amp;gt; off
httpd_tmp_exec --&amp;gt; off
httpd_unified --&amp;gt; off
httpd_use_cifs --&amp;gt; off
httpd_use_gpg --&amp;gt; off
httpd_use_nfs --&amp;gt; off
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;If you&amp;rsquo;re interested in SELinux, a good way to get your feet wet is to head over to the CentOS Wiki and review their &lt;a href="http://wiki.centos.org/HowTos/SELinux"&gt;SELinux Howtos&lt;/a&gt;&lt;/p&gt;</description></item><item><title>Idiot’s guide to OAuth logins for Twitter</title><link>https://major.io/p/idiots-guide-to-oauth-logins-for-twitter/</link><pubDate>Thu, 20 May 2010 01:26:07 +0000</pubDate><author>major@mhtx.net (Major Hayden)</author><guid>https://major.io/p/idiots-guide-to-oauth-logins-for-twitter/</guid><description>&lt;p&gt;It certainly shouldn&amp;rsquo;t be difficult, but I always have a tough time with &lt;a href="http://en.wikipedia.org/wiki/OAuth"&gt;OAuth&lt;/a&gt;. Twitter is &lt;a href="http://apiwiki.twitter.com/OAuth-FAQ#WhenareyougoingtoturnoffBasicAuth"&gt;dropping support for basic authentication&lt;/a&gt; on &lt;a href="http://countdowntooauth.com/"&gt;June 30th, 2010&lt;/a&gt;. I have some automated Twitter bots that need an upgrade, so I&amp;rsquo;ve been working on a quick solution to generate tokens for my scripts.&lt;/p&gt;
&lt;p&gt;I formulated a pretty simple script using &lt;a href="http://twitter.rubyforge.org/"&gt;John Nunemaker&amp;rsquo;s twitter gem&lt;/a&gt; that will get it done manually for any scripts you have that read from or update Twitter:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;#!/usr/bin/ruby
require &amp;#39;rubygems&amp;#39;
require &amp;#39;twitter&amp;#39;

# These credentials are specific to your *application* and not your *user*
# Get these credentials from Twitter directly: http://twitter.com/apps
application_token = &amp;#39;[this should be the shorter one]&amp;#39;
application_secret = &amp;#39;[this should be the longer one]&amp;#39;

oauth = Twitter::OAuth.new(application_token,application_secret)

request_token = oauth.request_token.token
request_secret = oauth.request_token.secret
puts &amp;#34;Request token =&amp;gt; #{request_token}&amp;#34;
puts &amp;#34;Request secret =&amp;gt; #{request_secret}&amp;#34;
puts &amp;#34;Authentication URL =&amp;gt; #{oauth.request_token.authorize_url}&amp;#34;

print &amp;#34;Provide the PIN that Twitter gave you here: &amp;#34;
pin = gets.chomp

oauth.authorize_from_request(request_token,request_secret,pin)
access_token = oauth.access_token.token
access_secret = oauth.access_token.secret
puts &amp;#34;Access token =&amp;gt; #{oauth.access_token.token}&amp;#34;
puts &amp;#34;Access secret =&amp;gt; #{oauth.access_token.secret}&amp;#34;

oauth.authorize_from_access(access_token, access_secret)
twitter = Twitter::Base.new(oauth)
puts twitter.friends_timeline(:count =&amp;gt; 1)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;When you run the script, it will give you a request token, request secret and a URL to visit. When you access the URL, you&amp;rsquo;ll be given a PIN. Type the PIN into the prompt and you&amp;rsquo;ll get your access token and secret. This is what you can use to continue authenticating with Twitter, so be sure to save the access token and secret.&lt;/p&gt;
&lt;p&gt;From then on, you should be able to login with a script like this:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;#!/usr/bin/ruby
require &amp;#39;rubygems&amp;#39;
require &amp;#39;twitter&amp;#39;

application_token = &amp;#39;[this should be the shorter one]&amp;#39;
application_secret = &amp;#39;[this should be the longer one]&amp;#39;

oauth = Twitter::OAuth.new(application_token,application_secret)

oauth.authorize_from_access(access_token, access_secret)
twitter = Twitter::Base.new(oauth)
puts twitter.friends_timeline(:count =&amp;gt; 1)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;I hope this helps!&lt;/p&gt;</description></item><item><title>Rotating rails logs when using Phusion Passenger</title><link>https://major.io/p/rotating-rails-logs-when-using-phusion-passenger/</link><pubDate>Fri, 26 Jun 2009 15:09:54 +0000</pubDate><author>major@mhtx.net (Major Hayden)</author><guid>https://major.io/p/rotating-rails-logs-when-using-phusion-passenger/</guid><description>&lt;p&gt;I found a &lt;a href="http://overstimulate.com/articles/logrotate-rails-passenger"&gt;great post&lt;/a&gt; on &lt;a href="http://overstimulate.com/"&gt;Overstimulate&lt;/a&gt; about handling the rotation of rails logs when you use Phusion Passenger. Most of the data for your application should end up in the apache logs, but if your site is highly dynamic, you may end up with a giant production log if you&amp;rsquo;re not careful.&lt;/p&gt;
&lt;p&gt;Toss this into /etc/logrotate.d/yourrailsapplication:&lt;/p&gt;
&lt;pre lang="html"&gt;/var/www/yourrailsapp/log/*.log {
 daily
 missingok
 rotate 30
 compress
 delaycompress
 sharedscripts
 postrotate
 touch /var/www/yourrailsapp/tmp/restart.txt
 endscript
}&lt;/pre&gt;
&lt;p&gt;For a detailed explanation, &lt;a href="http://overstimulate.com/articles/logrotate-rails-passenger"&gt;see the post&lt;/a&gt; on &lt;a href="http://overstimulate.com/"&gt;Overstimulate&lt;/a&gt;.&lt;/p&gt;</description></item><item><title>Writing a Ruby on Rails application without using a database</title><link>https://major.io/p/writing-a-ruby-on-rails-application-without-using-a-database/</link><pubDate>Fri, 09 Jan 2009 17:00:44 +0000</pubDate><author>major@mhtx.net (Major Hayden)</author><guid>https://major.io/p/writing-a-ruby-on-rails-application-without-using-a-database/</guid><description>&lt;p&gt;Some of you may be wondering “why would you want to use Rails without a database?” There are several situations why a database would not be needed, and I&amp;rsquo;ve run into quite a few of them. One of the specific cases was when I wanted to write a web interface for an application that only had a REST interface available to the public.&lt;/p&gt;
&lt;p&gt;If you find yourself needing to write a Rails application without a database, just do the following:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;For Rails 1.0 and up:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;code&gt;config/environment.rb&lt;/code&gt;:&lt;/p&gt;
&lt;pre lang="rails"&gt;config.frameworks -= [ :active_record ]&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;test/test_helper.rb&lt;/code&gt;&lt;/p&gt;
&lt;pre lang="rails"&gt;class Test::Unit::TestCase
 self.use_transactional_fixtures = false
 self.use_instantiated_fixtures = false
 def load_fixtures
 end
end&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;For Rails 2.1 and up:&lt;/strong&gt; Comment out both of the lines that begin with &lt;code&gt;ActiveRecord::Base&lt;/code&gt; in &lt;code&gt;config/initializers/new_rails_defaults.rb&lt;/code&gt;:&lt;/p&gt;
&lt;pre lang="rails"&gt;if defined?(ActiveRecord)
 # Include Active Record class name as root for JSON serialized output.
 # ActiveRecord::Base.include_root_in_json = true

 # Store the full class name (including module namespace) in STI type column.
 # ActiveRecord::Base.store_full_sti_class = true
end
&lt;/pre&gt;
&lt;p&gt;For more details, review the &lt;a href="http://wiki.rubyonrails.org/rails/pages/HowToUseRailsWithoutADatabase"&gt;full article&lt;/a&gt; on &lt;a href="http://rubyonrails.org"&gt;rubyonrails.org&lt;/a&gt;.&lt;/p&gt;</description></item><item><title>Viewing documentation for your ruby gems</title><link>https://major.io/p/viewing-documentation-for-your-ruby-gems/</link><pubDate>Thu, 06 Nov 2008 00:14:57 +0000</pubDate><author>major@mhtx.net (Major Hayden)</author><guid>https://major.io/p/viewing-documentation-for-your-ruby-gems/</guid><description>&lt;p&gt;I stumbled into this four line ruby script that will serve up all of the rdoc documentation for your server&amp;rsquo;s currently installed gems:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;#!/usr/bin/env ruby
require &amp;#34;rubygems/server&amp;#34;
options = {:gemdir =&amp;gt; Gem.dir, :port =&amp;gt; 4242, :daemon =&amp;gt; true}
Gem::Server::run(options)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;&lt;em&gt;Thanks to Daniel for the ruby code!&lt;/em&gt;&lt;/p&gt;</description></item></channel></rss>