Skip to content

Instantly share code, notes, and snippets.

Avatar

Mahmoud Salem modsaid

View GitHub Profile
@modsaid
modsaid / iptables-rollback.sh
Created Jan 20, 2020
helpful to apply after iptables commands on remote servers to avoid locking yourself out
View iptables-rollback.sh
#!/bin/bash
sleep 2m
iptables -F
iptables -P INPUT ACCEPT
iptables -P OUTPUT ACCEPT
iptables -P FORWARD ACCEPT
@modsaid
modsaid / dummy-web-server.py
Created May 30, 2018 — forked from bradmontgomery/dummy-web-server.py
a minimal http server in python. Responds to GET, HEAD, POST requests, but will fail on anything else.
View dummy-web-server.py
#!/usr/bin/env python
"""
Very simple HTTP server in python.
Usage::
./dummy-web-server.py [<port>]
Send a GET request::
curl http://localhost
@modsaid
modsaid / action_mailer_check.rb
Created Mar 9, 2016
Script to test action mailer configuration. to be run through the console, or rails runner
View action_mailer_check.rb
# 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
@modsaid
modsaid / all-ssconvert-to-xlsx.sh
Last active Sep 15, 2015
Convert batch csv files into xlsx in a single command
View all-ssconvert-to-xlsx.sh
#!/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 / access-log-timestamp.sh
Created Oct 21, 2014
Rename hourly rotated web access logs (access.log.1, access.log.2) to include the timestamp for better management of the times
View access-log-timestamp.sh
#!/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*
View README
Rails as it has never been before :)
@modsaid
modsaid / add-copyright.rb
Last active May 25, 2016
This ruby scripts add the prepends the specified arbitrary text (e.g copyright notice) to all .rb files under a given directory
View add-copyright.rb
@modsaid
modsaid / download_railscasts.rb
Created Apr 7, 2013
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
View download_railscasts.rb
#!/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 / gist:3833121
Created Oct 4, 2012
Testing ActionMailer from Rails 3 console
View gist:3833121
#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 / application_controller.rb
Created May 14, 2012
Default rescue for all actions/controllers
View application_controller.rb
#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