This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def split_on_spaces(text,limit,wrapper_id_short=nil,wrapper_id_long=nil) | |
results = text.split(' ') | |
i = 0 | |
short_p = "" | |
long_p = "" | |
while short_p.length < limit && i <= results.count - 1 | |
short_p << results[i] + ' ' | |
i+= 1 | |
end | |
rem = results[i..results.count-1] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class String | |
def escape_single_quotes | |
self.gsub(/[']/, '\\\\\'') | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class BootstrapFormBuilder < ActionView::Helpers::FormBuilder | |
delegate :capture, :content_tag, :tag, to: :@template | |
%w[text_field text_area password_field collection_select email_field].each do |method_name| | |
define_method(method_name) do |name, *args| | |
errors = object.errors[name].any?? " error" : "" | |
error_msg = object.errors[name].any?? content_tag(:span, object.errors[name].join(","), class: "help-inline") : "" | |
content_tag :div, class: "control-group#{errors}" do |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def paginate_linkedin_results(object,per_page=20) | |
# start = if params[:start] then params[:start] else count end | |
@total = object.total | |
@count = if object._count then object._count else per_page end | |
@start = if object._start then object._start else 0 end | |
@total_pages = (@total/per_page.to_f).ceil | |
url = if params[:start] then request.url else request.url + '&start=0' end | |
if @start <= 0 | |
html_prev = content_tag("span", " << Prev ", :class => 'prev_page disabled') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Applies to Rails 2.3 | |
# Since Rails doesn't load classes unless it needs them, you must read the models from the folder. Here is the code | |
Dir[Rails.root.to_s + '/app/models/**/*.rb'].each do |file| | |
begin | |
require file | |
rescue | |
end | |
end | |
Object.subclasses_of(ActiveRecord::Base).each do |model| |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Object.find(:all, :conditions => ["created_at >= ? and created_at < ?", "#{DateTime.now.strftime("%Y-%m-%d")}", "#{(DateTime.now + 1).strftime("%Y-%m-%d")}"]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class String | |
def chunk_by_words(char_count) | |
words = self.split | |
s1_len = 0 | |
word_count = 0 | |
i = 0 | |
while (i <= words.count-1) | |
s1_len += words[i].length | |
word_count += 1 | |
i+=1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Keep your sanity by making a simple change to Dogma config. | |
# Known to be compatible with v0.0.11 | |
# Override the default 80 for max_length and set it to 120 | |
config :dogma, | |
rule_set: Dogma.RuleSet.All, | |
override: %{ LineLength => [ max_length: 120 ] } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Instructions | |
# 1. Download to ~/scripts | |
# 2. chmod u+x ~/scripts/docker_scripts.sh | |
# 3. Add the /scripts into your PATH by including this in your ~/.bashrc `export PATH="$PATH:/$HOME/scripts"` | |
# 4. Open a new terminal and execute `docker_scripts.sh` | |
# 5. Choose from any of the options at the prompt | |
function stop_containers() { | |
id=$(docker ps | awk 'NR > 1 {print $1}' | tr '\n' ' ') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if Rails.env.staging? || Rails.env.production? | |
begin | |
redis_config = YAML.load_file(Rails.root + 'config/redis.yml')[Rails.env] | |
Sidekiq.configure_server do |config| | |
config.redis = { :url => "redis://#{redis_config['host']}:#{redis_config['port']}", :namespace => 'nin' } | |
end | |
# When in Unicorn, this block needs to go in unicorn's `after_fork` callback: | |
Sidekiq.configure_client do |config| |