Skip to content

Instantly share code, notes, and snippets.

View fduran's full-sized avatar

Fernando Duran fduran

View GitHub Profile
// www.fduran.com
// send mail with Amazon AWS SES without extra library
// needs Pear: apt-get install php-pear
<?php
function mailSES($to, $subject, $body, $from)
{
include_once('Mail.php');
$headers["From"] = $from;
$headers["To"] = $to;
# www.fduran.com
# delete files in a folder older than a number of days (100 for example)
find /path/to/folder -mtime +100 -exec rm -f {} \;
@fduran
fduran / gist:4622779
Created January 24, 2013 15:09
MySQL Master-Slave Replication
# www.fduran.com
MySQL Master-Slave Replication Notes
Master
/etc/mysql/my.cnf
server-id = 100
log_bin = /var/log/mysql/mysql-bin.log
binlog-do-db = wpdb
binlog-ignore-db = mysql
@fduran
fduran / gist:4586880
Created January 21, 2013 15:35
Create Java KeyStore from SSL certificate
# www.fduran.com
# Create Java KeyStore from SSL certificate for domain example.com
# Change format from cert.crt PEM (----BEGIN CERTIFICATE----- ... -----END CERTIFICATE-----) to DER
openssl x509 -in cert.crt -inform PEM -out cert.der -outform DER
# create KeyStore cert.jks for your domain ("alias" in keytool, "common name" or CN in openssl req)
keytool -import -trustcacerts -alias example.com -file cert.der -keystore cert.jks
@fduran
fduran / gist:4543001
Last active May 9, 2018 18:35
Python script to test/monitor if a Django site using authentication is up
# www.fduran.com
# python script to test/monitor if a Django site using authentication is up
# with logging output to a file including response times
# use in cronjob and output to log file, for ex: python /path/to/script.py >> /var/log/webmonitor.log
# bash: install pip if not already in system
apt-get install python-setuptools python-dev build-essential
easy_install -U pip
# bash: install requests
@fduran
fduran / gist:4514042
Created January 11, 2013 21:18
Linux "Too many files open" error
# www.fduran.com
# Linux "Too many files open" error
# check current number of open files:
lsof |wc -l
# check maximum number of file descriptors
sysctl -a |grep file-max
# increment value: edit
@fduran
fduran / gist:4271982
Created December 12, 2012 21:54
Apache2 optimization
# www.fduran.com
# Apache2 optimization
# apache-wide (/etc/apache2/apache2.config ):
# compression
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css application/javascript
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
@fduran
fduran / gist:4271967
Created December 12, 2012 21:52
Apache Redirect Subdomain to port
# www.fduran.com
# redirect from apache port (:8080 for ex for tomcat etc) to subdomain
# in apache config:
<VirtualHost *:80>
ServerName subdomain.example.com
ProxyPass / http://127.0.0.1:8080/
ProxyPassReverse / http://127.0.0.1:8080/
</VirtualHost>
@fduran
fduran / gist:4271952
Created December 12, 2012 21:49
Linux find files opened for writing
# www.fduran.com
# files opened for writing
lsof | grep -e "[[:digit:]]\+w"
@fduran
fduran / CloudFlareAlwaysOnline.html
Created October 24, 2012 22:18
CloudFlare Always Online
<h1>CloudFlare Always Online</h1>
<b>Summary:</b> I'd like to know if CloudFlare's <a href="http://www.cloudflare.com/always-online">Always Online</a> works when a web server goes completely down (server unresponsive).
1) According to CloudFlare's web site, the answer seems to be "yes" (emphasis mine):
<ul>
<li><a href="http://www.cloudflare.com/always-online">Description of the service</a>: Always Online is a feature that caches a static version of your pages in case your <b>server goes offline</b>.</li>
<li><a ref="http://blog.cloudflare.com/always-online-because-downtime-sucks">Blog entry</a>: "If, for any reason, your web host or service provider <b>goes down</b>, we kick in to keep your site online"</li>
<li><a href="https://cloudflare.tenderapp.com/kb/troubleshooting/why-doesnt-always-online-display-all-pages-of-my-site-when-my-server-is-down">KB documentation</a>: on the point 7: "In order to trigger Always Online, your web server will need to be <b>completely unresponsive</b>, or ..."</li>
<li>In a