Alpha
Share and Organize Code
login register
HotNewTop
F.A.Q.
1. To begin adding code first register.
2. Create your own tags for code that you add.
3. To see your own code click Me, to see all code click Everyone, or filter by people rob.
4. To follow a user, click on their username, rob and hit follow.
5. Add other code to your library by clicking the
button near the code titles (note that you can not edit these codes).
6. To create a copy of a code that you can edit use fork.
7. If you can't find your code, double check your filter settings as you can filter by Category, User and Tag simultaneously.
8. Add comments to a code by clicking on it's title or the comments link underneath it.

Hide status bar (plain)

1
2
ADD: "Status bar is initially hidden" to myApp-Info.plist
SET VALUE "YES" or TRUE
comments (1) flag fork

Select Elements That Have an id Attribute Specified (plain)

1
2
3
4
5
6
7
8
9
10
$.extend($.expr[':'],
{
    hasId: function(el)
    {
        return $(el).attr('id') !== undefined && $(el).attr('id') !== '';
    }
});

// usage
$("#container :hasId");
[+] (6) more...
comments (0) flag fork

Select Elements That Have the Specified Color Value in rgb(x, x, x) Format (plain)

1
2
3
4
5
6
7
8
9
10
11
$.extend($.expr[':'],
{
    color: function(el, i, m)
    {
        if(!m[3]) {return false;}
        return $(el).css('color') === m[3];
    }
});

// usage
$("#container :color(rgb(255, 0, 0))");
[+] (7) more...
comments (0) flag fork

Select Elements That Have a CSS font-weight of 700 (bold) (plain)

1
2
3
4
5
6
7
8
9
10
$.extend($.expr[':'],
{
    isBold: function(el)
    {
        return $(el).css("fontWeight") === '700';
    }
});

// usage
$("#container :isBold");
[+] (6) more...
comments (0) flag fork

Select Elements Larger Than the Specified Element (plain)

1
2
3
4
5
6
7
8
9
10
11
$.extend($.expr[':'],
{
    largerThan: function(el, i, m)
    {
        if(!m[3]) {return false;}
        return $(el).width() * $(el).height() > $(m[3]).width() * $(m[3]).height();
    }
});

// usage
$("#container :largerThan(#element)");
[+] (7) more...
comments (0) flag fork

Selects All Anchors With the Specified Target Value (plain)

1
2
3
4
5
6
7
8
9
10
11
12
13
$.extend($.expr[':'],
{
    target: function(el, i, m)
    {
        if(!m[3]) {return false;}
        return (m[3] === '_self' && ($(el).attr('target') == '' || !el.target)) || (m[3] === $(el).attr('target'));
    }
});

// usage
$("#container :target(_self)");
$("#container :target(_parent)");
$("#container :target(frameName)");
[+] (9) more...
comments (0) flag fork

Selects All Anchor Tags With a Domain Different Than the Current Domain (plain)

1
2
3
4
5
6
7
8
9
10
11
$.extend($.expr[':'],
{
    external: function(el)
    {
        if(!el.href) {return false;}
        return el.hostname && el.hostname !== window.location.hostname;
    }
});

// usage
$("#container :external");
[+] (7) more...
comments (0) flag fork

Selects all Elements to the Right of the Specified Element (plain)

1
2
3
4
5
6
7
8
9
10
11
12
13
$.extend($.expr[':'],
{
    rightOf: function(el, i, m)
    {
        var oe = $(el).offset();
        var om = $(m[3]).offset();

        return oe.left > om.left + $(m[3]).width();
    }
});

// usage
$("#container :righttOf(#element)");
[+] (9) more...
comments (0) flag fork

Selects all Elements to the Left of the Specified Element (plain)

1
2
3
4
5
6
7
8
9
10
11
12
13
$.extend($.expr[':'],
{
    leftOf: function(el, i, m)
    {
        var oe = $(el).offset();
        var om = $(m[3]).offset();

        return oe.left + $(el).width() < om.left;
    }
});

// usage
$("#container :leftOf(#element)");
[+] (9) more...
comments (0) flag fork

Select Elements With HeightGreater Than or Less Than the Specified Value (plain)

1
2
3
4
5
6
7
8
9
10
11
12
$.extend($.expr[':'],
{
    height: function(el, i, m)
    {
        if(!m[3]||!(/^(<|>)\d+$/).test(m[3])) {return false;}
        return m[3].substr(0,1) === '>' ? $(el).height() > m[3].substr(1) : $(el).height() < m[3].substr(1);
    }
});

// usage
$(".container:height(>100)");
$("#container :height(<100)");
[+] (8) more...
comments (0) flag fork

Select Elements With Width Greater Than or Less Than the Specified Value. (plain)

1
2
3
4
5
6
7
8
9
10
11
12
$.extend($.expr[':'],
{
    width: function(el, i, m)
    {
        if(!m[3]||!(/^(<|>)\d+$/).test(m[3])) {return false;}
        return m[3].substr(0,1) === '>' ? $(el).width() > m[3].substr(1) : $(el).width() < m[3].substr(1);
    }
});

