Skip to content

Instantly share code, notes, and snippets.

View wellington1993's full-sized avatar
🏠
Working from home

Wellington Torrejais da Silva wellington1993

🏠
Working from home
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
@mislav
mislav / gist:17371
Created October 17, 2008 07:42
haml2erb
class ErbEngine < Haml::Engine
def push_script(text, preserve_script, in_tag = false, preserve_tag = false,
escape_html = false, nuke_inner_whitespace = false)
push_text "<%= #{text.strip} %>"
end
def push_silent(text, can_suppress = false)
push_text "<% #{text.strip} %>"
end
end
@stevebartholomew
stevebartholomew / gist:50180
Created January 21, 2009 20:52
Simple database backup rake task for Rails using mysqldump
namespace :backup do
desc "Backup database"
task :db do
RAILS_ENV = "development" if !defined?(RAILS_ENV)
app_root = File.join(File.dirname(__FILE__), "..", "..")
settings = YAML.load(File.read(File.join(app_root, "config", "database.yml")))[RAILS_ENV]
output_file = File.join(app_root, "..", "backup", "#{settings['database']}-#{Time.now.strftime('%Y%M%d')}.sql")
system("/usr/bin/env mysqldump -u #{settings['username']} -p#{settings['password']} #{settings['database']} > #{output_file}")
@tansengming
tansengming / Rails Console Actionmailer test.rb
Created April 24, 2009 15:14
Rails Console Actionmailer test
# Copy and paste this to the rails console to test your email settings
class MyMailer < ActionMailer::Base
def test_email
@recipients = "someone@somewhere.com"
@from = "must_be_same_as_smpt_account_login@gmail.com"
@subject = "test from the Rails Console"
@body = "This is a test email"
end
end
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title>Graph-test</title>
<style>
* {
margin: 0;
padding: 0;
}
@awesome
awesome / strip HTML tags
Created November 3, 2009 16:29
ruby strip HTML tags
# copied from (thanks!): http://codesnippets.joyent.com/posts/show/615
str = <<HTML_TEXT
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<body>
<h1>Application error</h1>
<p>Change this error message for exceptions thrown outside of an action (like
in Dispatcher setups or broken Ruby code) in public/500.html</p>
# How to echobot with XMPP, BOSH, and Strophe
1. Setup ejabberd(http://www.ejabberd.im/) server and setup account admin@localhost.local
NOTE: localhost should be enough. If you setup something else, make sure you add it at /etc/hosts like this
#/etc/hosts
127.0.0.1 localhost.local
NOTE: Also download Psi(http://psi-im.org/), and make sure you can connect to your ejabberd server.
2. Download strophe(http://code.stanziq.com/strophe/) and place it (eg: /Users/makoto/work/sample/strophejs-1.0)
@ryanjm
ryanjm / Extra info
Created February 24, 2010 16:55
Issues with bad interpreter
Something else I found helpful along the way (as I had old stuff installed):
gem uninstall --install-dir /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8 rails
@metavida
metavida / dispatcher.rb.patch
Created April 21, 2010 14:24
A patch for a Mongrel + Rails 1.2.6 bug, described in detail here: http://billkirtley.wordpress.com/2009/03/03/failsafe-handling-with-rails/
--- a/rails-1.2.6/lib/dispatcher.rb
+++ b/rails-1.2.6/lib/dispatcher.rb
@@ -41,7 +41,7 @@
controller.process(request, response).out(output)
end
rescue Exception => exception # errors from CGI dispatch
- failsafe_response(output, '500 Internal Server Error', exception) do
+ failsafe_response(output, '500 Internal Server Error', exception, response) do
controller ||= (ApplicationController rescue ActionController::Base)
controller.process_with_exception(request, response, exception).out(output)
gem 'resque', '>= 1.10.0'
gem 'heroku' # You will need the heroku gem for this too.