[ create a new paste ] login | about

balajimca

Name: Balaji Kandasamy
Email:
Site/Blog: http://stackoverflow.com/users/817365/balaji-kandasamy
Location: India
Default language: PHP
Favorite languages: PHP,Javascript,HTML5,objective-C, cocoa touch
About: PHP programmer, iOS Developer.

Saved pastes by balajimca:

Plain Text, pasted on Oct 11:
1
2
3
4
5
Enable Gzip compression


#Expire Header
<FilesMatch "\.(ico|jpg|jpeg|png|gif|js|css|swf)$">
...
view (22 lines)
Plain Text, pasted on Oct 7:
1
2
3
4
5
Handling decimal values in Textfield:
NSString *text = [textField.text stringByReplacingCharactersInRange:range withString:string];
text = [text stringByReplacingOccurrencesOfString:@"." withString:@""];
double number = [text intValue] * 0.01;
textField.text = [NSString stringWithFormat:@"%.2lf", number];
view (5 lines)
Plain Text, pasted on Jun 19:
1
2
3
4
5
//*** Magento reset all orders and dashboard ***//
SET FOREIGN_KEY_CHECKS=0; 
TRUNCATE `catalogsearch_query`; 
ALTER TABLE `catalogsearch_query` AUTO_INCREMENT=1;
 