// usage
$(".container:width(>100)");
$("#container :width(<100)");
[+] (8) more...
comments (0) flag fork

Check if an Element is "loaded" (plain)

1
2
3
4
5
6
7
8
$.extend($.expr[':'],
{
    loaded: function(el) { return $(el).data('loaded'); }
});

// usage
$("img").load(function(){ $(this).data("loaded", true); });
$("#container img:loaded");
[+] (4) more...
comments (1) flag fork

Load jQuery From Google With Graceful (local) Fallback (plain)

1
2
3
4
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script>
    window.jQuery || document.write('<script src="js/libs/jquery-1.7.1.min.js"><\/script>');
</script>
comments (0) flag fork

Prevent Hotlinking (plain)

1
2
3
4
RewriteEngine On
RewriteCond %{HTTP_REFERER} !^$  
RewriteCond %{HTTP_REFERER} !^http://(www\.)?domain.com/ .*$ [NC]  
RewriteRule \.(gif|jpg|swf|flv|png)$ /feed/ [R=302,L]
comments (1) flag fork

Set up a Default Image (plain)

1
2
3
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f  
RewriteRule ^images/.*\.jpg$ /images/default.jpg [L]
comments (1) flag fork

Strip Query Strings (plain)

1
2
3
RewriteEngine On
RewriteCond %{QUERY_STRING} example=  
RewriteRule (.*) http://www.domain.com/$1? [R=301]
comments (1) flag fork

Block User Agents (plain)

1
2
3
4
RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} UserAgentA [OR]  
RewriteCond %{HTTP_USER_AGENT} UserAgentB
RewriteRule ^/* http://www.domain.com/sorry.html [L]
comments (1) flag fork

Block a Specific IP Address (plain)

1
2
3
RewriteEngine On
RewriteCond %{REMOTE_ADDR} ^(A\.B\.C\.D)$
RewriteRule ^/* http://www.domain.com/sorry.html [L]
comments (1) flag fork

Redirect Request For domain.com To www.domain.com (plain)

1
2
3
RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain\.com$
RewriteRule ^(.*) http://www.domain.com/$1 [R=301,L]
comments (1) flag fork

Redirect Anything That Starts With a Specific Pattern to Index (plain)

1
2
3
RewriteEngine On
RewriteCond $1 !^(index\.php|images|css|javascript)
RewriteRule ^(.*)$ /index.php/$1 [L]
comments (1) flag fork

Temporary Maintenance Page (plain)

1
2
3
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/maintenance\.html$
RewriteRule ^(.*)$ http://domain.com/maintenance.html [L]
comments (1) flag fork

Relaxing Security in a Subdirectory (plain) (source)

1
2
3
4
5
6
7
8
9
10
<Directory /var/www>
    Satisfy All
    AuthUserFile /etc/apache/htpasswd
    Require valid-user
</Directory>

#put in .htaccess file in any sub directory you want to allow access to.
Satisfy Any
Order Deny,Allow
Allow from all
[+] (6) more...
comments (1) flag fork

Deny other servers from accessing your files (plain)

1
2
3
4
5
<FilesMatch "\.(gif|jpe?g)$">
    SetEnvIf Referer "^http://([^/]*\.)?domain.com/" request_ok = 1
    Order Allow, Deny
    Allow from env=request_ok
</FilesMatch>
[+] (1) more...
comments (0) flag fork

Setup alias to an alternate directory (plain)

1
2
3
4
5
6
<VirtualHost *:80>
    ServerName domain.com

    DocumentRoot /home/www/www.domain.com
    Alias /phpmyadmin "/home/www/phpmyadmin"
</VirtualHost>
[+] (2) more...
comments (0) flag fork

Allow Apache to access all projects within directory (plain)

1
2
3
4
5
6
<Directory "/path/to/projects">
    Options FollowSymLinks
    AllowOverride All
    Order deny,allow
    Allow from all
</Directory>
[+] (2) more...
comments (0) flag fork

Only Allow a Specific IP Address (plain)

1
2
3
RewriteEngine On
RewriteCond %{REMOTE_ADDR} !^A\.B\.C\.D$
RewriteRule ^ https://domain.com/ [R]
comments (1) flag fork

Show Server Load Avg (plain)

1
2
3
4
5
6
#!/usr/bin/perl

my $uptime = `uptime | sed "s/.*load average: //g" | head -n1`;
chomp($uptime);

print $uptime . "\n";
[+] (2) more...
comments (1) flag fork

MySQL Match Against (plain)

1
2
MATCH(c.code, c.title) AGAINST ('keyword' IN NATURAL LANGUAGE MODE)
MATCH(c.code, c.title) AGAINST ('keyword' IN BOOLEAN MODE)
comments (0) flag fork

Restart Server (plain)

1
2
3
4
5
6
# Shutting down your server this way depending on platform...
# will most likely cause the server to run fsck during start up
shutdown -r now

# Shutdown this way for a faster reboot...
reboot
[+] (2) more...
comments (0) flag fork

Get URL parts (plain)

1
2
window.location.hostname
window.location.pathname
comments (0) flag fork