Skip to content

Instantly share code, notes, and snippets.

@cezr
cezr / mysqldump remote host
Last active May 12, 2016 20:01
Linux Commands
### MySQL commands ###
# Connect to a remote Database and dump the database
mysqldump -h [IP_ADDRESS] -u [USERNAME] -p [DATABASE_NAME] > [FILENAME.sql]
mysqldump -h [IP_ADDRESS] -u [USERNAME] -p [DATABASE_NAME] | gzip -9 > [FILENAME.sql.gz]
# In situations where the MySQL dump is large. A good approach is to split the uncompressed/SQL file
# into multiple files. Use the linux "split" command. Will make multiple files per 200 lines.
# i.e. dump_aa, dump_ab, dump_ac,....
cd /path/to/backup
mkdir splits
@cezr
cezr / iOS - UIScrollView focus to control
Last active May 12, 2016 20:01
iOS Dev Code Snippets
# Programatically move a UIScrollView to focus in a control above keyboard.
-(void) textFieldDidBeginEditing:(UITextField *)textField
{
CGRect rect = [textField bounds];
rect = [textField convertRect:rect toView:self.scrollView];
rect.origin.x = 0;
rect.origin.y -= 60;
rect.size.height = 400;
[scrollView scrollRectToVisible:rect animated:YES];
@cezr
cezr / example.conf
Last active May 12, 2016 19:59
Ubuntu Helper Upstart-job NGINX + Gunicorn
# /etc/init/example.conf
# Example Startup Script
# Created by Cesar
#
# Replace all "example" with project name, then register this after creating using:
# ln -fs /lib/init/upstart-job /etc/init.d/example
# update-rc.d example defaults
#
# You can now manage this application as a service, with:
# service example start/restart/reload/stop
server {
# Example Server Configuration
# Created by Cesar
listen 80;
server_tokens off;
server_name example.com;
root /var/www/;
import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "Example.settings")
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
@cezr
cezr / demodays.conf
Last active May 12, 2016 19:57
Upstart Job Example for Django + Gunicorn
# /etc/init/example.conf
# Example Startup Script
# Created by Cesar
#
# Replace all "example" with project name, then register this after creating using:
# ln -fs /lib/init/upstart-job /etc/init.d/example
# update-rc.d example defaults
#
# You can now manage this application as a service, with:
# service example start/restart/reload/stop
#mysql connect
mysql -u root -h localhost -p
#list all databses
show databases;
#Use database
use database_name;
#Create user
##MySQL connection is blocked
MySQL connection is blocked of many connections errors; unblock with 'mysqladmin flush-hosts
Your IP is blocked because you have attempted to log-into the MySQL server too many times
without the correct username/password, as per the error:
Host '*****************' is blocked because of many connection errors; unblock with 'mysqladmin flush-hosts'
To fix, log-into your MySQL server console and execute a FLUSH HOSTS command.
If this is on shared hosting, deleting and recreating the database will work. In my own experience many
web-hosts tend to say it's your MySQL database, it's your problem. Unless you want to wait a long time for
##Server requirments
- Web Server (public access)
- Python 2.7 (available by default in Ubuntu >12.04 or via manual installation)
- MySQL > 5.1 with access to a single database
- PIP Python module (for installing Django and any additional packages)
- Python Virtual env (not required, but highly recommended)
- Read more: http://docs.python-guide.org/en/latest/dev/virtualenvs/
- Apache web server with mod_wsgi
- Read more: https://docs.djangoproject.com/en/1.6/howto/deployment/wsgi/modwsgi/
#1
##Follow virtualenv gist
https://gist.github.com/cezr/b986b69e6fbdffb8eb3d
#2
## Quick Install ##
On Ubuntu 12.04, the following requirements will satisfy the project's system components:
sudo aptitude install libapache2-mod-wsgi
sudo apt-get install libmysqlclient-dev