Skip to content

Instantly share code, notes, and snippets.

View codfish's full-sized avatar

Chris O'Donnell codfish

View GitHub Profile
@codfish
codfish / unload_apache.sh
Last active August 29, 2015 14:06
Stop apache permanently on mac Mavericks. This will stop a running instance of Apache, and record that it should not be restarted. It records your preference in /private/var/db/launchd.db/com.apple.launchd/overrides.plist. http://goo.gl/J26slP
# ** you need to have an apache instance running already for this command to work.
sudo apachectl start
sudo launchctl unload -w /System/Library/LaunchDaemons/org.apache.httpd.plist
@codfish
codfish / angularIgnoreRegularLinks.js
Last active August 29, 2015 14:07
Prevent regular links from not working once angular bootstraps.
@codfish
codfish / angularSafeApply.js
Created October 24, 2014 17:39
Angular safe apply
$rootScope.safeApply = function (fn) {
var phase = this.$root.$$phase;
if (phase == '$apply' || phase == '$digest') {
if (fn && (typeof(fn) === 'function')) {
fn();
}
} else {
this.$apply(fn);
}
};
@codfish
codfish / custom_vagrant.sh
Created October 29, 2014 13:21
Create and customize a Vagrant box. reference: http://goo.gl/NfQrL4
# choose a box as a starting point
vagrant init hashicorp/precise64
vagrant up
vagrant ssh
# customize the box to your liking, for example:
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install vim
sudo apt-get install apache2
@codfish
codfish / get_table_sizes.sql
Last active August 29, 2015 14:09
Here is a super simple SQL query to determine the size of all tables in a given database. References: http://goo.gl/7jFF5y, http://goo.gl/cBZKWW
-- only thing you need to supply is the database name in the WHERE statement
SELECT TABLE_NAME AS "Table",
round(((data_length + index_length) / 1024 / 1024), 2) AS Size_in_MB
FROM information_schema.TABLES
WHERE table_schema = '%%database%%'
ORDER BY Size_in_MB DESC
@codfish
codfish / msword_to_ascii.php
Last active August 29, 2015 14:12
This function strips incompatible iso characters from ms office documents. If no ascii conversion is found the character is ignored.
/**
* This function strips incompatible iso characters
* from ms office documents. If no ascii conversion is found
* the character is ignored.
*
* @author hannuraina
* @param array|string $replace value(s) to replace
* @return array|string $items
*/
function msword_to_ascii($replace) {
@codfish
codfish / check_dns.sh
Created January 5, 2015 19:55
Check DNS of a domain/subdomain to see if it's properly configured using whois & dig
# returns whois info for the domain, including name servers
whois codfish.io
# use dig to lookup any subdomain on a name server(s)
dig @ns-371.awsdns-46.com codly.codfish.io
# dig will output details of the lookup. If configured properly you should see
# the details in the ANSWER SECTION ... e.g.
;; ANSWER SECTION:
codly.codfish.io. 300 IN CNAME codly.herokuapp.com.
@codfish
codfish / curl_headers.sh
Created January 20, 2015 18:05
Just request a page's headers using curl
curl -I
# or curl --head
@codfish
codfish / wp_admin_redirect.sh
Last active August 29, 2015 14:14
Scenario: You use a subdomain for your WP Admin separate from your blogs main domain, i.e. admin.superblog.com. You want to make sure only requests to the WP admin use this subdomain. This apache rewrite logic redirects all non-admin traffic away from admin domain to the homepage, keeping in mind that preview urls should also be included as an a…
RewriteEngine On
RewriteBase /
# http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html
# "If you wish to match against the full URL-path in a per-directory (htaccess) RewriteRule,
# use the %{REQUEST_URI} variable in a RewriteCond."
RewriteCond %{HTTP_HOST} ^admin.superblog.com$
RewriteCond %{REQUEST_URI} !^(/wp-admin|/wp-login|/wp-content|/wp-includes)
RewriteCond %{QUERY_STRING} !^(.*?)preview=true(.*?)$
RewriteRule (.*) http://superblog.com? [R=301,L] # the trailing ? after the domain makes sure to remove any query string params from the original request
@codfish
codfish / apache_response_code_counts.sh
Last active August 29, 2015 14:14
Get apache response code counts for your site from access log
cat example.com-access.log | awk '{print $9}' | sort | uniq -c | sort -nr
# Example Output:
# 545475 200
# 153819 304
# 99102 301
# 13346 404
# 8027 206
# 3822 302