Skip to content

Instantly share code, notes, and snippets.

@joshmvandercom
joshmvandercom / sync_tables.rake
Created November 16, 2016 20:20
Fixing out of sync postgres
task :sync_tables => :environment do
ActiveRecord::Base.connection.tables.each do |table|
unless ['schema_migrations', 'ar_internal_metadata'].include?(table)
sql = "SELECT setval('#{table}_id_seq', COALESCE((SELECT MAX(id)+1 FROM #{table}), 1), false);"
ActiveRecord::Base.connection.execute(sql)
end
end
end
var Input = React.createClass({
propTypes: {
type: React.PropTypes.string,
label: React.PropTypes.string,
help: React.PropTypes.string,
className: React.PropTypes.string
},
renderInput: function() {
switch(this.props.type) {
@joshmvandercom
joshmvandercom / engine.rb
Created October 18, 2012 23:48
Testing routes with Rails 3.2 mountable engines and RSpec 2
# your-engine/lib/magic/rails/engine.rb
module Magic
module Rails
module Engine
##
# Automatically append all of the current engine's routes to the main
# application's route set. This needs to be done for ALL functional tests that
# use engine routes, since the mounted routes don't work during tests.
#
jQuery.fn.autoresize = function (options) {
options = options || {}
return this.each(function () {
// Init Sizes
var parent = $(this).parent();
var imageWidth = $(this).width();
var imageHeight = $(this).height();
var parentWidth = parent.width();
var parentHeight = parent.height();
var ratio, newSide;
class UsersController < ApplicationController
def index
@users = User.all
respond_to do |format|
format.html # renders index.html.erb
format.json { render :json => @users }
format.xml { render :xml => @users }
end
@joshmvandercom
joshmvandercom / test.scss
Created March 10, 2012 18:55
Scss Example
@mixin module{
background: white;
border: 1px solid #ccc;
box-shadow: 0 0 3px rgba(0, 0, 0, 0.1);
}
#content {
@include module;
float: left;
}
@joshmvandercom
joshmvandercom / dropdown_to.rb
Created February 27, 2012 21:39
Passing a block into a helper
# Creates a Bootstrap dropdown
# Ex:
# = dropdown_to "Auctions", auctions_path do
# %li= link_to 'Upcoming Auctions', auctions_path
# %li= link_to 'Past Auctions', past_auctions_path
#
# Returns:
# <li class="dropdown">
# <a class="dropdown-toggle" data-toggle="dropdown" href="/auctions">
# <span>Auction</span>
@joshmvandercom
joshmvandercom / gist:1847955
Created February 16, 2012 21:22
ruby_example.rb
class Person
def initialize(food = 0)
@next_feeding_time = Time.now
feed(food)
end
def hungry?
@next_feeding_time < Time.now
end
@joshmvandercom
joshmvandercom / .htaccess
Created January 19, 2012 15:57
.htaccess redirect w/ hash
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{QUERY_STRING} !ajax
RewriteRule ^(.*)$ /#/$1 [R=301,L,NE]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
@joshmvandercom
joshmvandercom / convert-colors.jsx
Created January 5, 2012 18:36
Change path colors
var colorObject;
var hexes = ['5b7f52', '6ea041', '62a04a', '5b7f52', '6cb84e'];
var colors = [];
for (var h = 0; h < hexes.length; h++) {
colorObject = new SolidColor();
colorObject.rgb['hexValue'] = hexes[h];
colors.push(colorObject);
}