Skip to content

Instantly share code, notes, and snippets.

View zachbrowne's full-sized avatar

Zach Browne zachbrowne

View GitHub Profile
@zachbrowne
zachbrowne / instructions.txt
Created November 30, 2012 14:42
Create MYSQL database
mysql -u root -p
CREATE DATABASE testing;
GRANT ALL PRIVILEGES ON testing.* TO test_user@localhost IDENTIFIED BY 'test_pass';
FLUSH PRIVILEGES;
@zachbrowne
zachbrowne / php.txt
Created November 27, 2012 20:16
Optimize PHP
1. If a method can be static, declare it static. Speed improvement is by a factor of 4.
2. echo is faster than print.
3. Set the maxvalue for your for-loops before and not in the loop.
4. Unset your variables to free memory, especially large arrays.
5. Avoid magic like __get, __set, __autoload
6. require_once() is expensive
7. Use full paths in includes and requires, less time spent on resolving the OS paths.
8. If you need to find out the time when the script started executing, $_SERVER['REQUEST_TIME'] is preferred to time()
9. See if you can use strncasecmp, strpbrk and stripos instead of regex
10. str_replace is faster than preg_replace, but strtr is faster than str_replace by a factor of 4
@zachbrowne
zachbrowne / DirectoryStructure.txt
Created November 22, 2012 18:45
Static app.yaml File for Hosting Static Websites on Google App Engine
audio
files
files/index.html
flash
fonts
images
javascript
stylesheets
videos
app.yaml
@zachbrowne
zachbrowne / app.yaml
Created November 22, 2012 18:11 — forked from darktable/app.yaml
GAE: App.yaml designed for serving a static site on Google App Engine (Python). Copy your static html and files into a folder called "static" next to app.yaml. Contains a bunch of mimetype declarations from html5boilerplate's .htaccess. May not be neces
application: you-app-name-here
version: 1
runtime: python
api_version: 1
default_expiration: "30d"
handlers:
- url: /(.*\.(appcache|manifest))
mime_type: text/cache-manifest
@zachbrowne
zachbrowne / instructions.txt
Created November 1, 2012 19:29
Install Ubuntu Desktop With NoMachine FreeNX on Ubuntu Server 12.04
This is a method to using your Ubuntu 12.04 server without the Unity desktop on a very fast remote desktop program. This is by far the best method to managing your Ubuntu server if you like GUI.
apt-get install --no-install-recommends ubuntu-desktop
apt-get --yes purge unity unity-2d unity-2d-places unity-2d-panel unity-2d-spread
apt-get --yes purge unity-asset-pool unity-services unity-lens-* unity-scope-*
apt-get --yes purge liboverlay-scrollbar*
apt-get --yes purge appmenu-gtk appmenu-gtk3 appmenu-qt
apt-get --yes purge firefox-globalmenu thunderbird-globalmenu
apt-get --yes purge unity-2d-common unity-common
apt-get --yes purge libunity-misc4 libunity-core-5*
@zachbrowne
zachbrowne / commands.txt
Created August 10, 2012 04:04
Ubuntu Commands Cheat Sheet
# Commands to backup a website from root access to ssh with mysql database
cd to directory of website
# Compress
tar czf filename.tar.gz *
mysqldump -u root -ppassword databasename | gzip -9 > filename.sql.gz
# Decompress
tar xzf filename.tar.gz
gunzip filename.sql.gz
@zachbrowne
zachbrowne / auto-post.php
Created August 9, 2012 06:45
Auto post status updates to Google+
<?php
// REQUIRED PARAMETERS
$status = 'http://www.mylink.com';
$email = 'your@email.com';
$pass = 'yourpassw0rd';
class SearchEngineReferrerMiddleware(object):
"""
Usage example:
==============
{% if request.session.search_engine %}
You searched for {{ request.session.search_term }} using {{ request.session.search_engine }}.
{% endif %}
"""
SEARCH_PARAMS = {
@zachbrowne
zachbrowne / instructions.txt
Created June 20, 2012 05:47
Install RVM in /root directory
Please note that if you want to install for root only, using a per-user install, then you must prepopulate root's $HOME/.rvmrc with the following BEFORE you attempt to install:
echo 'export rvm_prefix="$HOME"' > /root/.rvmrc
echo 'export rvm_path="$HOME/.rvm"' >> /root/.rvmrc
This overrides the checking done that assumes that if root is executing the install it must be a Multi-User installation type, and that RVM must go into /usr/local/rvm. This also negates the need to use sudo, as the combination of all these factors effectively turns it into a Per-User installation type specifically for the root user only. Please note that this is not a typical, or generally supported installation type.
Install RVM
curl -L https://get.rvm.io | sudo bash -s stable
@zachbrowne
zachbrowne / domain.tld
Created June 16, 2012 20:20
Set Up Nginx Virtual Host
mkdir -p /home/zach/domains/website.com/{public,logs}
nano /home/zach/domains/website.com/public/index.html
server {
listen 80;
server_name www.website.com;
rewrite ^/(.*) http://website.com/$1 permanent;
}