Skip to content
View gernerator.rb
# don't generate RSpec tests for views and helpers by default
Rails.application.config.generators do |g|
g.view_specs false
g.helper_specs false
g.stylesheets false
g.helper false
g.javascripts false
g.template_engine :haml
g.form_builder :simple_form
g.test_framework :rspec, fixture: true, view_specs: false
View dev.rake
namespace :development do
desc "copies the config/*.example.yml files be the usable config/*.yml versions"
task :configure do
Dir.glob('config/*.yml.example').each do |filename|
sh "cp #{filename} #{filename.gsub('.example', '')}"
end
end
task :configure_all_but_database do
(Dir.glob('config/*.yml.example') - ["config/database.yml.example"]).each do |filename|
sh "cp #{filename} #{filename.gsub('.example', '')}"
View start_stop_jenkins.md

Start Jenkins:

sudo launchctl load /Library/LaunchDaemons/org.jenkins-ci.plist

Stop Jenkins:

sudo launchctl unload /Library/LaunchDaemons/org.jenkins-ci.plist

View enable_root_on_man.md
  • Open System Preferences, select Users & Groups
  • Click the lock and enter your password to unlock the panel
  • Click Login Options, then click the Join button
  • Click Open Directory Utility button
  • Now go up to the Edit menu and select Enable Root User
  • Enter a password and voila, root is enabled
  • Later, after the rest is done, you need to retrace these steps and select Disable Root User
View ci.rake
namespace :ci do
task :copy_yml do
sh "cp #{Rails.root}/config/example_database.yml #{Rails.root}/config/database.yml"
sh "other preparation"
end
desc "Prepare for CI and run entire test suite"
task :build do
Rake::Task['db:migrate'].invoke
Rake::Task['db:test:prepare'].invoke
View nginx_basic_auth.md

Assume we have Nginx installed on Ubuntu 12.04 server. Now I will show you how to configure HTTP basic authentication in Nginx.

step1:

Open conf/nginx.conf file, and add some directives into locatiion / section:

        location / {
            auth_basic "Restricted";
            auth_basic_user_file pwd;
View proxy_nginx.sh
sudo aptitude -y install nginx
cd /etc/nginx/sites-available
sudo rm default
sudo cat > jenkins
upstream app_server {
server 127.0.0.1:8080 fail_timeout=0;
}
server {
listen 80;
View share_to_facebook.erb
<% content_for :html_head_content do %>
<meta property="og:title" content="<%= @post.title %>"/>
<meta property="og:type" content="website"/>
<meta property="og:site_name" content="sample.com"/>
<% if Rails.env == 'production' %>
<meta property="og:image" content="http://sample.com/assets/logo.png"/>
<% else %>
<meta property="og:image" content="http://sample.com/logo.png"/>
<% end %>
<meta property="og:description" content="<%= strip_tags(@post.excerpt).strip[0, 200] %>"/>
View split_csv.sh
#!/bin/bash
# check if an input filename was passed as a command
# line argument:
if [ ! $# == 1 ]; then
echo "Please specify the name of a file to split!"
exit
fi
# create a directory to store the output:
View random.rb
def self.random(n = 1)
indexes = (0..self.count-1).sort_by{rand}.slice(0,n).collect!
if n == 1
return self.skip(indexes.first).first
else
return indexes.map{ |index| self.skip(index).first }
end
end
Something went wrong with that request. Please try again.