Skip to content

Instantly share code, notes, and snippets.

View amilabandara's full-sized avatar

Amila Bandara amilabandara

View GitHub Profile
@amilabandara
amilabandara / mysql password change.txt
Created December 3, 2015 04:50
Change a Password for MySQL on Linux via Command Line
mysql -u root -p
use mysql;
update user set password=PASSWORD('your_new_password') where User='root';
flush privileges;
quit
@amilabandara
amilabandara / Joomla_Bootstrap_Tabs.php
Created December 7, 2015 05:25
Joomla 3.4 Bootstrap tabs
<?php
$options = array(
'active' => 'tab1'
);
echo JHtml::_('bootstrap.startTabSet', 'tab_group_name',$options);
echo JHtml::_('bootstrap.addTab', 'tab_group_name', 'tab1', JText::_('Tab 1 Header'));
tab 1 content goes here
echo JHtml::_('bootstrap.endTab');
echo JHtml::_('bootstrap.addTab', 'tab_group_name', 'tab2', JText::_('Tab 2 Header'));
@amilabandara
amilabandara / Joomla_modal.php
Last active December 7, 2015 06:21
Joomla 3x Modal Box
<?php
JHTML::_('behavior.modal');
//example 1
<a href="http://www.example.com/images/myimage.jpg" class="modal">Click here to see my image</a>
//example 2
<div id="loadDiv">
A div element containing some text that you want to display.
</div>
<?php
$position = 'wrapper';
$modules =& JModuleHelper::getModules('testpos');
foreach ($modules as $module) {
echo JModuleHelper::renderModule($module);
}
?>
@amilabandara
amilabandara / pgsql.sql
Created June 16, 2016 19:34
Make column auto increment after creation of the table
create sequence player_id_seq;
alter table player alter playerid set default nextval('player_id_seq');
Select setval('player_id_seq', 2000051 );--set to the highest current value of playerID
<?php
function redirect($url)
{
if (!headers_sent())
{
header('Location: '.$url);
exit;
}
else
{
@amilabandara
amilabandara / datetime.php
Created July 27, 2016 10:26
Time specific php code snippets
<?php
//get difference between two dates in days
//$now = time(); // or your date as well
$now = strtotime("2016-07-28");
$your_date = strtotime("2016-07-26");
$datediff = $now - $your_date;
echo floor($datediff/(60*60*24));
//check from date is after than to date
//import .sql file
1) select the schema.
2) Plugins->PSQL console
3) Type \i /path/to/yourfile.sql
i.e \i 'C:/Users/Work/Desktop/School Work/load_database.sql' <= Note the single quote
@amilabandara
amilabandara / array_search_duplicates.php
Created November 15, 2016 14:42
Search an array for duplicate values
<?php
$array_1 = array();
array_push($array_1,10,15,2,3,4,5,18,40);
$array_2 = array_unique( array_diff_assoc( $array_1, array_unique( $array_1 ) ) );
print_r($array_2);
?>
<?php
//hierarchical
//hook into the init action and call create_book_taxonomies when it fires
add_action( 'init', 'create_topics_hierarchical_taxonomy', 0 );
//create a custom taxonomy name it topics for your posts
function create_topics_hierarchical_taxonomy() {