Skip to content

Instantly share code, notes, and snippets.

View mojaray2k's full-sized avatar

Amen Moja Ra mojaray2k

  • Miami, Fl
View GitHub Profile
@mojaray2k
mojaray2k / Ruby 1
Created August 14, 2013 09:51
These are the line of code that need to be included on your Mac's .bash_profile in order for mysql to work properly with Ruby on Rails
//Ruby Ron Ral .txt
export DYLD_LIBRARY_PATH="/usr/local/mysql/lib/:$DYLD_LIBRARY_PATH"
@mojaray2k
mojaray2k / HTACCESS 2
Created August 18, 2013 09:20
This is the basic rule to get clean urls on a website
RewriteEngine On
RewriteCond %(REQUEST_FILENAME) !-f
RewriteCond %(REQUEST_FILENAME) !-d
RewriteRule .* index.php
@mojaray2k
mojaray2k / APM Stack 1
Created August 18, 2013 09:40
These are some default bash commands for installing Apache, Mysql, and PHP
Installing The LAMP Stack On Apt-Get Machines
#apt-get update
#apt-get install mysql-server mysql-client libmysqlclient15-dev
#apt-get install apache2 apache2-doc apache2-mpm-prefork apache2-utils libexpat1 ssl-cert
#apt-get install libapache2-mod-php5 php5 php5-common php5-curl php5-dev php5-gd php5-idn php-pear php5-imagick php5-mcrypt php5-mysql php5-ps php5-pspell php5-recode php5-xsl
#apt-get install phpmyadmin
@mojaray2k
mojaray2k / HTACCESS 1
Created August 22, 2013 23:41
Wordpress .htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
@mojaray2k
mojaray2k / JavaScript 2
Created September 8, 2013 17:35
You can use the vanilla Javascript Dom Ready event without jQuery
//domready2.js
// without jQuery (doesn't work in older IEs)
document.addEventListener('DOMContentLoaded', function(){
// your code goes here
}, false);
// and here's the trick (works everywhere):
r(function(){
alert('DOM Ready!');
@mojaray2k
mojaray2k / domready.js
Created September 8, 2013 17:39 — forked from ded/domready.js
function r(f){/in/(document.readyState)?setTimeout(r,9,f):f()}
@mojaray2k
mojaray2k / routes.js
Created September 8, 2013 18:17
Here is one simple way to keep your code in check and avoid bugs: write a page routing function that executes only the JS that is needed for that particular page.
var route = {
_routes: {}, // The routes will be stored here
add: function(url, action) {
if( typeof url === 'string' ) { // if url isn't an array, convert it to an array
url = [url];
}
for (var i=0; i<url.length; i++) { // loop over the array elements
this._routes[url[i]] = action;
}
@mojaray2k
mojaray2k / and.js
Created September 8, 2013 20:27
The JavaScript logical AND operator doesn't evaluate the second expression if the first is false. You can use this to your advantage and save yourself from having to write a full if-statement:
// Instead of writing this:
if ($('#elem').length) {
// do something
}
// You can write this:
$('#elem').length && alert("doing something");
@mojaray2k
mojaray2k / is.html
Created September 8, 2013 20:41
The is() method is more powerful than you think. Here are a few examples:
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>jQuery Is Method</title>
</head>
<body>
<div id="elem"></div>
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
@mojaray2k
mojaray2k / number-of-elements.js
Created September 9, 2013 01:27
This simply passes the universal selector (which matches everything) to jQuery, and logs the number of elements found.
// How many elements does your page have? console.log('This page has ' + $('*').length + ' elements!');