Skip to content

Instantly share code, notes, and snippets.

View dasdennis's full-sized avatar

Dennis A. Silva dasdennis

  • Concrete
  • São Paulo
View GitHub Profile
@JosephPecoraro
JosephPecoraro / shell-execution.rb
Last active September 10, 2023 10:12
Shell Execution in Ruby
# Ways to execute a shell script in Ruby
# Example Script - Joseph Pecoraro
cmd = "echo 'hi'" # Sample string that can be used
# 1. Kernel#` - commonly called backticks - `cmd`
# This is like many other languages, including bash, PHP, and Perl
# Synchronous (blocking)
# Returns the output of the shell command
# Docs: http://ruby-doc.org/core/classes/Kernel.html#M001111
@rogerleite
rogerleite / install_monaco_font.sh
Last active April 27, 2024 05:27
Install Monaco font in Linux
#!/bin/bash
# Install Monaco font in Linux
# Version from nullvideo https://gist.github.com/rogerleite/99819#gistcomment-2799386
sudo mkdir -p /usr/share/fonts/truetype/ttf-monaco && \
sudo wget https://gist.github.com/rogerleite/b50866eb7f7b5950da01ae8927c5bd61/raw/862b6c9437f534d5899e4e68d60f9bf22f356312/mfont.ttf -O - > \
/usr/share/fonts/truetype/ttf-monaco/Monaco_Linux.ttf && \
sudo fc-cache
@akitaonrails
akitaonrails / onemanga_downloader.rb
Created January 24, 2010 05:28
Download from onemanga.com
#!/usr/bin/env ruby
#
# Put this script in your PATH and download from onemanga.com like this:
# onemanga_downloader.rb Bleach [chapter number]
#
# You will find the downloaded chapters under $HOME/Documents/OneManga/Bleach
#
# If you run this script without arguments, it will check your local manga downloads
# and check if there are any new chapters
#
@rbarazi
rbarazi / sessions_controller.rb
Created March 20, 2010 21:25
[Beginning Rails 3] Listing 7-18. create Method in app/controllers/sessions_controller.rb
class SessionsController < ApplicationController
def create
if user = User.authenticate(params[:email], params[:password])
session[:user_id] = user.id
redirect_to root_path, :notice => "Logged in successfully"
else
flash.now[:alert] = "Invalid login/password combination"
render :action => 'new'
end
end
@rbarazi
rbarazi / new.html.erb
Created March 20, 2010 21:35
[Beginning Rails 3] Listing 7-19. new Session Template in app/views/sessions/new.html.erb
<h1>Login</h1>
<%= form_tag session_path do %>
<div class="field">
<%= label_tag :email %><br />
<%= text_field_tag :email %>
</div>
<div class="field">
<%= label_tag :password %><br />
<%= password_field_tag :password %>
@rbarazi
rbarazi / form.html.erb
Created March 23, 2010 18:34
[Beginning Rails 3] Listing 7-22. Modified app/views/articles/_form.html.erb
<%= form_for(@article) do |f| %>
<% if @article.errors.any? %>
<div id="errorExplanation">
<h2><%= pluralize(@article.errors.count, "error") %> prohibited this article from being saved:</h2>
<ul>
<% @article.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
@rbarazi
rbarazi / application_controller.rb
Created March 23, 2010 20:37
[Beginning Rails 3] Listing 7-23. Modified app/controllers/application_controller.rb
class ApplicationController < ActionController::Base
protect_from_forgery
protected
# Returns the currently logged in user or nil if there isn't one
def current_user
return unless session[:user_id]
@current_user ||= User.find_by_id(session[:user_id])
end
@rbarazi
rbarazi / users_controller.rb
Created March 23, 2010 20:48
[Beginning Rails 3] Listing 7-25. Before Filter Added in app/controllers/users_controller.rb
class UsersController < ApplicationController
before_filter :authenticate, :only => [:edit, :update]
def new
@user = User.new
end
def create
@user = User.new(params[:user])
if @user.save
@rbarazi
rbarazi / _article.html.erb
Created March 24, 2010 00:25
[Beginning Rails 3] Listing 7-29. Edit Controls for Article in app/views/articles/_article.html.erb
<%= div_for article do %>
<h3>
<%= link_to article.title, article %>
<% if article.owned_by? current_user %>
<span class='actions'>
<%= link_to "Edit", edit_article_path(article) %>
<%= link_to "Delete", article, :confirm => "Are you sure?", :method => :delete %>
</span>
<% end %>
</h3>
@rbarazi
rbarazi / application_helper.rb
Created March 24, 2010 00:36
[Beginning Rails 3] Listing 7-32. The submit_or_cancel Method in app/helpers/application_helper.rb
module ApplicationHelper
# Creates a submit button with the given name with a cancel link
# Accepts two arguments: Form object and the cancel link name
def submit_or_cancel(form, name='Cancel')
form.submit + " or " + link_to(name, 'javascript:history.go(-1);', :class => 'cancel')
end
end