Skip to content

Instantly share code, notes, and snippets.

@sr75
sr75 / wildcard-ssl-cert-for-testing-nginx-conf.md
Created June 1, 2013 18:35
create a self signed wildcard ssl cert for testing with nginx.conf example

just change out app_name for your purposes

openssl genrsa 2048 > app_name-wildcard.key

openssl req -new -x509 -nodes -sha1 -days 3650 -key app_name-wildcard.key > app_name-wildcard.cert

# Common Name (eg, your name or your server's hostname) []:*.app_name.com

openssl x509 -noout -fingerprint -text < app_name-wildcard.cert > app_name-wildcard.info
@sr75
sr75 / submission_form_helper.rb
Created May 29, 2013 06:45
How to override default rails ActionView::Base.field_error_proc for individual form builders
module SubmissionFormHelper
# Override the default ActiveRecordHelper behaviour of wrapping the input.
# This gets taken care of semantically by adding an error class to the wrapper tag
# containing the input.
#
FIELD_ERROR_PROC = proc do |html_tag, instance_tag|
html_tag
end
@sr75
sr75 / mysql_max_text_limits_active_record.rb
Created April 15, 2013 15:09
mysql 5.6 rails active_record migration text max lengths for a database created with utf8
# just an active_record migration example for reference
# source of this logic: https://github.com/rails/rails/blob/master/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb
class CreateMetaTexts < ActiveRecord::Migration
def up
create_table :meta_texts do |t|
t.text :default_text_63KB, limit: 63.kilobytes # 64512 < 65535 limit for when text datatype changes to mediumtext datatype
t.text :medium_text_64KB, limit: 64.kilobytes # 65536 > 65535 limit and triggers text datatype to mediumtext datatype
t.text :medium_text_15MB, limit: 15.megabytes # 15728640 < 16777215 limit for when mediumtext changes to longtext datatype
@sr75
sr75 / my.cnf
Created April 14, 2013 17:41
Optimized my.cnf for mysql server when setting up physical servers or vps. Configured for 2GB of memory allocated to the mysql process. Adjust connections and max memory for larger setups with more available memory.
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# The maximum amount of concurrent sessions the MySQL server will
# allow. One of these connections will be reserved for a user with
# SUPER privileges to allow the administrator to login even if the
@sr75
sr75 / rvm_ruby2_rails4_example.txt
Last active December 15, 2015 07:29
Install rails 4.0 with ruby 2.0.0 using RVM & brew
# important update xcode to 4.6 and make sure command line tools are installed under preferences
ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go)"
# if brew is already installed update existing
brew update
brew tap homebrew/dupes
# For rvm:
brew install bash curl git
@sr75
sr75 / ExampleViewController.m
Last active December 13, 2015 17:09
Load nib/xib for iphone 5 / Retina 4 Full Screen (568h) custom views, but then default back to ios universal naming conventions (~iphone/~ipad).
#import "UIViewController+AppCategories.h"
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
nibNameOrNil = [UIViewController nibNamedForDevice:@"ExampleViewController"];
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Do any additional customization
@sr75
sr75 / vagrant.org
Created January 24, 2013 20:34 — forked from akiatoji/vagrant.org

Installing CentOS

Download net install iso: CentOS-6.2-x86_64-netinstall.iso

Create a new VirtualBox machine

  • Name: vagrant-centos
  • Operating System: Linux
  • Version: Red Hat
@sr75
sr75 / testing-subdomains-cucumber-capybara.md
Created January 6, 2013 07:09
Express guide to a rails 3.2+ testing custom subdomains using cucumber capybara with pow setup... along with devise mailer config helper (only useful when needing to test custom subdomains in your rails app).

Express guide to a rails 3.2+ testing custom app subdomains using cucumber capybara with a pow setup... along with devise mailer config helper example (useful if you need to test various auth situations for custom subdomains in a rails app).

If you haven't used pow, I wouldn't recommend it for local web dev... there's much better gems for local web dev like unicorn-rails or passenger nginx standalone are far better choices IMHO. I use pow for all the local name redirects to a port like explained below, with a rails dev server listening on that port running unicorn-rails.

So we're going to use it for the awesome subdomain redirect to a local customapp.dev on a specific port magic mojo.

First install pow.cx

  • now go to pow.cx and install
  • cd ~/.pow
@sr75
sr75 / wordpress-htaccess-rewrite
Created December 27, 2012 16:03
wordpress htaccess rewrite to subfolder of install
# BEGIN Custom
Options -Indexes
RewriteEngine On
RewriteCond $1 !^wordpress/
RewriteRule ^(.*)$ wordpress/$1 [L]
# END Custom
# 4 workers is enough for our app
worker_processes 4
# App location
@app = "/var/rails/myapp/current"
# Listen on fs socket for better performance
listen "#{@app}/tmp/sockets/unicorn.sock", :backlog => 64
# Nuke workers after 30 seconds instead of 60 seconds (the default)