Skip to content

Instantly share code, notes, and snippets.

View basti's full-sized avatar

Slobodan Kovačević basti

View GitHub Profile
@basti
basti / application.rb
Created May 28, 2013 07:07
Simple username/password protect for whole app.
if ENV['AUTH_USERNAME'].present? && ENV['AUTH_PASSWORD'].present?
config.middleware.insert_after(::Rack::Lock, "::Rack::Auth::Basic", "Staging") do |user, pass|
[user, pass] == [ENV['AUTH_USERNAME'], ENV['AUTH_PASSWORD']]
end
end
@basti
basti / Gemfile
Created May 28, 2013 07:06
Force SSL for some parts of an app with ability to turn it on/off on a server level (ENV var)
# add Rack SSL Enforcer
gem "rack-ssl-enforcer", "~> 0.2.5", :require => 'rack/ssl-enforcer'
@basti
basti / gist:1180385
Created August 30, 2011 07:29
Calculate start/end dates and next week number for given week number
def week_dates( year, week_no )
week_start = Date.commercial( year, week_no, 1 )
week_end = Date.commercial( year, week_no, 7 )
week_start.strftime( "%d/%m/%y" ) + ' - ' + week_end.strftime( "%d/%m/%y" )
end
def next_week_no(year, week_no)
week_start = Date.commercial( year, week_no, 1 )
week_start.advance(:weeks => 1).cweek
end
@basti
basti / migrate_s3.rake
Created August 8, 2011 09:01
rake task to migrate paperclip attachments to Amazon S3
namespace :attachments do
task :migrate_to_s3 => :environment do
require 'aws/s3'
# Load credentials
s3_options = YAML.load_file(File.join(Rails.root, 'config/s3.yml')).symbolize_keys
bucket = s3_options[:bucket_name]
# Establish S3 connection
class News < ActiveRecord::Base
has_many :quotes, :autosave=>true, :dependent=>:destroy, :order => "position"
MAX_QUOTES = 3
before_save :remove_excess_quotes
protected
def remove_excess_quotes

jQuery expert with RoR experience

We are looking for a senior jQuery engineer (2+ years on hard jQuery problems) who really loves a beautiful and polished application.

If you are excited about the new Silicon Valley trend towards gamification, and love working with other great engineers, this is the perfect project for you.

Our engineers have experience with Jquery and ajax. But we are looking for someone who can focus on our most difficult front-end technical problems, and can develop cool (and production ready) features with our UI/UX technical designer.

We have smaller (but still hard) issues needing to be addressed for our march release, and have larger feature development and optimization jquery projects for our june release.

@basti
basti / cm_to_feet_and_inches.rb
Created July 31, 2010 12:34
Convert height/length from cm to feet and inches
def self.cm_to_feet_and_inches(cm)
feet = (cm / 30.48).floor
inches_total = cm / 2.54
inches = (inches_total - (feet * 12)).round
"#{feet} #{inches}"
end
@basti
basti / gist:493710
Created July 28, 2010 07:51
Code to generate model related views and YML files
<%
# generate RHTML/erb code for displaying all model columns
model = YourModel
%>
<ul>
<% model.column_names.each do |col| %>
<li>
< %= <%= model.model_name %>.human_attribute_name("<%= col %>").humanize %>:
< %= @<%= model.model_name.downcase %>.<%= col %> %>
</li>
@basti
basti / paperclip.rb
Created May 30, 2009 18:52 — forked from atog/paperclip.rb
Initializer solution for paperclip and passenger on Mac
# initializer solution for paperclip + passenger combo
# Paperclip::Attachment#post_process => "/tmp/stream.3916.0 is not recognized by the 'identify'
# command" error.
if RAILS_ENV == "development"
Paperclip.options[:command_path] = "/usr/local/bin"
Paperclip.options[:swallow_stderr] = false
end