Skip to content

Instantly share code, notes, and snippets.

SELECT first_name, last_name
FROM users
GROUP BY first_name, last_name
HAVING COUNT(*) > 1
@vladimir-e
vladimir-e / model.rb
Last active December 15, 2015 02:59
Disable ActiveRecord "type" column subclassing (http://www.ruby-forum.com/topic/102961) #rails #ar
# Rails 4
class ExampleModel < ActiveRecord::Base
self.inheritance_column = '_type_disable'
end
# Rails 3
class ExampleModel < ActiveRecord::Base
set_inheritance_column do
'disabled'
end
@vladimir-e
vladimir-e / iconv_latin1_to_utf-8.rb
Last active December 15, 2015 01:19
The only way I managed to convert german text from latin1-swedish-ci to be able to use in ruby #ruby #encoding #utf
puts oldproduct.title
# => Gestänge Stahl lang für Tarps (240cm)
i = Iconv.new('LATIN1','UTF-8')
new_title = i.iconv(oldproduct.title).force_encoding("UTF-8")
puts new_title
# => Gestänge Stahl lang für Tarps (240cm)
class App.Helper
generate_password: (length = 8) ->
charset = "abcdefghjknpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789_@=.%"
password = ""
i = 0
n = charset.length
while i < length
password += charset.charAt(Math.floor(Math.random() * n))
++i
password