Posted by Andy Nagai on May 08, 2013
The following will install a stable chromium release.
1) Create file /etc/yum.repos.d/fedora-chromium-stable.repo with this content. Create as root.
[fedora-chromium-stable]
name=Builds of the "stable" tag of the Chromium Web Browser
baseurl=http://repos.fedorapeople.org/repos/spot/chromium-stable/fedora-$releasever/$basearch/
enabled=1
skip_if_unavailable=1
gpgcheck=0
[fedora-chromium-stable-source]
name=Builds of the "stable" tag of the Chromium Web Browser - Source
baseurl=http://repos.fedorapeople.org/repos/spot/chromium-stable/fedora-$releasever/SRPMS
enabled=0
skip_if_unavailable=1
gpgcheck=0
2) Install
sudo yum install chromium -y
Posted by Andy Nagai on Apr 26, 2013
Go to Preferences -> Settings Default
// Set to true to removing trailing white space on save
“trim_trailing_white_space_on_save”: true,
// Auto wrap at column 80
“wrap_width”: 80,
// Show ruler at column 80
“rulers”: [80],
// Set to true to insert spaces when tab is pressed
“translate_tabs_to_spaces”: true,
// Set line ending to unix style
“default_line_ending”: “unix”,
Posted by Andy Nagai on Mar 01, 2013
Whenever passing base64 encoded strings in url should always urlencode or do the following which replaces characters that should not be in a query string value with safe characters so query string will not be malformed. When you use the encode method must also use the decode method to convert those characters back to the original.
/**
* Custom base64 encoding. Replace unsafe url chars
*
* @param string $val
* @return string
*/
static function base64_url_encode($val) {
return strtr(base64_encode($val), '+/=', '-_,');
}
/**
* Custom base64 decode. Replace custom url safe values with normal
* base64 characters before decoding.
*
* @param string $val
* @return string
*/
static function base64_url_decode($val) {
return base64_decode(strtr($val, '-_,', '+/='));
}
Posted by Andy Nagai on Feb 28, 2013
Use this method when you need to open a new window into a tab and not into a popup window through javascript. This should work in most browsers if settings have not been altered.
function open_in_tab(url) {
var win = window.open(url, '_blank');
win.focus();
}
Opening window into tab after Ajax Call
window.open() will only open into a tab if it’s result of direct user action. Must make javascript think clicking button is the result of button click after the ajax call. Danger of running ajax synchronously is page can freeze waiting for the request. You can open a window into a tab after an AJAX call with the following:
$('#btn').on("click", function(){
$.ajax({
type: 'POST',
url: "ajax.php",
data: {action: 'update'},
dataType: 'json',
context: document.body,
async:false, //Send Synchronously
success: function(resp){
if(resp.success) {
window.open('http://google.com'); //Will open into a tab
}
}
});
})
Posted by Andy Nagai on Feb 21, 2013
You can set custom error messages using the built-in php upload error constants.
http://www.php.net/manual/en/features.file-upload.errors.php
$upload_errors = array (
UPLOAD_ERR_OK => 'No errors.',
UPLOAD_ERR_INI_SIZE => 'Larger then upload_max_filesize.',
UPLOAD_ERR_FORM_SIZE => 'File size is to large!',
UPLOAD_ERR_PARTIAL => 'Resume partially uploaded!',
UPLOAD_ERR_NO_FILE => 'You must upload a resume!',
UPLOAD_ERR_NO_TMP_DIR => 'Temporary directory does not exist!',
UPLOAD_ERR_CANT_WRITE => "Can't write to disk!",
UPLOAD_ERR_EXTENSION => 'File upload stopped by extension!'
);
......
// After form post get file info
$file = $_FILES['uploaded_file'];
// If there was an error during upload then display custom message
if ($file['error'] != 0) {
echo $upload_errors[$file['error']]);
}
Posted by Andy Nagai on Feb 04, 2013
This will extract just the file name portion of the current page.
//e.g. location.href = www.domain.com/example.php
console_log(location.pathname.substring(1));
//displays: example.php
Posted by Andy Nagai on Jan 15, 2013
$site_name = preg_replace('/\s+/', '', $profile_name);
Posted by Andy Nagai on Jan 10, 2013
This will display the current datetime in London.
Here is list of supported timezone strings you can use:
http://us1.php.net/manual/en/timezones.php
$tz = new DateTimeZone('Europe/London');
$dt = new DateTime();
$dt->setTimeZone($tz);
// London time
echo $dt->format('Y-m-d H:i:s') . '<br>';
// Local time
echo date('Y-m-d H:i:s');
Posted by Andy Nagai on Sep 14, 2012
This will take an input and output a single value. Must define input and output data types.
$db = mysqli_connect("127.0.0.1", "dash_rw", "password", "database");
$db->query("DROP PROCEDURE IF EXISTS p");
// take input and output single value. Output does not have to match table field length.
$db->query("CREATE PROCEDURE p(IN id_val INT, OUT pname varchar(100)) BEGIN SELECT name FROM panel WHERE id= id_val INTO pname; END;");
$db->query("CALL p(2,@pname)");
$res = $db->query("SELECT @pname as p_out");
$row = $res->fetch_assoc();
echo $row['p_out'];
This will return a single result set. Can also return multiple result sets
$db = mysqli_connect("127.0.0.1", "dash_rw", "password", "database");
$db->query("DROP PROCEDURE IF EXISTS p");
$db->query("CREATE PROCEDURE p() READS SQL DATA BEGIN SELECT name FROM panel; END;");
// needs to be multi_query() even if returning just one result set
$db->multi_query("CALL p()");
// Store the first result set
$res = $db->store_result();
while($row=$res->fetch_assoc()) {
echo 'name: ' . $row['name'] . '<br>';
}
$res->free();
// Get next result set
$db->next_result();
$res = $db->store_result();
...
$res->free();
Posted by Andy Nagai on Sep 10, 2012
This will remove all items in a select drop down except the first default item. Find this useful with dynamic drop downs that rely on other form selections.
$('#sel_list').find('option:gt(0)').remove();