Skip to content

Instantly share code, notes, and snippets.

View equivalent's full-sized avatar
:octocat:
I'm IDDQD + IDKFA for Ruby on Rails

Tomas Valent equivalent

:octocat:
I'm IDDQD + IDKFA for Ruby on Rails
View GitHub Profile
@equivalent
equivalent / list_all_rails_models.rb
Created November 8, 2011 13:03
how to get model names of all rails models (works for STI)
#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
models = ActiveRecord::Base.subclasses.collect { |type| type.name }.sort
@equivalent
equivalent / factories_inside_rails_console.rb
Created November 10, 2011 18:44
use factories inside rails console
require 'factory_girl'
require 'faker' #if needed
Dir[Rails.root.to_s + '/spec/factories/**/*.rb'].each {|file| require file }
@equivalent
equivalent / run_rails_app_tests.sh
Created November 11, 2011 12:20
This is a bash script that runs bundler, drop test database, recreates it, run migrations and runs specs and tests
#!/bin/sh
WORK_DIR=/Users/tomi/rails_apps/myapp/;
RETURN_DIR=/Users/tomi/my_bash_scripts/; #optional
if [ -r $WORK_DIR ]; then
cd $WORK_DIR
# why and what is solarized http://ethanschoonover.com/solarized
# Simple installation notes for iterm2 and Solarized
Set ZSH_THEME in ~/.zshrc to blinks
https://github.com/altercation/solarized/tree/master/iterm2-colors-solarized
#if you create new profile e.g. solarized you have to set him as default
#Simple installation notes for janus and Solarized
# .vimrc.before
let g:solarized_termcolors=256
set t_Co=16
@equivalent
equivalent / haml
Created May 15, 2012 12:02 — forked from erich/haml
= form_for [@user, @task], :html => { :class => 'form-inline' } do |f|
-if @task.errors.any?
#error_explanation
%h2= "#{pluralize(@task.errors.count, "error")} prohibited this task from being saved:"
%ul
@equivalent
equivalent / simple_form.rb
Created June 21, 2012 14:16
Simple Form with Bootstrap....initiliazer
# place this file in config/initializers/simple_form.rb
#
# Use this setup block to configure all options available in SimpleForm.
SimpleForm.setup do |config|
# Wrappers are used by the form builder to generate a
# complete input. You can remove any component from the
# wrapper, change the order or even add your own to the
# stack. The options given below are used to wrap the
# whole input.
config.wrappers :default, :class => :input,
@equivalent
equivalent / app-assets-javascript-datepicker.js.coffee
Created July 5, 2012 12:24
Simple Form custom input for "Datepicker for Twitter Bootstrap" running under Ruby on Rails with Ransack search
# install and make run basic bootstrap date-picker functionality described here http://www.eyecon.ro/bootstrap-datepicker/
# app/assets/javascript/datepicker.js.coffee
$(document).on 'pageChanged', ->
# datepicker for simple_form & Ransack
$(".custom_datepicker_selector").datepicker().on 'changeDate', (en) ->
correct_format = en.date.getFullYear() + '-' + ('0' + (en.date.getMonth() + 1)).slice(-2) + '-' + ('0' + en.date.getDate()).slice(-2) # date format yyyy-mm-dd
$(this).parent().find("input[type=hidden]").val(correct_format)
@equivalent
equivalent / Gemfile
Created July 9, 2012 21:32
Script to rename files in folders (Sketchup animation render)
source 'https://rubygems.org'
gem 'bundler'
gem 'rb-readline'
@equivalent
equivalent / speedtest
Created July 16, 2012 12:09
ljust speed test
# just speed test for http://stackoverflow.com/questions/11502629/how-to-do-number-to-string-suffix/11502715#11502715
1.9.3p194 :019 > def shot
1.9.3p194 :020?> a=Time.now
1.9.3p194 :021?> 1000000.times do
1.9.3p194 :022 > "5".ljust(3, "0")
1.9.3p194 :023?> end
1.9.3p194 :024?> b =Time.now
@equivalent
equivalent / app-views-my_gem-foo.html.haml
Created July 30, 2012 15:26
simple_form input extensions in own gems
-#app/views/my_gem/foo.html.haml
= f.input :address_country_id_eq, :as => :country_search, label: 'Country'