Skip to content

Instantly share code, notes, and snippets.

@sr75
sr75 / csv_to_array
Created August 26, 2011 13:19
csv_to_array
def csv_to_array(file_location)
csv = CSV::parse(File.open(file_location, 'r') {|f| f.read })
fields = csv.shift
csv.collect { |record| Hash[*(0..(fields.length - 1)).collect {|index| [fields[index],record[index].to_s] }.flatten ] }
end
@sr75
sr75 / httpi_fork_perl_shell
Created August 26, 2011 14:36
httpi fork perl process for shell script (.pl,.ksh) file name passed through url
#!/bin/perl
($var_name, $process_name) = split(/=/,$ENV{'QUERY_STRING'});
print "HTTP/1.0 200 OK\r\n";
print "Content-type: text/plain\r\n\r\n";
print "OK";
#print $ENV{'QUERY_STRING'};
$process_path = "";
@sr75
sr75 / spec_helper.rb
Created February 2, 2012 16:24
Example rails 3.1 spec_helper.rb file using spork, rspec, factory_girl, database_cleaner, I18n
require 'spork'
Spork.prefork do
# Loading more in this block will cause your tests to run faster. However,
# if you change any configuration or code from libraries loaded here, you'll
# need to restart spork for it take effect.
# This file is copied to spec/ when you run 'rails generate rspec:install'
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
@sr75
sr75 / rvm-quick-setup.txt
Created March 14, 2012 13:55
rvm quick setup examples
# from your user dir
cd
# create or update .bash_profile
touch .bash_profile
# Install RVM: (https://rvm.io/rvm/install/)
curl -L get.rvm.io | bash -s stable
@sr75
sr75 / parse_decimal_from_string.rb
Created March 21, 2012 13:37
parse decimal from string example method
def parse_decimal_from_string(value)
value.scan(/[-+]?\d*\.?\d+/).join('')
end
@sr75
sr75 / centos6-barebones-vps-rails-server-walkthrough
Last active October 2, 2015 12:38
centos6-barebones-vps-rails-server-walkthrough (rvm, nginx, mysql, memcached)
# CentOS 6.4 barebones walkthrough guide for a new vps rails server instance
# assumes you already have a personal ssh key locally
#
# script implements the following security approaches:
# disables root login
# configures ssh setup for deployer user
# opens up standard ports
#
# setup includes:
# rvm & ruby-1.9.3-p429
@sr75
sr75 / create-mysql-app-user-example.sql
Created April 4, 2012 20:58
create mysql app user example
CREATE USER 'sysadmin'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON `appname_environment`.* TO 'sysadmin'@'localhost';
@sr75
sr75 / Gemfile
Created April 11, 2012 16:06
Refinery + Twitter Bootstrap WIP
source 'https://rubygems.org'
gem 'rails', '3.2.1'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
gem 'sqlite3'
@sr75
sr75 / 0. nginx_setup.sh
Created July 25, 2012 01:46 — forked from mikhailov/0. nginx_setup.sh
Nginx+Unicorn (production-ready setup)
# Nginx optimal congifuration guide.
# We use latest stable nginx with fresh **openssl**, **zlib** and **pcre** dependencies.
# Some extra handy modules to use: --with-http_stub_status_module --with-http_gzip_static_module
$ cd /usr/src
$ wget http://nginx.org/download/nginx-1.2.2.tar.gz
$ tar xzvf ./nginx-1.2.2.tar.gz && rm -f ./nginx-1.2.2.tar.gz
$ wget http://zlib.net/zlib127.zip
@sr75
sr75 / Gemfile
Created July 25, 2012 01:36 — forked from flomotlik/Gemfile
Unicorn config for cedar stack on Heroku.
gem 'unicorn'