Skip to content

Instantly share code, notes, and snippets.

View modsaid's full-sized avatar

Mahmoud Salem modsaid

View GitHub Profile
@modsaid
modsaid / git_export
Created February 22, 2012 11:55
Exporting files out of a git repo like svn export
git archive master | tar -x -C /somewhere/else
OR
git archive --format zip --output /full/path/to/zipfile.zip master
Ref: http://stackoverflow.com/questions/160608/how-to-do-a-git-export-like-svn-export
@modsaid
modsaid / gist:1891303
Created February 23, 2012 07:28
Checking if a process with a certain pid is running
# Sometimes, specially if we are building a monitoring system or an admin UI,
# we need to be able to easily check if a process is running.
# Unfortunately this is not directly available through Process module. so here is a patch to add it
#
# Usage:
# Process.running?(pid)
# Process.memory(pid) # returns the memory usage in KB
module Process
@modsaid
modsaid / application_controller.rb
Created May 14, 2012 14:40
Default rescue for all actions/controllers
#To be placed in application_controller.rb
rescue_from Exception, :with => :rescue_all_exceptions unless %W(development test).include?(Rails.env)
def rescue_all_exceptions(exception)
buffer = "[EXCEPTION] "
buffer << exception.message << "\t(Request: #{request.url}\t Referrer: (#{request.env['HTTP_REFERER']} ) \n\t"
buffer << exception.backtrace.join("\n\t")
Rails.logger.error buffer
@modsaid
modsaid / gist:3833121
Created October 4, 2012 11:45
Testing ActionMailer from Rails 3 console
#place this directly in the rails console of ur rails application
class UserMailer < ActionMailer::Base
default from: 'sender@espace.com.eg'
def test_email
@receiver_email = 'mahmoud.said@espace.com.eg'
mail(to: @receiver_email, subject: 'testing email from console')
end
end
@modsaid
modsaid / download_railscasts.rb
Created April 7, 2013 13:42
Ruby script for downloading rails casts http://blog.modsaid.com/2010/02/ruby-script-for-downloading-rails-casts.html this has been posted 3 years ago actually
#!/usr/local/bin/ruby
# A script to download the latest episodes from railscasts.com
#
# requires simple-rss (1.2.2) gem
# and base on linux wget
#
# author: modsaid < mahmoud@modsaid.com >
#
@modsaid
modsaid / add-copyright.rb
Last active May 25, 2016 02:56
This ruby scripts add the prepends the specified arbitrary text (e.g copyright notice) to all .rb files under a given directory
Rails as it has never been before :)
@modsaid
modsaid / access-log-timestamp.sh
Created October 21, 2014 17:50
Rename hourly rotated web access logs (access.log.1, access.log.2) to include the timestamp for better management of the times
#!/bin/bash
# This script is made to rename default rotated access log files from access.log.1, access.log.2 and
# so on, to using timestamp instead of auto increment index (to be access.log.2014102009)
#
# USAGE:
# cd LOGS_DIR && ./access-logs-timestamp.sh
FILES=access.log*
@modsaid
modsaid / all-ssconvert-to-xlsx.sh
Last active September 15, 2015 08:04
Convert batch csv files into xlsx in a single command
#!/bin/bash
# This script uses ssconvert to convert all *.csv files in the current directory into *.xlsx format
command -v ssconvert >/dev/null 2>&1 || { echo >&2 "ssconvert is not installed, please install it via apt-get install gnumeric"; exit 1; }
find . -maxdepth 1 -name "*.csv" -exec ssconvert {} --export-type=Gnumeric_Excel:xlsx2 \;
@modsaid
modsaid / action_mailer_check.rb
Created March 9, 2016 01:37
Script to test action mailer configuration. to be run through the console, or rails runner
# author @modsaid
# Script to test action mailer configuration. to be run through the console, or rails runner
class MyMailer < ActionMailer::Base
default from: 'notifications@example.com'
def test_email
mail(to: "mail@exmaple.com",
subject: 'SMTP configuraiton test',
body: 'bla bla bla')
end