Skip to content

Instantly share code, notes, and snippets.

@begin29
begin29 / git_config_alias.sh
Created December 21, 2016 09:02
git config useful aliases
# put variable to alias
#put it out of quote
!sh -c 'git rebase -i HEAD~'$1''
@begin29
begin29 / composed_of_rails.rb
Last active December 9, 2016 18:23
composed_of for manipulating ValueObjects add composition class to active_record class with additional information and ability to write value converter
#If we have following code in model:
composed_of :temperature, :mapping => %w(celsius)
#Then our composition class can be this:
class Temperature
def initialize(celsius)
@celsius = celsius
end
@begin29
begin29 / if_loc_var_def_in_view.rb
Created December 9, 2016 17:51
check if local variable is defined in view
render "shared/header", { :headline => "Welcome", :person => person }
# shared/header
<% if local_assigns.has_key? :headline %>
Headline: <%= headline %>
<% end %>
@begin29
begin29 / coffe_usefull_snippets.coffee
Created December 2, 2016 10:02
coffescript useful snippets
# for with index
for value, index in list
console.log value, index
#jQuery each
$.each data, (i, line) ->
@begin29
begin29 / active_record_useful.rb
Created December 1, 2016 11:00
active record useful commands
# check if column exist
ActiveRecord::Base.connection.column_exists?(:table_name, :column_name)
@begin29
begin29 / rails_migration.rb
Last active December 23, 2016 15:29
how rails migration works?
# it looks to `schema_migrations` table and check what migrations was already run
# after merge your code with migration if your migration has name e.g. 2015000000
# and it used some old column name that already renamed in new migrations, this
# migration will crash
# file: 2015000000_old_migration
class OldMigration < ActiveRecord::Migration
def up
# trow Error, that column car_id doesn't exist
@begin29
begin29 / multiple_line_in_slim.rb
Created November 24, 2016 15:51
multiple lines in slim
h2[id="tagline"
class="small tagline"] = page_tagline
@begin29
begin29 / preloading_data.rb
Created November 24, 2016 10:39
includes, preload, eager_loading
# :includes delegates to :eager_loading or :preload
# :eager_loading - one big query
# :preload - few small queries
# get only polish adresses then preload all
User.joins(:addresses).where("addresses.country = ?", "Poland").preload(:addresses)
# SELECT "users".* FROM "users"
# INNER JOIN "addresses" ON "addresses"."user_id" = "users"."id"
# WHERE (addresses.country = 'Poland')
@begin29
begin29 / bash_useful.sh
Last active May 8, 2017 09:53
bash useful commands
# check if variables is set
if [[ $1 ]]; then
echo 'variable is set!'
else
echo 'ERROR: variable is not set!'
fi
@begin29
begin29 / ftp_mount_as_local.sh
Created November 13, 2016 10:28
mount ftp server as local folder
mkdir /ftpmount
# first install curlftpfs if it doesn't exist
curlftpfs -o allow_other user_name:password@ftpserver /ftpmount
# mount it permanently
# go to /etc/fstab and add command above
# it will be added automatically
# umount
umount /ftpmount