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.

Add php.ini to OS X (plain) (source)

1
2
3
sudo cp /private/etc/php.ini.default /private/etc/php.ini

;When no config is used, you may get a timezone error when parsing php
comments (0) flag fork

Display PHP Config Used (plain)

1
2
3
php -i | grep -i configuration

; Good for showing php.ini use and location
comments (0) flag fork

List Tables Using MyISAM (plain)

1
2
3
4
5
/* Within MySQL Shell you can use this: */

SELECT table_schema, table_name, engine FROM information_schema.tables WHERE engine='myisam' AND table_schema NOT IN ('mysql','performance_schema','information_schema');

/* This will list all tables using MyISAM excluding default mysql table schemas. */
[+] (1) more...
comments (0) flag fork

File Descriptor Limit (plain)

1
2
3
4
5
6
7
8
9
10
11
12
# Total file descriptor limit
sysctl fs.file-nr
# User limit
ulimit -Hn
# Find out how many file descriptors are in use by user
sudo lsof -u <username> 2>/dev/null | wc -l

# Increase file descriptor limit for a user
echo "username hard nofile 64000" >> /etc/security/limits.conf
echo "ulimit -n 64000" >> /home/username/.bashrc ; echo "ulimit -n 64000" >> /home/username/.bash_profile*

# tested in centos
[+] (8) more...
comments (1) flag fork

Remove Comments and Empty Lines (plain)

1
2
3
4
5
6
7
# Example using /etc/my.cnf to easily view DB config in Linux
grep -v -e ^# -e ^$ /etc/my.cnf

# copy to new file...
grep -v -e ^# -e ^$ /etc/my.cnf > /etc/my-nocomments.cnf

# tested in bash amazon ec2 instance ubuntu 12.04
[+] (3) more...
comments (0) flag fork

Bash While Loop (plain)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#!/bin/bash
# Tested & Created in CentOS

ENVARRAY=(
dev
qa
prd
)

