Skip to content

Instantly share code, notes, and snippets.

@felipediesel
felipediesel / query.rb
Last active July 14, 2019 16:22
Query Object module
# Provides a basic query interface to organize the interface between controller and model
module Query
attr_reader :scope_methods, :params, :args
def self.included(base)
base.extend ClassMethods
end
module ClassMethods
attr_reader :scope_methods
@felipediesel
felipediesel / commands.sh
Created February 22, 2017 17:44
simple shell commands reminder
# Split mysqldump into databases
csplit -f 'db_' dump.sql "/Current Database/" '{1000}'
# Split mysqldump into tables
csplit -f 'table_' db_dump.sql "/Dumping data for table/" '{1000}'
@felipediesel
felipediesel / index.html.erb
Created March 30, 2016 14:20
Bootstrap grid in index views
<% @jobs.in_groups_of(3, false).each do |group| %>
<div class="row">
<% group.each do |job| %>
<div class="col-md-4">
<%= job.title %>
</div>
<% end %>
</div>
<% end %>
@felipediesel
felipediesel / exists.js
Created April 20, 2015 11:48
jQuery function to check if an element exists
jQuery.exists = function (selector, context) {
return ($(selector, context).length > 0);
};
@felipediesel
felipediesel / form-reset.js
Created April 20, 2015 11:10
A way to reset and clean a form using jQuery
// reseting a form set it back to his original value.
(function ($) {
$.fn.reset = function () {
$(this).each(function () {
this.reset();
});
return this;
};
}(jQuery));
@felipediesel
felipediesel / browser.js
Created April 20, 2015 11:03
Improved version of removed jQuery.browser
(function () {
'use strict';
var matched, browser;
matched = (function (ua) {
ua = ua.toLowerCase();
var match = /(chrome)[ \/]([\w.]+)/.exec(ua) ||
/(webkit)[ \/]([\w.]+)/.exec(ua) ||
@felipediesel
felipediesel / ruby-debug for 1.9.3
Created March 27, 2012 14:45 — forked from 4nkh/ruby-debug for 1.9.3
ruby-debug install script for 1.9.3
# Install with:
# bash < <(curl -L https://raw.github.com/gist/2216529)
#
# Reference: http://blog.wyeworks.com/2011/11/1/ruby-1-9-3-and-ruby-debug
echo "Installing ruby-debug with $rvm_ruby_string ..."
curl -OL http://rubyforge.org/frs/download.php/75414/linecache19-0.5.13.gem
curl -OL http://rubyforge.org/frs/download.php/75415/ruby-debug-base19-0.11.26.gem
@felipediesel
felipediesel / lightbulb.rb
Created June 1, 2011 14:08
Lightbulb Teaser
# from http://blog.brunomiranda.com/post/5660219139/100-light-bulbs-brain-teaser
bulbs = Array.new(100, true)
(2..100).each do |num|
(1..(100/num)).each do |step|
position = num * step - 1
bulbs[position] = !bulbs[position]
end
end
#!/usr/local/bin/ruby
# Import your Wordpress posts to Tumblr
# How-to:
# 1. Install disqus (http://disqus.com/) in your Wordpress blog and import your comments to Disqus
# 2. Export your Wordpress posts (http://en.blog.wordpress.com/2006/06/12/xml-import-export/)
# 4. Open your XML and rename all <link> tags to <link_>. Don't forget to rename the closing tag too.
# Is necessary to use link_ because hpricot thinks link is the HTML tag.
# 3. Edit the information to match your settings
# 4. Create a empty file named like FILE_URLS_TO_TIDS
#page_posts {}
#page_posts.page_posts_index {}
#page_posts.page_posts_show {}