Skip to content

Instantly share code, notes, and snippets.

View yyalim's full-sized avatar
🧙‍♂️
Thinking & Hacking

Yusuf Yalım yyalim

🧙‍♂️
Thinking & Hacking
View GitHub Profile
# Title is an active record model
titles = Title.all.each { |title| title.some_attribute = Random.new_seed }.sort_by { |title| title.some_attribute }
# SELECT *
# FROM people
# WHERE name = 'francais' collate utf8_bin;
#
# This is the active record equivalent of MySQL query above.
Person.where("name = :name collate utf8_bin", name: "francis")
Week.where{ matches_count.eq 0 }
# Week Load (1.0ms) SELECT "weeks".* FROM "weeks"
# => #<ActiveRecord::QueryMethods::WhereChain:0x007fee87784fd8 @scope=#<ActiveRecord::Relation [#<Week id: 6, created_at: "2015-07-24 09:39:24", updated_at: "2015-07-24 09:39:24", matches_count: 2>, #<Week id: 1, created_at: "2015-07-24 09:39:24", updated_at: "2015-07-24 09:39:24", matches_count: 2>, #<Week id: 5, created_at: "2015-07-24 09:39:24", updated_at: "2015-07-24 09:39:24", matches_count: 2>, #<Week id: 3, created_at: "2015-07-24 09:39:24", updated_at: "2015-07-24 09:39:24", matches_count: 2>, #<Week id: 4, created_at: "2015-07-24 09:39:24", updated_at: "2015-07-24 09:39:24", matches_count: 2>, #<Week id: 2, created_at: "2015-07-24 09:39:24", updated_at: "2015-07-24 09:39:24", matches_count: 2>]>>
@yyalim
yyalim / locale_for_digital_ocean_ubuntu.sh
Last active October 13, 2015 08:37
Install charset for debian variants.
# thanks to tanaydin < github.com/tanaydin >
# set locales for system
export LANGUAGE="en_US:en"
export LC_ALL="en_US.UTF-8"
sudo locale-gen en.UTF-8
sudo dpkg-reconfigure locales
echo "LANGUAGE=\"en_US:en\"" | sudo tee --append /etc/default/locale
echo "LC_ALL=\"en_US.UTF-8\"" | sudo tee --append /etc/default/locale
class User < ActiveRecord::Base
validates_confirmation_of :password, message: "custom message."
# ...
end
@yyalim
yyalim / mysql_socket_location.sh
Created October 21, 2015 06:31
Mysql Socket Location
mysqladmin variables | grep socket
@yyalim
yyalim / last_rails_migration_file.sh
Created October 21, 2015 13:35
Open last generated rails migration on your code editor.
# You can your favorite code editor.
# I love sublime :)
subl `ls db/migrate/*.rb | tail -n 1`
@yyalim
yyalim / escape_from_no_method_error_on_nil.rb
Last active November 2, 2015 11:23
Trick to handle no method error on nil objects
"hello world".upcase
# => "HELLO WORLD"
nil.upcase
# NoMethodError: undefined method `upcase' for nil:NilClass
# "gem install activesupport" if it is not installed
require 'active_support/core_ext/object/blank'
nil.presence && nil.upcase
@yyalim
yyalim / git_aliases.md
Created January 5, 2016 08:31
Git aliases

Pretty logging

git config --global alias.lg "log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative"