Skip to content

Instantly share code, notes, and snippets.

View brobertsaz's full-sized avatar

Bob Roberts brobertsaz

  • Self
  • Madison, WI
  • 23:19 (UTC -05:00)
View GitHub Profile
/usr/sbin/update-rc.d -f unicorn defaults
chmod +x /etc/init.d/unicorn
/usr/sbin/update-rc.d -f unicorn remove
@brobertsaz
brobertsaz / _new.html.haml
Created March 20, 2013 16:52
agree_to_terms
= form_tag "/auth/identity/register", id: 'loginform' do
= error_messages_for @identity, :header_message => ""
%table
%tr{colspan: 2}
%td
= label_tag :title
= text_field_tag :title, @identity.try(:title), size: '32', class: 'logininput'
%tr
%td
@brobertsaz
brobertsaz / gist:5121612
Created March 9, 2013 00:16
merge_pdfs_old_school
def merge_pdfs
pdfs = []
pdfs << @bulletin.pdf.path
@bulletin.bulletin_inserts.first.bulletin_insert_items.each do |bii|
if bii.pdf.present?
pdfs << bii.pdf.path
end
end
if pdfs.count > 1
system "gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=temp.pdf #{pdfs.join(' ')}"
upstream myapp {
server unix:///myapp/tmp/puma.sock;
}
server {
listen 80;
server_name myapp.com;
# ~2 seconds is often enough for most folks to parse HTML/CSS and
# retrieve needed images/icons/frames, connections are cheap in
class ProtectedController << ApplicationController
before_filter :force_user
def index
end
private
def force_user
unless session[:user_id]
session[:redirect_url] = request.fullpath
redirect_to new_sessions_path
@brobertsaz
brobertsaz / testing-select2
Created December 19, 2012 18:51
A small script to use for testing rails-select2
click_link "Select"
page.execute_script("i = $('.select2-container input').first();
i.val('"name of first optionin selection"').trigger('keyup');");
find('.select2-results li:first-child').click
@brobertsaz
brobertsaz / serversetup.md
Last active July 6, 2020 08:56
Ubuntu 12.04 Ruby, Rails, Nginx, Unicorn

Ubuntu 12.04, Ruby, Rails, Nginx, Unicorn and git-deploy

In the seemlingly endless search for the actual correct and easy way to deploy a Rails app, we have tried several ways. We tried out using Apache2 and running a cluster of Thin servers. With the built in threading of Puma we decided to use it with Nginx.

Server Setup

  • Create new server
  • Login to new server
    • ssh root@IPaddress (you can also use the domain name if you have the DNS setup already)
    • accept the RSA key
#! /bin/bash
### BEGIN INIT INFO
# Provides: unicorn
# Required-Start: $local_fs $remote_fs $network $syslog
# Required-Stop: $local_fs $remote_fs $network $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts the unicorn web server
# Description: starts unicorn
@brobertsaz
brobertsaz / mysql-setup
Created December 6, 2012 00:11
mysql-setup
sudo apt-get install mysql-server mysql-client libmysqlclient-dev
* If you need to add your user to the mysql database:
mysql -u root
mysql > CREATE USER “username”;
mysql > GRANT ALL ON *.* TO “username”;
@brobertsaz
brobertsaz / nginx-startstop
Created December 6, 2012 00:08
nginx-startstop
sudo /etc/init.d/nginx stop
sudo /etc/init.d/nginx start