Skip to content

Instantly share code, notes, and snippets.

View mortymacs's full-sized avatar

Morteza NourelahiAlamdari mortymacs

View GitHub Profile
@mortymacs
mortymacs / ping_log.sh
Last active December 15, 2015 15:49
This is simple code for pinging an address and save the results in a log file and can get percent about lost and success packets and then run your command when you got lost packets over 20%!
#!/bin/bash
#read -p "Enter your url: " $address
######
# Ping URL and get percent
######
address='google.com'
log_file='packet.log'
@mortymacs
mortymacs / gp.sh
Last active December 15, 2015 17:59
Showing branch and commits number of current directory
function gb
{
if [ -d ".git" ]
then
cc=$(git log --pretty=oneline|wc -l)
gb=$(git branch | grep '*' | awk '{print $2}')
echo [$gb:$cc]
fi
}
@mortymacs
mortymacs / regex_fetch_mail.py
Last active December 17, 2015 17:48
Fetch email addresses from imap return strings via python
import re
pattern = re.compile('.*<([a-zA-Z0-9\-\+_-]+@[a-zA-Z0-9_]+\.[a-zA-Z]{2,})>.*')
## example-1
data = "bla bla bla ..... reza <salam@gmail_test.com> bla bla bla"
print pattern.findall(data)
## example-2
data = "bla bla bla ..... reza <a-a+1@gmail_test.com> bla bla bla"
@mortymacs
mortymacs / regex_simple_href_title.py
Created May 25, 2013 07:05
Simple regex for fetching href and title attributes of <a> tag
import re
pattern = re.compile('.*<a.*href="(?P<link>[a-zA-Z0-9\+\/\.\?#:_-]+)".*>(?P<title>\w+)</a>.*')
data = '<div calss="bla"><a href="http://link1.domain/index.php" class="test">Link1</a></div>'
print pattern.findall(data)
##output : [('http://link1.domain/index.php', 'Link1')]
@mortymacs
mortymacs / mysql_show_query_status.sh
Last active December 17, 2015 17:49
This is simple bash script for counting MySQL queries.
#!/bin/bash
echo -e 'Id | Queries'
echo '-------------'
i=0
while [ $i -lt 10 ]
do
a=$(mysql -uroot -p1234 -e "show status like 'Queries'" | tail -1 | awk '{print $2}')
sleep 1
b=$(mysql -uroot -p1234 -e "show status like 'Queries'" | tail -1 | awk '{print $2}')
result=$[b-a]
@mortymacs
mortymacs / yt_href.py
Created June 4, 2013 17:12
Fetch youtube href(src) from html source code
#!/usr/bin/env python
import re
pattern = '.*<(iframe|param).*(src|value)="(?P<link>http://www.youtube.com/(embed|v)/[a-zA-Z0-9/\.\?&;=\+_-]+);?.*".*>.*</(iframe|param)>.*'
action = re.compile(pattern)
result = action.findall('<div><iframe.....></iframe><param......></param></div>')
print result
@mortymacs
mortymacs / fetch_var_value.py
Created June 11, 2013 06:07
Fetch variables name and value via python script.
import re
pattern = '\$*(?P<var>[a-zA-Z0-9_\.]+)\s*=\s*\'?\"?(?P<value>[a-zA-Z0-9_\+\.]*)\'?\"?'
#pattern = '\$*(?P<var>\w+)\s*=\s*\'?\"?(?P<value>\w*)\'?\"?'
action = re.compile(pattern)
data = '''
$firstname = "Morteza"
$last_name="ipo"
$age=23
@mortymacs
mortymacs / flask_httpd_apache.py
Created June 11, 2013 08:34
My config on Flask + Apache After serveral hours...
vim /etc/httpd/conf.d/s.conf
------------------------------
WSGISocketPrefix /var/run/wsgi
<VirtualHost *:80>
#WSGISocketPrefix /var/run/wsgi
WSGIDaemonProcess myapp user=apache group=apache threads=5
WSGIScriptAlias /myapp /var/www/html/myapp/myapp.wsgi
Alias /myapp /var/www/html/myapp
AddType text/html .py
<Directory /var/www/html/myapp>
@mortymacs
mortymacs / python_decorator.py
Created June 26, 2013 11:38
Simple python decorator.
#!/usr/bin/env python
session = False
def login_required(fn):
def ok(input):
if(session == True):
data = "welcome dear %s" % input
else:
data = "you are not logged in"
@mortymacs
mortymacs / random_ext.py
Created July 10, 2013 23:00
random_ext is a extra class for python random class. This class has shuffle_child.
#!/usr/bin/env python
import random
class random_ext():
@staticmethod
def shuffle_child(var,key,make=None):
'''
Shuffle child index