Why is the most-often needed folder in /etc named so poorly !? (e.g. tabbing does not work)
sudo ln -s /etc/init.d /etc/i now.... sudo /etc/i/apache2 restart feels much better...
Why is the most-often needed folder in /etc named so poorly !? (e.g. tabbing does not work)
sudo ln -s /etc/init.d /etc/i now.... sudo /etc/i/apache2 restart feels much better...
Notice: this needs to be admin/development only, since it can be really dangerous in the wrong hands… (uses eval or param…)
View
Just make a form that submits:
<%form_tag({:action=>'make_mail'}, :method=>:get) do%>
<%=select_tag :method_name, options_for_select(UserMailer.public_instance_methods(false).sort)%>
Models: Product.find(12322) / String: "abc" / Numbers: 123 / Array: [1,2,3]
<table>
<%5.times do |i|%>
<tr>
<td><%=i%></td>
<td><%=text_field_tag "args[]", '', :style=>'width:300px'%></td>
</tr>
<%end%>
</table>
<%=submit_tag 'Preview'%>
<%=submit_tag 'Send'%>
<%end%>
<%end%>
Controller
Evals the ‘args’ and send or previews the mail.
def make_mail
args = params[:args].map{|arg| eval arg}.compact
if params[:commit]=='Preview' #preview button
@text = UserMailer.send("create_#{params[:method_name]}", *args).body
if @text =~ /<body>/
render :text=>@text
else
render :text=>"<pre>#{@text}</pre>"
end
else #Send button
UserMailer.send("deliver_#{params[:method_name]}", *args)
flash[:notice] = 'Mail sent!'
redirect_to params.merge(:action=>:index)
end
end
Happy mail preview too you 😀
I write my Readme in marddown, and often it gets messed up and then I have to commit & push until its finally right, so I wrote a small script to get a preview (using githubs markdown library)!
Usage
markdown README.markdown ... chrome pops up with the html preview
Install
gem install redcarpet
Put this into e.g. ~/bin/markdown and do a chmod +x on it
#!/usr/bin/env ruby
raise "gime a file!!" unless ARGV[0]
exec "redcarpet #{ARGV[0]} > /tmp/markdown.html && chromium-browser /tmp/markdown.html"
Alternatively: Interactive Live Preview<
The normal answer to most ssh related problems is: “use public/private keys”
but sometimes this does not work…
What i did regularly was this:
Thats not very complicated, but its frustrating. What I do now is: “sshxx”, which executes this excpect script in ~/bin/sshxx
(For Ubuntu you need to “sudo apt get install expect” first)
Could it be that you pollute the global namespace ?
If you ask your users to ‘include’ your library this can happen easily!
Calculate footprint
initial = methods.count + Module.constants.count require 'my_library' include MyLibrary puts "Namespace-Footprint" puts methods.count + Module.constants.count - initial
How to clean up ?
A simple solution is adding a separate Inclusion module, that does not live in your main
namespace and redirect all methods you want to share with the user from your main namespace.
#my_library/inclusion.rb
module MyLibrary
module Inclusion
...
end
end
#my_library.rb
module MyLibrary
..
Inclusion.public_instance_methods.each do |method|
define_method method do |*args|
Inclusion.send(method,*args)
end
end
end