Skip to content

Instantly share code, notes, and snippets.

View warolv's full-sized avatar

Igor Zhivilo warolv

View GitHub Profile
@warolv
warolv / Undo Changes
Created October 10, 2013 12:37
Undo Changes
git reset --soft HEAD^ -> undo last commit and save changes
git reset --hard HEAD~1 -> undo last commit and remove changes
git reset --hard HEAD~2 -> undo 2 last commits and remove changes
git revert commit-hash -> create new commit which reverts last commit
git checkout . -> remove all uncommitted changes
git checkout filename -> undo changes in specific file
git clear -df -> remove all untracked files
git rm filename -> remove file from index, after your did git add filename
git commit --amend -> change message of last commit
@warolv
warolv / migration.rb
Created October 14, 2013 10:05
Standart Operations
rake db:migrate VERSION=20080906120000
rake db:rollback
rake db:migrate:redo STEP=3
rake db:migrate:up VERSION=20080906120000
rake db:migrate:down VERSION=20080906120000
@warolv
warolv / example_controller.rb
Created October 14, 2013 12:48
Backend Example in Rals for Angular (Rails Controller)
class StaffController < ApplicationController
respond_to :json
def index
respond_with Staff.all
end
def show
respond_with Staff.find(params[:id])
end
@warolv
warolv / application.html.rb
Created October 14, 2013 12:53
Adding placeholder for app to use Angular
- if content_for?(:angular_module)
= javascript_include_tag 'angular'
= javascript_include_tag 'angular-resource'
= javascript_include_tag 'angular-ui-bootstrap'
= javascript_include_tag 'angular-sanitize'
@warolv
warolv / rails_ujs.html.haml
Created October 20, 2013 14:24
Rails UJS events handling example using form
$(document)
.on('ajax:beforeSend', '#scheduling_options_form', function() {
console.log('beforeSend');
$('.ajax-loader').show();
})
.on('ajax:success', '#scheduling_options_form', function(data, status, xhr) {
console.log('Success');
$('.ajax-loader').hide();
})
.on('ajax:error', '#scheduling_options_form', function(data, status, xhr) {
@warolv
warolv / en.yaml
Created October 29, 2013 09:46
I18n Link inclusion
branding_logo_link: "To select branding logo for your business %{link:click}"
@warolv
warolv / en.yml
Created October 29, 2013 09:48
i18n Text inclusion
branding_logo_link: "To select branding logo for your business %{text}"
@warolv
warolv / example.rb
Created November 3, 2013 16:29
Rails’ index_by: the easy way to convert an Array to a Hash
Post.all.index_by { |post| post.id }
# => { 1 => #<Post ...>, 2 => #<Post ...>, ... }
Post.all.index_by(&:title)
# => { "My first post" => #<Post ...>, "My second post" => #<Post ...>, ... }
@warolv
warolv / example.rb
Last active December 27, 2015 08:09
Octopress Commands
rake generate # Generates posts and pages into the public directory
rake watch # Watches source/ and sass/ for changes and regenerates
rake preview # Watches, and mounts a webserver at http://localhost:4000
rake 'new_post["Building Form Ajax Validator"]' # Generate new post
# Create a new page
rake new_page[super-awesome]
rake new_page[super-awesome/page.html]
@warolv
warolv / gemfile.rb
Created November 10, 2013 12:59
Gem File example to start with
source 'https://rubygems.org'
ruby '2.0.0'
gem 'rails', '4.0.1'
group :production do
gem 'pg'
gem 'rails_12factor'
end