Skip to content

Instantly share code, notes, and snippets.

Cristiano cristianogregnanin

Block or report user

Report or block cristianogregnanin

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
cristianogregnanin /
Last active Aug 26, 2015 — forked from chooh/
Simple Rack web server for static files with index.html
# This is the root of our app
@root = File.expand_path(File.join(File.dirname(__FILE__), "www"))
run { |env|
# Extract the requested path from the request
req =
index_file = File.join(@root, req.path_info, "index.html")
if File.exists?(index_file)
# Rewrite to index
View contactForm.html
<!DOCTYPE html>
<html lang="en">
<link rel="stylesheet" href="">
<link rel="stylesheet" href="">
<script src=""></script>
<script src=""></script>
<link rel="stylesheet" href=""/>
<script type="text/javascript" src=""></script>
View transactions.markdown


As your business logic gets complex you may need to implement transactions. The classic example is a bank funds transfer from account A to account B. If the withdrawal from account A fails then the deposit to account B should either never take place or be rolled back.


All the complexity is handled by ActiveRecord::Transactions. Any model class or instance has a method named .transaction. When called and passed a block, that block will be executed inside a database transaction. If there's an exception raised, the transaction will automatically be rolled back.


View capybara cheat sheet
=Clicking links and buttons=
click_link('Link Text')
click('Link Text') # Click either a link or a button
click('Button Value')
View db.rake
# lib/tasks/db.rake
namespace :db do
desc "Dumps the database to db/APP_NAME.dump"
task :dump => :environment do
cmd = nil
with_config do |app, host, db, user|
cmd = "pg_dump --host #{host} --username #{user} --verbose --clean --no-owner --no-acl --format=c #{db} > #{Rails.root}/db/#{app}.dump"
puts cmd
View creating-nested-resources-in-ruby-on-rails-3-and-updating-scaffolding-links-and-redirection.markdown
# Italian translation for Devise 3.2
# Date: 2013-20-12
# Author: xpepper
# Note: Thanks to fuzziness (
# Additional translations at
confirmed: "Il tuo account è stato correttamente confermato. Ora sei collegato."
cristianogregnanin / gist:78a5bb9c9e686727a0b0
Last active Aug 29, 2015
Extjs. Populate grid with ajax call
View gist:78a5bb9c9e686727a0b0
//click in search button ==> start the ajaxSearch_function() retrive the form data parameters and call the load method. ==>
//load method start an ajax call. Retrive the data from the server and populate the store.
//The grid is not yet populated. ==> The load method lunch the callback. ==> when callback terminate the grid is populated
var store = new{
url: "my/json/url",
idProperty: "name",
root: "data",//parsing the json starting from data field. Ex: {"results":1,"errors":"","success":true,"data":[{"msg":"SomeData"}]}
View posts_controller.rb
class PostsController < ApplicationController
before_action :set_post, only: [:show, :edit, :update, :destroy]
# GET /posts
# GET /posts.json
def index
@posts = Post.all
# GET /posts/1
cristianogregnanin / Guard-livereload
Last active Aug 29, 2015
Guard config to monitoring php project. Run this commands in your root project path
View Guard-livereload
#setup the Gemfile
$ nano Gemfile
source ''
group :development do
gem 'guard'
gem 'guard-livereload', require: false
$ bundle
You can’t perform that action at this time.