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 / README.md
Last active December 16, 2021 16:34
String "false" to_bool ... or how to convert Rails/SimpleForm radio buttons to boolean

This gist was writen in 2012 and it was solving specific problem in Rails & SimpleForm. Some fellow developers were pointing out this may be out dated concept. That's why I advise everyone to read comment section bellow to have a full grasp of alternative solutions

other sources that may be helpful to understand why this may not be best idea:

@equivalent
equivalent / 0-readme.md
Created September 14, 2012 12:45 — forked from burke/0-readme.md
ruby-1.9.3-p194 cumulative performance patch.

Patched ruby 1.9.3-p194 for 30% faster rails boot

Overview

This script installs a patched version of ruby 1.9.3-p194 with boot-time performance improvements (#66 and #68), and runtime performance improvements (#83 and #84). It also includes the new backported GC from ruby-trunk.

Many thanks to funny-falcon for the performance patches.

@equivalent
equivalent / aes_test.rb
Created September 11, 2012 14:42 — forked from taylor/aes_test.rb
Ruby AES encryption test with lib openssl
#!/usr/bin/env ruby
# encoding: UTF-8
require 'rubygems'
begin
require 'bundler/setup'
rescue LoadError
end
require 'digest/sha1'
require 'openssl'
@equivalent
equivalent / model_spec.rb
Created August 23, 2012 15:46
FactoryGirl attributes_for giving only accessible attributes
describe SomeModel do
it do
p accessible_attributes_for(:contact)
end
end
@equivalent
equivalent / a-m-opiton.rb
Created August 21, 2012 10:30
dynamically defining STI + fixing Rails STI routing problem
class Option < ActiveRecord::Base
def self.sti_class_names
%w[Alert Foo Bar]
end
#define STIs
sti_class_names.each do |class_name|
new_class = Class.new(Option) do
def self.model_name
@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'
@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 / 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 / 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 / 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,