Last active
April 7, 2017 08:54
-
-
Save madeindjs/a9ff346d7490ec583890f567de931022 to your computer and use it in GitHub Desktop.
My Rakefile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'git' | |
require 'fileutils' | |
require 'date' | |
require 'pathname' | |
desc "Print directory-tree" | |
task :tree, [:folder, :folder_only] do |t, args| | |
args.with_defaults(:folder_only => false) | |
$folder_only = args.folder_only == "true" | |
$ArmMap = Hash.new("| ") | |
$ArmMap[""] = "" | |
$ArmMap["`"] = " " | |
def visit path, leader, tie, arm, node | |
print("#{leader}#{arm}#{tie}#{node}\n") if $folder_only and File.directory?(path+node) | |
visitChildren(path + node, leader + $ArmMap[arm]) | |
end | |
def visitChildren path, leader | |
return unless FileTest.directory? path | |
return unless FileTest.readable? path | |
files = path.children(false).sort #false = return name, not full path | |
return if files.empty? | |
arms = Array.new(files.length - 1, "|") << "`" | |
pairs = files.zip(arms) | |
pairs.each { |e| visit(path, leader, "-- ", e[1], e[0]) } | |
end | |
visit Pathname.new("."), "","","",Pathname.new(args.folder) | |
end | |
namespace :csv do | |
desc "find doubles on given column" | |
task :double, [:file, :column] do |t, args| | |
args.with_defaults(column: 0) | |
values = [] | |
index = args.column.to_i | |
# parse given file row by row | |
File.open(args.file, "r").each_slice(1) do |line| | |
# get value of the given column | |
values << line.first.split(';')[index] | |
end | |
# compare length with & without uniq method | |
puts values.uniq.length == values.length ? "File does not contain duplicates" : "File contains duplicates" | |
end | |
end | |
namespace :linux do | |
desc "run all maintenance" | |
task :all do | |
%w(update upgrade autoclean autoremove purge).each do |action| | |
system "sudo apt-get #{action}" | |
end | |
end | |
end | |
namespace :php do | |
desc "lauch PHPUnit on a specific file" | |
task :phpunit, [:filepath, :times] => :cd do |t, args| | |
args.with_defaults(times: 1) | |
args.times.to_i.times { |i| | |
system "APPLICATION_ENV=\"development\" phpunit --bootstrap bootstrap.php --colors #{args.filepath}" | |
} | |
end | |
desc "change php version" | |
task :version, [:old, :new] do |t, args| | |
allowed_params = ["5.6", "7.0", "7.1"] | |
if allowed_params.include?(args.old) and allowed_params.include?(args.new) | |
# change apache | |
system "sudo a2dismod php#{args.old}" | |
system "sudo a2enmod php#{args.new}" | |
system "sudo /etc/init.d/apache2 restart" | |
# change CLI | |
system "sudo update-alternatives --set php /usr/bin/php#{args.new}" | |
else | |
puts "bad params.." | |
end | |
end | |
end | |
namespace :git do | |
desc "delete a Git branch both locally and remotely" | |
task :delete_branch do | |
%x(git branch -D feature/5545_ExpenseNew) | |
%x(git push origin feature/5545_ExpenseNew) | |
end | |
end | |
namespace :gac do | |
task :cd do | |
cd "/home/arousseau/www" | |
end | |
desc "initialize work environement" | |
task :init => :cd do | |
[ | |
'firefox http://localhost/ https://web.skype.com/en/', | |
'/home/arousseau/netbeans-8.2/bin/netbeans', | |
'thunderbird', | |
'subl' | |
].each do |comand| | |
# run theses commands in "silent" mode | |
system "#{comand} > /dev/null 2>&1" | |
end | |
end | |
namespace :campaign do | |
desc "send all mails waiting in the database" | |
task :mail => :cd do | |
system "APPLICATION_ENV=development php scripts/jobs/compute_campaign.php" | |
end | |
end | |
desc "start a new ticket" | |
task :start, [:id] do |t, args| | |
repo = Git.open "/home/arousseau/dev/php/gac-report" | |
# pull the repository | |
ticket_id = args.id | |
repo.checkout('develop') | |
repo.pull 'origin', 'develop' | |
# Create a new branch on Git repository | |
repo.branch("feature/#{ticket_id}").checkout | |
# Create a File note skeleton | |
filepath = "/home/arousseau/Documents/Tickets/#{args.id}.md" | |
File.open(filepath, "w+") do |f| | |
f << "# #{ticket_id}" | |
end | |
system "subl #{filepath}" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment