Skip to content

Instantly share code, notes, and snippets.

View redteam-snippets's full-sized avatar

redteam-snippets

View GitHub Profile
@redteam-snippets
redteam-snippets / decimalToFraction.js
Created October 22, 2012 21:02
JavaScript: Decimal To Fraction
// Adapted from: http://bateru.com/news/2011/11/improved-code-for-javascript-decimal-to-fraction/
function gcd(a, b) {
return (b) ? gcd(b, a % b) : a;
}
var decimalToFraction = function (_decimal) {
var top = _decimal.toString().replace(/\d+[.]/, '');
var bottom = Math.pow(10, top.length);
if (_decimal > 1) {
@redteam-snippets
redteam-snippets / db_connection.php
Created October 15, 2012 18:43
Magento DB Connection
<?php
//Magento DB connection
include("/path/to/app/Mage.php");
$app = Mage::app('default');
$db = Mage::getSingleton('core/resource')->getConnection('core_read');
?>
@redteam-snippets
redteam-snippets / InfiniteScrollingTableView.js
Created October 12, 2012 14:28 — forked from dawsontoth/InfiniteScrollingTableView.js
Infinite loading table view for iOS and Android.
/**
* We're going to create an infinite loading table view. Whenever you get close to the bottom, we'll load more rows.
*/
var win = Ti.UI.createWindow({ backgroundColor: '#fff' });
var isAndroid = Ti.Platform.osname === 'android';
/**
* Create our UI elements.
*/
var table = Ti.UI.createTableView({ top: 0, right: 0, bottom: 0, left: 0 });
@redteam-snippets
redteam-snippets / gist:3768927
Created September 23, 2012 04:59
Javascript: Calculate Resize Dimensions
function calculateResize (_params) {
var ratio = 0;
var output = {
width : _params.current_width,
height : _params.current_height
};
if(_params.current_width > _params.max_width){
ratio = _params.max_width / _params.current_width;
output.width = parseInt(_params.max_width, 10);
@redteam-snippets
redteam-snippets / states.html
Created August 20, 2012 14:32
HTML: USA State List - Abbr Value - Full Name Label
<!-- US States Drop Down Select List -->
<select id="ddl_state" name="ddl_state">
<option value="AL" selected="selected">Alabama</option>
<option value="AK">Alaska</option>
<option value="AZ">Arizona</option>
<option value="AR">Arkansas</option>
<option value="CA">California</option>
<option value="CO">Colorado</option>
<option value="CT">Connecticut</option>
@redteam-snippets
redteam-snippets / javascript.limit.character.input.js
Created August 3, 2012 16:29
javascript: limit characters in field example
$('#myField').bind('keyup', function (e) {
$(this)[0].value = $(this)[0].value.replace(/[^0-9\.]/g, '');
});
@redteam-snippets
redteam-snippets / gist:2353695
Created April 10, 2012 19:01
Javascript: Get JSON Key / Values From Array of JSON Objects
var headers = [
{"Authentication" : "AUTH_KEY"},
{"rememberMe" : true}
];
// ===============================================================
for (var i = 0, j = headers.length; i < j; i = i + 1) {
Object.keys(headers[i]).forEach(function (header) {
console.log(header + ' = ' + headers[i][header]);
@redteam-snippets
redteam-snippets / gist:2286949
Created April 2, 2012 20:20
Terminal: Watch Live Log Feed
tail -f filename.log
@redteam-snippets
redteam-snippets / gist:2002065
Created March 8, 2012 16:58
HTML: USA State List - Full Name Value - Full Name Label
<!-- US States Drop Down Select List -->
<select id="ddl_state" name="ddl_state">
<option value="Alabama" selected="selected">Alabama</option>
<option value="Alaska">Alaska</option>
<option value="Arizona">Arizona</option>
<option value="Arkansas">Arkansas</option>
<option value="California">California</option>
<option value="Colorado">Colorado</option>
<option value="Connecticut">Connecticut</option>
@redteam-snippets
redteam-snippets / gist:2002044
Created March 8, 2012 16:54
MySQL: Backup Database
mysqldump --opt -u dbuser -p dbname > filename.back.dump