Showing posts from 2013


jquery noConflict

<!-- load jQuery 1.1.3 --> <script type="text/javascript" src=""></script> <script type="text/javascript"> var jQuery_1_1_3 = $.noConflict(true); </script> <!-- load jQuery 1.3.2 --> <script type="text/javascript" src=""></script> <script type="text/javascript"> var jQuery_1_3_2 = $.noConflict(true); </script> Then, instead of $('#selector').function();, you'd do jQuery_1_3_2('#selector').function(); or jQuery_1_1_3('#selector').function();

get an input field value from the last row in a table using jquery

$('table#table1 tr:last input[name=code]').val();

count number of rows in a table using jquery

var rowCount = $('#myTable tr').length;

allow only numeric (0-9) in html inputbox using jquery

jsnya : <script type="text/javascript"> $(document).ready(function(){ //numeric numericOnly('biaya'); numericOnly('OutboundDetail_weight'); function numericOnly(id){ $("#"+id).keydown(function(event) { // Allow: backspace, delete, tab, escape, and enter if ( event.keyCode == 46 || event.keyCode == 8 || event.keyCode == 9 || event.keyCode == 27 || event.keyCode == 13 || // Allow: Ctrl+A (event.keyCode == 65 && event.ctrlKey === true) || // Allow: home, end, left, right (event.keyCode >= 35 && event.keyCode <= 39)) { // let it happen, don't do anything return; } else { // Ensure that it is a number and stop the keypress if (event.shiftKey || (event.keyCode < 48 || event.keyCode > 57) && (event.keyCode < …

resetting multi element/controll form using jquery

function resetForm($form) { $form.find('input:text, input:password, input:file, select, textarea').val(''); $form.find('input:radio, input:checkbox') .removeAttr('checked').removeAttr('selected'); } // to call, use: resetForm($('#myform')); // by id, recommended resetForm($('form[name=myName]')); // by name
source :

close thickbox popup from code behind c#

ScriptManager.RegisterStartupScript(this, typeof(Page), UniqueID, “self.parent.tb_remove()”, true);

Reset Dropdownlist value using jQuery


Get selected text from dropdownlist using jQuery

$("#yourdropdownid option:selected").text();

cast or convert from varchar to integer in mysql

select convert(id, UNSIGNed integer) as id from tb_test order by id select CAST(id AS UNSIGNED) as id from tb_test order by id

get data from textbox on form pop up using thickbox

cara pertama dengan alt tag:   jsnya :   <script type="text/javascript">         function GetLinks(i,vsid) {           document.getElementById("btn"+i).alt = "packageBookingRes.aspx?vsid="+vsid+"&BPax=" + document.getElementById('txtBookingPax'+ i).value + "&keepThis=true&TB_iframe=true&height=450&width=605";         }     </script>   htmlnya :   <input type=\"button\" id=\"btn" + i.ToString() + "\" onclick='GetLinks(" + i.ToString() + ",\""+vsid+"\")' class=\"thickbox sendbook\" value=\"Booking\" />   ---------------------------------------------   cara kedua dengan tb_show :   jsnya :   <script type="text/javascript">     function GetPax(i, vsid) {       if((document.getElementById('txtBookingPax'+i).value != "0")&&(document.getElementById('t…

change cjuidatepicker / jquery datepicker z-index

.date_field {position: relative; z-index:100;} jQuery will set the calendar's z-index to 101 (one more than the corresponding element). The position field must be absolute, relative or fixed. jQuery searches for the first element's parent, which is absolute/relative/fixed, and takes its' z-index

source :
DESCRIBE tb_invoice;

show create table tb_invoice;

select * from `information_schema`.`tables`
  where table_name like 'tb_invoice'

get date yesterday with php

echo date('Y-m-d', strtotime("-1 days"));

yii config on production and development

on production :
.................. // Application components 'components' => array( // Database 'db'=>array( 'connectionString' => 'Your connection string to your production server', 'emulatePrepare' => false, 'username' => 'admin', 'password' => 'password', 'charset' => 'utf8', ), // Application Log 'log'=>array( 'class'=>'CLogRouter', 'routes'=>array( array( 'class'=>'CFileLogRoute', 'levels'=>'error, warning', ), // Send e…

css persen minus px

.calculated-width { width:-moz-calc(100%-100px); width:-webkit-calc(100%-100px); width: calc(100%-100px);}​

setting cache control pada php

<?php //set headers to NOT cache a page header("Cache-Control: no-cache, must-revalidate"); //HTTP 1.1 header("Pragma: no-cache"); //HTTP 1.0 header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past //or, if you DO want a file to cache, use: header("Cache-Control: max-age=2592000"); //30days (60sec * 60min * 24hours * 30days) ?>

php date format

format characterDescriptionExample returned valuesDay------dDay of the month, 2 digits with leading zeros01 to 31DA textual representation of a day, three lettersMon through SunjDay of the month without leading zeros1 to 31l (lowercase 'L')A full textual representation of the day of the weekSunday through SaturdayNISO-8601 numeric representation of the day of the week (added in PHP 5.1.0)1 (for Monday) through 7 (for Sunday)SEnglish ordinal suffix for the day of the month, 2 charactersst, nd, rd or th. Works well with jwNumeric representation of the day of the week0 (for Sunday) through 6 (for Saturday)zThe day of the year (starting from 0)0 through 365Week------WISO-8601 week number of year, weeks starting on Monday (added in PHP 4.1.0)Example: 42 (the 42nd week in the year)Month------FA full textual representation of a month, such as January or MarchJanuary through DecembermNumeric representation of a month, with leading zeros01 through 12MA short tex…

jQuery multiple events like keyup, keypress, blur, change, focusout, etc call in one line

You can use .on() to bind a function to multiple events:
$('#element').on('keyup keypress blur change', function() { ... });

yii menu with onclick link

yii menu :
array('label'=>'Create Invoice', 'url'=>'', 'linkOptions'=>array('onclick'=>'{printInvoice();}', 'style'=>'cursor: pointer; text-decoration: none;',)),
the html result :

<a href="#" onclick="{printInvoice();}">Create Invoice</a>
then create the js function :

<script> function printInvoice(){ something here… } </script>

Reference: Model rules validation Yii

get first and last date in a month with php, mysql


php :
$first = date('Y-m-d', mktime(0, 0, 0, date('m'), 1, date('Y'))); $last = date('Y-m-t', mktime(0, 0, 0, date('m'), 1, date('Y')));

yii Fatal error: Class 'PDO' not found in ...

add php.ini with the below line and put it to the root of my website on my share hosting where the operating system used is linux.

Four Men in Hats

Shown above are four men buried up to their necks in the ground. They cannot move, so they can only look forward. Between A and B is a brick wall which cannot be seen through.
They all know that between them they are wearing four hats--two black and two white--but they do not know what color they are wearing. Each of them know where the other three men are buried.
In order to avoid being shot, one of them must call out to the executioner the color of their hat. If they get it wrong, everyone will be shot. They are not allowed to talk to each other and have 10 minutes to fathom it out.
After one minute, one of them calls out.
Question: Which one of them calls out? Why is he 100% certain of the color of his hat?

This is not a trick question. There are no outside influences nor other ways of communicating. They cannot move and are buried in a straight line; A & B can only see their respective sides of the wall, C can see B, and D can see B & C.

gets current working directory

echo getcwd();

A Farmer's Good Fortune

A farmer from a small community is out of money. After a mysterious desease spread among and killed his lifestock, he now needs to quickly make up for the lost animals. He needs a whole grand.
Knowing that the bank won't lend him any money, he pays a visit to the local loan shark. The outlaw, who's known to have a bit of an obsession with puzzles, proposes a deal.
With the $1,000 he gets, the farmer has to be able to buy a combination of cows, pigs, and sheep, to total exactly 100 heads of lifestock. The combination has to include at least one cow ($100 each), one pig ($30 each), and one sheep ($5 each). The total amount of money spent for the 100 animals has to equal exactly $1,000.
If the farmer manages to accomplish the task, he'll have to return the money with a "friendly" interest rate. Otherwise, he'll get the normal rate, and the threat of a broken pinkie...
How many of each kind of livestock did the farmer buy?

The Snail And The Well

There was a small snail at the bottom of a thirty foot well. In desperation to get out, the snail was only able to climb up three feet during the daytime, and reluctantly slide back down two feet at night.
At this pace, how many days and nights will it take the snail to reach the top of the well?

c# foreach descending loop (Enumerable.reverse)

List<int> test = new List<int>() { 1, 2, 4, 5, 6, 7, 9 }; foreach (int t in Enumerable.Reverse(test)) { Console.Write(t+","); } result : 9,7,6,5,4,2,1,

php datetime

$date = date("Y-m-d", strtotime('2013-04-23'));
echo $date; //2013-04-23

get prime number c#

private int[] IsPrime(int upperLimit) { int sieveBound = (int)(upperLimit - 1) / 2; int upperSqrt = ((int)Math.Sqrt(upperLimit) - 1) / 2; BitArray PrimeBits = new BitArray(sieveBound + 1, true); for (int i = 1; i <= upperSqrt; i++) { if (PrimeBits.Get(i)) { for (int j = i * 2 * (i + 1); j <= sieveBound; j += 2 * i + 1) { PrimeBits.Set(j, false); } } } List<int> numbers = new List<int>((int)(upperLimit / (Math.Log(upperLimit) - 1.08366))); numbers.Add(2); for (int i = 1; i <= sieveBound; i++) { if (PrimeBits.Get(i)) { numbers.Add(2 * i + 1); } } return numbers.ToArray(); }

Open an url in a new tab when click a button

source :
<input type="button" value="button name" onclick="'')" />

yii cmenu external url

<?php $this->widget('zii.widgets.CMenu',array( 'items'=>array( ...... array('label'=>'Home', 'url'=>'http:../../menu/home.php'), array('label'=>'Home', 'url'=>''), ...... ), )); ?>

Yii Set Item per Page CGridView dynamically

In the Controller / ActionAdmin:

if (isset($_GET['pageSize'])) { Yii::app()->user->setState('pageSize',(int)$_GET['pageSize']); unset($_GET['pageSize']); }
In the model / Search Function: return new CActiveDataProvider(get_class($this), array( 'pagination'=>array( 'pageSize'=> Yii::app()->user->getState('pageSize',Yii::app()->params['defaultPageSize']), ), 'criteria'=>$criteria, ));
In the View Admin: <?php $pageSize=Yii::app()->user->getState('pageSize',Yii::app()->params['defaultPageSize']); $this->widget('zii.widgets.grid.CGridView', array( 'id'=>'file-grid', 'dataProvider'=>$model->search(), 'columns'=>array( ..., array( '…

Yii : set item per page CGridView

public function search() { // Warning: Please modify the following code to remove attributes that // should not be searched. $criteria=new CDbCriteria; ... return new CActiveDataProvider('Client', array( 'criteria'=>$criteria, 'pagination'=>array( 'pageSize'=>50, ), )); }

yii Unique Validator

/** * @return array validation rules for model attributes. */ public function rules() { // NOTE: you should only define rules for those attributes that // will receive user inputs. return array( ........ array('username','unique'), ........ ); }

CMenu selected

Creating a parameterized LIKE query

yii Auto complete text field

Yii : change column size in CGridView

'columns'=>array(   array('name'=>'name','value'=>'asdf','htmlOptions'=>array('width'=>'40px'),),

Searching and sorting by related model in CGridView

link to new tab

this is open in new tab source :
<a href="" target="_blank">

show first and last button CLinkPager Yii

add the following style to main.css#page ul.yiiPager .first,#page ul.yiiPager .last{         display:inline;}

how to remove eval( gzinflate( base64_decode(

copy and paste to cronjob the script below to remove the nasty code injected in all my PHP files from public_html folder:   find -name "*.php" -exec sed -i '/<?.*eval(gzinflate(base64.*?>/ d' '{}' \; -print

netbeans 7.2.1 can not start after installing python plugin

codeigniter - user Authentication

Parse error on wp-includes/functions.php

error :
Parse error: syntax error, unexpected T_VARIABLE in /home/dewat913/public_html/soft1/wp-includes/functions.php on line 191

solution :
replace functions.php file with the new one.

source : its work for me.

PHP Shorthand If / Else Examples

Basic True / False Declaration $is_admin = ($user['permissions'] == 'admin' ? true : false);
Basic True / False Declaration echo 'Welcome '.($user['is_logged_in'] ? $user['first_name'] : 'Guest').'!';
Conditional Items Message echo 'Your cart contains '.$num_items.' item'.($num_items != 1 ? 's' : '').'.';
Conditional Error Reporting Level error_reporting($WEBSITE_IS_LIVE ? 0 : E_STRICT);
Conditional Basepath echo '<base href="http'.($PAGE_IS_SECURE ? 's' : '').'://" />';
Nested PHP Shorthand echo 'Your score is: '.($score > 10 ? ($age > 10 ? 'Average' : 'Exceptional') : ($age > 10 ? 'Horrible' : 'Average') );
Leap Year Check $is_leap_year = ((($year % 4) == 0) && ((($year % 100) != 0) || (($year %400) == 0)));
Conditional PHP Redirect header('Locat…

How to Solve Port 80 Problems When Running Apache on Windows

Run an administrator command prompt (e.g. Start, search for cmd, right click on it, choose "Run as administrator", approve the UAC prompt if any.
Type net stop HTTP
If there are other running services that depend on the HTTP service, you'll get a list; double check to see if there's anything listed there you can't bear to do without. Or, if you're just stopping HTTP to use port 80 temporarily, make a note of those dependent services that you'll want to restart once you're done with the port. Either way, if it's okay, enter y to continue.
Some dependent services might throw up stop control warnings that cancel the operation; just repeat net stop HTTP until it is stopped (i.e. until it says The HTTP service was stopped successfully.)
Later on, you can restart any of the dependent services, using net start or by using the Services item in Administrative Tools, and the HTTP service will be started again automatically.

source :
- http://msg…

create read more with php on yii framework

using a simple php code strip_tags and substr

$isi = strip_tags(substr($data->description, 0, 200))."...."; echo $isi; echo CHtml::link('View Detail', array('view', 'id'=>$data->id),array('class'=>'btn btn-success btn-small'));
demo :

set each textbox value with jquery

potongan jquery sintax : $( document ).on( 'click', '#copyall', function( e ) { var allotment = $('#AllotmentToAll').val(); $('#allotment').each( function() { $('.allotment').val(allotment); }); }); potongan sintax php pada framework yii :
echo CHtml::textField('AllotmentToAll','','',array('id'=>'AllotmentToAll')); echo CHtml::button('Copy To All', array('id'=>"copyall")); $totDay = date('t', strtotime('2013-01')); echo "<br />"; echo "<table border=1>"; echo '<tr>'; for($i=1; $i<=$totDay; $i++){ echo '<td>'; echo "2013-01-$i <br />"; echo CHtml::textField('allotment[]', '', array('id'=>"allotment", 'cla…