Skip to content

Instantly share code, notes, and snippets.

View modsaid's full-sized avatar

Mahmoud Salem modsaid

View GitHub Profile
@modsaid
modsaid / iptables-rollback.sh
Created January 20, 2020 18:08
helpful to apply after iptables commands on remote servers to avoid locking yourself out
#!/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 20:47 — 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.
#!/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 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
@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 / 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*
Rails as it has never been before :)
@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
@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 / 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 / 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