ENV=${#ENVARRAY[*]}
i=0

while [ $i -lt $ENV ]; do
        echo "${ENVARRAY[$i]}"
let i++
done

# Output will be
# dev
# qa
# prd
[+] (17) more...
comments (0) flag fork

Show Table Row Counts (plain)

1
2
SELECT TABLE_SCHEMA,TABLE_NAME, TABLE_ROWS FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA IN ('db1','db2','db3') ORDER BY `TABLE_SCHEMA`, `TABLE_NAME`, `TABLE_ROWS`;
/* This will show you database table counts */
comments (0) flag fork

Size of All tables in MySQL (plain)

1
2
3
4
5
6
7
8
/* Size of ALL Table Schemas in GB and MB */
SELECT round(sum(((data_length + index_length)/1024/1024/1024)),2) GB, round(sum(((data_length + index_length)/1024/1024)),2) MB FROM information_schema.TABLES;

/* Size of ALL Table Schemas Ordered by Table Schema Name */
SELECT TABLE_SCHEMA, TABLE_NAME, round(((data_length + index_length)/1024/1024/1024),2) GB, round(((data_length + index_length)/1024/1024),2) MB FROM information_schema.TABLES ORDER BY TABLE_SCHEMA, TABLE_NAME;

/* You can also filter on
Database (Table_Schema) Name, Order by Size, etc */
[+] (4) more...
comments (0) flag fork

Top 3 Processes Using RAM (plain)

1
2
3
4
# after using free -m OR free -g ... you may like to know what's using up the RAM:
ps auxf | sort -nr -k 4 | head -3

# Tested / used on Ubuntu and CentOS
comments (0) flag fork

SSH - Convert Win Pub Key to Linux (plain)

1
2
3
4
5
6
7
# This assumes you generated a keypair on a Windows client with puttygen for a Linux server
ssh-keygen -i -f ~/.ssh/id_rsa_win.pub > ~/.ssh/id_rsa.pub
# OR convert it and add it directly to ~/.ssh/authorized_keys file on Linux server
ssh-keygen -i -f ~/.ssh/id_rsa_win.pub >> ~/.ssh/authorized_keys

# SSH key pair notes:
# PUB key always goes on server / PRIVATE key saved on local client
[+] (3) more...
comments (0) flag fork

Monitor Network, Disc, CPU, RAM Simultaneously (plain) (source)

1
2
3
4
# --- Install dstat: Improved systat like system monitoring tool
dstat -talm

# --- Very useful for any Sys Admin
comments (1) flag fork

SHOW tips (plain)

1
2
3
4
5
6
7
8
9
10
/* From your MySQL client you can get a lot of good info with SHOW cmds */
SHOW TABLE STATUS;
SHOW TABLE STATUS LIKE "%partial_table_name%";
SHOW TABLE STATUS WHERE Rows > 15000;
SHOW TABLE STATUS WHERE Rows > 15000 AND Index_length > 52564;

/* Some probably don't know you can have WHERE clauses in your SHOW cmds */


/* Enjoy */
[+] (6) more...
comments (0) flag fork

Generate GRANT Statements (plain)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#!/bin/bash
mysql -N -ss -u root -p -e"SELECT CONCAT('SHOW GRANTS FOR ', user, '@', host, ';') FROM mysql.user;" > ~/showgrants.sql
sed -i "s/FOR /FOR '/g" ~/showgrants.sql
sed -i "s/@/'@'/g" ~/showgrants.sql
sed -i "s/;/';/g" ~/showgrants.sql
mysql < ~/showgrants.sql > ~/grants.sql

# --- OR

mysql -N -ss -u root -p -e"SELECT CONCAT('SHOW GRANTS FOR ', user, '@', host, ';') FROM mysql.user;" > ~/showgrants.sql
sed "s/FOR /FOR '/g" ~/showgrants.sql > ~/showgrantsa.sql
sed "s/@/'@'/g" ~/showgrantsa.sql > ~/showgrantsb.sql
sed "s/;/';/g" ~/showgrantsb.sql > ~/showgrantsc.sql
mysql -N -ss -u root -p < ~/showgrantsc.sql > ~/grants.sql

# --- Don't forget to add the mysql delimiters in ~/grants.sql since they aren't added by default.
# --- Feel free to alter or improve in anyway



#
[+] (17) more...
comments (1) flag fork

Whitelist urls for iOS (plain)

1
2
3
4
ADD: "EternalHosts" to PhoneGap.plist
SET VALUE in the array to "*" for all URLS
OR "www.url.com" for specific URL
ALSO *.url.com for all sub-domains for a given url
comments (0) flag fork

Display Table Schema Sizes (plain)

1
SELECT table_schema, sum(data_length+index_length)/1024/1024/1024 "Gigs" FROM information_schema.tables GROUP BY table_schema;
comments (1) flag fork

Execute Shell Script on Multiple Servers from 1 Host (plain)

1
2
3
4
5
6
7
8
9
# Bash Script
ssh -p 22 user@remotehost exec /bin/bash -s "$LE_PATH" < /usr/local/bin/shellscript
# Perl Script
ssh -p 22 user@remotehost exec /bin/perl -s "$LE_PATH" < /usr/local/bin/shellscript

# --- If you have a script you normally execute locally on a machine and you want to run your scripts on multiple machines from a centralized location, this is a good method.
# --- Just ensure you have key pair access set up accordingly between machines
#
#
[+] (5) more...
comments (1) flag fork

List and remove a stash (plain)

1
2
git stash list
git stash drop stash@{0}
comments (0) flag fork

Remove working directory changes and reset to last commit (plain)

1
git reset --hard
comments (0) flag fork

Hide Spinner when app loading (plain)

1
2
ADD: "ShowSplashScreenSpinner" to PhoneGap.plist
SET VALUE "NO" or FALSE
comments (0) flag fork

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

Select Elements That Have Any Portion Within the Viewing Window (plain)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
$.extend($.expr[':'],
{
    inView: function(el)
    {
        var offset = $(el).offset();

        return !(
            (offset.top > $(window).height() + $(document).scrollTop()) ||
            (offset.top + $(el).height() < $(document).scrollTop()) ||
            (offset.left > $(window).width() + $(document).scrollLeft()) ||
            (offset.left + $(el).width() < $(document).scrollLeft())
        )
    }
});

// usage
$(#container :inView")
[+] (13) 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