Skip to content

Instantly share code, notes, and snippets.

View Rio517's full-sized avatar

Mario Olivio Flores Rio517

View GitHub Profile
#
# Paperclip convert id => id_partition
#
require 'ftools' #FileUtils
class PaperclipExtend
def self.obtain_class
class_name = ENV['CLASS'] || ENV['class']
uploads_path = ENV['UPLOADS_PATH'] || ENV['uploads_path']
raise "Must specify CLASS" unless class_name
@Rio517
Rio517 / file.rb
Created April 15, 2011 03:47
This is from the activo-rails gem
module Activo
module Rails
module Helper
# Displays a breadcrumb trail
#
# options - A hash of attributes to apply to the wrapping div tag
#
# Example:
# <div class="block">
@Rio517
Rio517 / fuzzy matching from
Created April 29, 2011 16:16
fuzzymatch.rb
#http://rcoder.net/content/testing-string-similarity-using-ruby-and-zlib
#see also: http://www.postgresql.org/docs/8.3/static/fuzzystrmatch.html
#see also: http://flori.github.com/amatch/
require 'zlib'
# this is optimized to store a relatively smaller subset of common index
# terms against which new strings should be tested
class ZlibDistanceCalc
def initialize
@Rio517
Rio517 / elasticsearch.yml
Created September 28, 2011 17:22
elasticsearch configuration fail
#/usr/local/elasticsearch/elasticsearch-0.17.7/logger.yml/elasticsearch.yml
# The cluster name
cluster.name: traceful_elasticsearch
cloud:
aws:
access_key: AKIAIPILOGJA7ORIBDNQ
secret_key: sdyXUTxPqDTL7vr2axB7Ufa1ikFqmAR+J63FgYAJ
@Rio517
Rio517 / show.html.erb
Created October 17, 2011 01:27
Stripe.com api feedback example
<% count = 1 %>
<% if @invoice.lines.subscriptions.any? %>
<% @invoice.lines.subscriptions.each do |subscription| -%>
<tr class="<%= count % 2 == 0 ? 'even' : 'odd' %>">
<td class="first"><%= format_unix_time(subscription.period.end) %></td>
<td><%= subscription.plan.name %> subscription from <%= format_unix_time(subscription.period.start) %> to <%= format_unix_time(subscription.period.end) %></td>
<td><%= number_to_currency(subscription.amount/100) %></td>
</tr>
<% count += 1 %>
<% end %>
@Rio517
Rio517 / jquery.validate.phone.js
Created January 10, 2012 22:49
Add method to Jquery Validate for Phone Numbers
jQuery.validator.addMethod("phoneUS", function(phone_number, element) {
phone_number = phone_number.replace(/\s+/g, "");
return this.optional(element) || phone_number.length > 9 &&
phone_number.match(/^(1-?)?(\([2-9]\d{2}\)|[2-9]\d{2})-?[2-9]\d{2}-?\d{4}$/);
}, "Please specify a valid phone number");
// Source: http://docs.jquery.com/Plugins/Validation/CustomMethods/phoneUS
@Rio517
Rio517 / fix_salsa.html
Created January 12, 2012 01:14
Fix SalsaLabs.com problems with CRM embeds. Click view source, then copy and paste this into your page before adding content.
<style>
.contentWrap{float:left;width:630px;}
.formRow{float:right;position:releative;}
.wrapper.site_wrapper .salsa FORM .supporterInfo{float:right;margin:0;padding:0 0 0 30px;position:relative;height:auto;top:-40px !important}
.wrapper.site_wrapper .salsa FORM .supporterInfo SELECT{padding:8px;width:203px;}
.formRow INPUT.blockInput{padding:8px;}
.wrapper.site_wrapper .salsa FORM{position:relative;overflow:hidden;}
@Rio517
Rio517 / example-post-ajax-through-iframe.html
Last active October 4, 2015 21:47
Example: Submit post requests across domains using an intermediary targeted Iframe.
<form action="http://anotherdomain/save" method="post" target="myiframe" id="myform">
<!-- standard form here -->
</form>
<iframe src="about:blank" name="myiframe" style="display: none;"></iframe>
<!-- Then, javascript something like: -->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
<script>
@Rio517
Rio517 / elastic-search-sandbox.rb
Created September 10, 2012 21:37
ElasticSearch Sandbox - a little ruby script to give me a place to test out ElasticSearch facets and queries.
require 'tire'
require 'sqlite3'
require 'active_record'
ActiveRecord::Base.establish_connection( adapter: 'sqlite3', database: ":memory:" )
ActiveRecord::Migration.verbose = false
ActiveRecord::Schema.define(version: 1) do
create_table :articles do |t|
t.string :title
@Rio517
Rio517 / style.css
Created September 14, 2012 23:09
Expression Engine Compact CSS - compact styling of EE Admin pages.
textarea.markItUpEditor {
height: 500px;
min-height: 600px;
padding: 2px;
}
#activeUser {
margin-top: 0;
padding-top: 0;
}