...
view (82 lines)
C, pasted on Apr 17:
1
2
3
4
5
#include<stdarg.h>
int addition(int n, ...){
int sum=0;
va_list vargs;
int i;
...
view (18 lines, 2 lines of output)
PHP, pasted on Apr 2:
1
2
3
4
<?php echo "380*480 - iPhone
640*960 -iPhone 4
640*1136 - iPhone5
768*1024 - iPad"; ?>
view (4 lines, 4 lines of output)
PHP, pasted on Feb 19:
1
2
3
<?php
echo "1.They are generally used for functional callbacks or threading. Say you want to run an update piece of code when a download is finished, then you can put that code in a block and pass to the download function. Similar to lambda notation in the upcoming Java 8, or how C++ can pass functions as pointers, or how JavaScript uses functions as variables.\n 2.“blocks” of code that you can pass along like any object. This probably sounds a lot like a function, and they are very similar, but there is a significant difference in that they “close” around variables that are in scope before a block is declared.";
?>
view (3 lines, 2 lines of output)
PHP, pasted on Feb 8:
1
2
3
4
5
<?php

$array = array('Istruncated' => '', 'ServerCertificateMetadataList' => array(array('ServerCertificateName' => 'mycert', 'Path' => '/')));
foreach ($array as $key => $value) {
    if (is_array($value)) {
...
view (11 lines, 1 line of output)
PHP, pasted on Feb 4:
1
2
3
4
5
<?php
$responses = array('A=1', 'B=2', 'C=3');
foreach ($responses as $value) {
    $split = explode('=', $value);
    $array1[$split[0]] = $split[1];
...
view (8 lines, 6 lines of output)
PHP, pasted on Feb 1:
1
2
3
4
<?php
//How to create web serive for iOS
echo "http://www.techrepublic.com/blog/software-engineer/create-your-own-web-service-for-an-ios-app-part-one/";
?>
view (4 lines, 1 line of output)
PHP, pasted on Jan 2:
1
2
3
4
5
<?php
echo "1)
Apport constantly errored for me in 12.10, and this is how I fixed it. I'm not sure if it's related to anything in 13, but it's the only other thing I did to the system after a clean install before step 2, so I want it documented in my post.
sudo apt-get purge apport
sudo apt-get autoremove
...
view (11 lines, 9 lines of output)
PHP, pasted on Dec 7:
1
2
3
4
5
<?php
//get previous and next ids of current id using SQL query
echo "select field1, field2
     , ( select min(id) from yourtable where id > t.id ) as next_id
     , ( select max(id) from yourtable where id < t.id ) as prev_id
...
view (7 lines, 4 lines of output)
PHP, pasted on Dec 6:
1
2
3
<?php
echo "Let's role"
?>
view (3 lines, 1 line of output)
PHP, pasted on Dec 6:
1
2
3
4
5
<?php

function sor($arr) {
  for ($i=0; $i<count($arr); $i++) {
    for ($j=0; $j<count($arr)-1-$i; $j++) {
...
view (21 lines, 9 lines of output)
PHP, pasted on Jun 13:
1
2
3
4
5
<?php
$date=date("d_m_Y_h_i",time());
	$file_name="service_report_".$date.".xls";
	$data=ob_REQUEST_contents();
	ob_end_clean();
...
view (11 lines, 2 lines of output)
PHP, pasted on Apr 26:
1
2
3
4
<?php
$str = "123456";
echo sha1($str);
?>
view (4 lines, 1 line of output)
PHP, pasted on Mar 25:
1
2
3
4
5
<?php
function test($s)
{

echo 'test';
...
view (12 lines, 1 line of output)
PHP, pasted on Jan 22:
1
2
3
4
5
<?php
$array = array(0 => 100, "color" => "red");
print_r(array_keys($array));

$array = array("blue", "red", "green", "blue", "blue");
...
view (11 lines, 16 lines of output)
PHP, pasted on Jan 12:
1
2
3
4
5
<?php
$string = 'April 15, 2003';
$pattern = '/(\w+) (\d+), (\d+)/i';
$replacement = '${1} 2,$3';
echo preg_replace($pattern, $replacement, $string);
...
view (6 lines, 1 line of output)
PHP, pasted on Dec 12:
1
2
3
4
5
<?php
$rate=12.00;
$percent = 5;
$newrate = ($rate - (($rate/100)*$percent));
print $newrate;
...
view (6 lines, 1 line of output)
PHP, pasted on Oct 27:
1
2
3
4
5
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title></title>
...
view (51 lines, 2 lines of output)
PHP, pasted on Oct 27:
1
2
3
4
5
<?php
if(isset($_POST[sub])) {
function find_user($filename, $email) {

$f = fopen($filename, "r");
...
view (27 lines, 5 lines of output)
PHP, pasted on Oct 8:
1
2
3
4
<?php
$date="1349697006";
echo date("m-d-Y",$date);
?>
view (4 lines, 1 line of output)
PHP, pasted on Oct 5:
1
2
3
4
5
<?php
$beginning = 'foo';
$end = array('bar');
$result = array_merge((array)$beginning, (array)$end);
print_r($result);
...
view (6 lines, 5 lines of output)
PHP, pasted on Oct 5:
1
2
3
4
5
<?php
$array = array(0 => 100, "color" => "red");
print_r(array_keys($array));

$array = array("blue", "red", "green", "blue", "blue");
...
view (11 lines, 16 lines of output)
PHP, pasted on Sep 25:
1
2
3
4
<?php
$string = '60, 1, 1, 188, pdgje5565';

$output_array = array_map('trim',explode(',',$string));
...
view (6 lines, 8 lines of output)
PHP, pasted on Sep 17:
1
2
3
4
5
<?php
$sites = array("Nettuts+"=>"ets", "Psdtuts+"=>"erre", "Mobiletuts+"=>"swa", "Mactuts+"=>"oooo");  
$k = array_rand($sites);  
echo $k."\n";
$sites[$k]; 
...
view (7 lines, 2 lines of output)
PHP, pasted on Sep 17:
1
2
3
4
5
<?php
$sites = array("Nettuts+", "Psdtuts+", "Mobiletuts+", "Mactuts+");  
$k = array_rand($sites);  
$sites[$k]; 
echo  $sites[$k]; 
...
view (6 lines, 1 line of output)
PHP, pasted on Sep 7:
1
2
3
4
5
<?php
// Delimiters may be slash, dot, or hyphen
$date = "04.30.1973";
list($month, $day, $year) = split('[/.-]', $date);
echo "Month: $month; Day: $day; Year: $year<br />\n";
...
view (8 lines, 9 lines of output)
PHP, pasted on Sep 6:
1
2
3
<?php
echo metaphone("pearl");
?>
view (3 lines, 1 line of output)
PHP, pasted on Sep 6:
1
2
3
4
<?php
$date = time();
echo $date;
?>
view (4 lines, 1 line of output)
PHP, pasted on Sep 6:
1
2
3
4
5
<?php
//facebook like past time display
function facebook_style_date_time($timestamp){
$difference = time() - $timestamp;
$periods = array("sec", "min", "hour", "day", "week", "month", "years", "decade");
...
view (24 lines, 1 line of output)
PHP, pasted on Sep 6:
1
2
3
4
5
<?php
function facebook_style_date_time($timestamp){
$difference = time() - $timestamp;
$periods = array("sec", "min", "hour", "day", "week", "month", "years", "decade");
$lengths = array("60","60","24","7","4.35","12","10");
...
view (23 lines, 1 line of output)
PHP, pasted on Jul 24:
1
2
3
4
5
<?php

$timezone="Asia/Calcutta";
date_default_timezone_set($timezone);
echo date('y-D-M h:i:s');
...
view (6 lines, 1 line of output)
PHP, pasted on Jul 24:
1
2
3
4
5
<?php
date_default_timezone_set('Asia/Delhi');

$timestamp = strtotime("+1 month +2 days +0 hours +0 minutes 2 seconds")."\n";
echo $timestamp;
...
view (7 lines, 2 lines of output)
PHP, pasted on Jul 24:
1
2
3
4
5
<?php
$timestamp = strtotime("+1 month +2 days +4 hours +32 minutes 2 seconds")."\n";
echo $timestamp;
echo date('y-D-M h:i:s', $timestamp);
?>
view (5 lines, 2 lines of output)
PHP, pasted on Apr 9:
1
2
3
4
5
<?php
$my_array = array("Dog","Cat",45,'f');
var_dump($my_array);
echo "\n";
var_export($my_array);
...
view (11 lines, 24 lines of output)
PHP, pasted on Apr 2:
1
2
3
4
5
<?php
    function some_func($a, $b) {
        for ($i = 0; $i < func_num_args(); ++$i) {
            $param = func_get_arg($i);
            echo "Received parameter $param.\n";
...
view (17 lines, 9 lines of output)
PHP, pasted on Apr 2:
1
2
3
4
5
<?php

class Teste {

    function insertUser() {
...
view (74 lines, 12 lines of output)
PHP, pasted on Mar 28:
1
2
3
4
5
<?php
$var = array("naMe"=>"madhu","desTination"=>"developer");
print_r(array_change_key_case($var,CASE_UPPER));
print_r(array_change_key_case($var,CASE_LOWER));
?>
view (5 lines, 10 lines of output)
PHP, pasted on Mar 17:
1
2
3
4
<?php
$test = array ('first'=>'balaji','second'=>'balaji2','third'=>'balaji3');
print_r(array_chunk($test,2));
?>
view (4 lines, 14 lines of output)
PHP, pasted on Dec 10:
1
2
3
4
5
<?php
$array = array("2011-September_38","2011-September_10","2010-November_1","2011-June_50","2011-June_4","2009-November_9","2009-November_29","2010-December_19","2011-September_1");
function monthCompare($a, $b) {
   $count = substr($a,strpos($a,'_'));
   $count =strlen($count);
...
view (36 lines, 6 lines of output)
PHP, pasted on Dec 3:
1
2
3
4
5
<?php
$array = array("2011-September_38","2011-September_10","2011-June_50","2011-June_4","2009-November_9","2009-November_29","2010-December_19","2011-September_1");
function monthCompare($a, $b) {
   $count = substr($a,strpos($a,'_'));
   $count =strlen($count);
...
view (36 lines, 6 lines of output)
PHP, pasted on Dec 3:
1
2
3
4
5
<?php
$array = array("2011-September_38","2011-June_4","2009-May_3","2009-May_45","2010-March_2","2010-November_9","2011-December_29","2010-March_19");
function yearmonthCompare($a, $b) {
   $count = substr($a,strpos($a,'_'));
   $count =strlen($count);
...
view (19 lines, 51 lines of output)
PHP, pasted on Dec 2:
1
2
3
4
5
<?php
$array = array("2011-September_38","2011-June_4","2009-May_45","2010-November_9","2011-December_29","2010-March_19");
function monthCompare($a, $b) {
   $count = substr($a,strpos($a,'_'));
   $count =strlen($count);
...
view (14 lines, 9 lines of output)
PHP, pasted on Dec 2:
1
2
3
4
5
<?php
$array = array("2011-September_38","2011-June_4","2010-November_9","2011-November_29","2010-December_19");
function monthCompare($a, $b) {
   $count = substr($a,strpos($a,'_'));
   $count =strlen($count);
...
view (14 lines, 8 lines of output)
PHP, pasted on Dec 2:
1
2
3
4
5
<?php
$range = range(2011,2100);
$range = array_flip($range);
print_r($range);
?>
view (5 lines, 93 lines of output)
PHP, pasted on Dec 1:
1
2
3
4
5
<?php
$array = array("2011-September_38","2011-June_4","2011-November_9");
function monthCompare($a, $b) {
    $a = strtolower(substr($a,5,-3));
    $b = strtolower(substr($b,5,-3));
...
view (29 lines, 10 lines of output)
PHP, pasted on Dec 1:
1
2
3
4
5
<?php
    $date=array('2009-03','2010-01','2009-02');
    for ($i=0;isset($date[$i]);$i++) {

    $datess=explode('-',$date[$i]);
...
view (12 lines, 6 lines of output)
PHP, pasted on Dec 1:
1
2
3
4
5
<?php
    $date=array('2009-03','2010-01','2009-02');
    for ($i=0;isset($date[$i]);$i++) {

    $datess=explode('-',$date[$i]);
...
view (12 lines, 6 lines of output)
PHP, pasted on Dec 1:
1
2
3
4
<?php
    $date=array('2009-03','2010-01','2009-02');
    for ($i=0;isset($date[$i]);$i++) {
    $datess=explode('-',$date[$i]);
...
view (10 lines, 6 lines of output)
PHP, pasted on Dec 1:
1
2
3
4
5
<?php
    //set date array to list of dates in y-d-m format
    $date=array('2009-03','2010-01','2009-02');
    for ($i=0;isset($date[$i]);$i++) {
    $datess=explode('-',$date[$i]);
...
view (18 lines, 6 lines of output)
PHP, pasted on Dec 1:
1
2
3
4
5
<?php
function sortMonths($a1, $b1) {
	$a = date("Y F",$a1);
	$b = date("Y F",$b1);	
    if ($a->received_date == $b->received_date)
...
view (17 lines, 1 line of output)
PHP, pasted on Dec 1:
1
2
3
4
5
<?php 
//convert timestamp to normal date
$test=array(1316427274,1289909504);
foreach($test as $sort)
{
...
view (14 lines, 5 lines of output)
PHP, pasted on Dec 1:
1
2
3
4
<?php 
//convert timestamp to normal date
echo date("Y F d H:i:s a","1316427274");
?>
view (4 lines, 1 line of output)
PHP, pasted on Nov 17:
1
2
3
4
5
<?php
//merge two arrays
$array1 = array("color" => "red", 2, 4);
$array2 = array("a", "b", "color" => "green", "shape" => "trapezoid", 4);
$result = array_merge($array1, $array2);
...
view (7 lines, 10 lines of output)