For smart Primates & ROBOTS (oh and ALIENS ).

Thursday, May 28, 2015

How to fix any HTML tag at any position

Problem:

How to fix any HTML tag at any position for ex: fix a div at right bottom corner?

Solution:

Use style z-index, bottom, right attribute

Example:

<div id="loading_msg" style="position: fixed; z-index: 99;  bottom: 15px; right: 10px;
    display:; background-color:#CC99FF">Loading now Please wait...</div>
Share:

Tuesday, May 26, 2015

Scrolling paging in PHP

Problem:

Database paging without paging page number.  This is same as Facebook and Tumblr like paging.

Solution:

By using Ajax you can achieve that like scroll paging.

Example:

Use below code. Assuming 1 to 10th records already showing.

index.php
<script type="text/javascript" src="jquery-1.6.js"></script>
<div id="mydiv">
<p>Database paging </p><p>without paging</p><p>page number</p><p>This is same as Facebook</p><p>and Tumblr.</p><p>like paging.</p><p>Assuming 1 to 10th records already showing.</p> <p>Next 11th to end of records will show when scroll page.</p>

<p>1 record</p><p>2 record</p><p>3 record</p><p>4 record</p><p>5 record</p><p>6 record</p><p>7 record</p><p>8 record</p><p>9 record</p><p>10 record</p>   </div>

<a id="loading_img" style="position:fixed; z-index: 99;bottom: 15px; right: 10px; display:none;">Loading... <img src="ajax-loader.gif" /></a>

<script type="text/javascript">
var page = 1;
$(window).scroll(function () {
currentX = $(window).scrollTop();
if  ($(window).scrollTop() == $(document).height() - $(window).height()){
$('a#loading_img').show('fast');
$.get('mydb.php?page=' + page, function(data) {
$('#mydiv').append(data);
$('a#loading_img').hide('fast');
}
);
page++;
}
});
</script>



mydb.php

<?php
$mysqli = new mysqli('localhost', 'root', '','mydb');
$pg=$_GET['page'];
$pg=$pg*10;
$sql='SELECT *FROM book_wise_test ORDER BY book_wise_test_id LIMIT '.$pg .', 10';
$result  = $mysqli->query($sql);
while($row = $result->fetch_assoc()) {
$book_wise_test_id=$row['book_wise_test_id'];
$book_nm=$row['book_nm'];
echo $book_wise_test_id.'======'.$book_nm.'<br/><br/>';
}
?>
Share:

Monday, May 11, 2015

Message: Undefined variable: 0 in CodeIgniter PHP

Problem:

Sometime while working with CodeIngiter / PHP you may encounter "Undefined variable: 0" error.
It surprise to that is "0" (Zero) could be a variable!

Solution:

This "Undefined variable: 0" error come when you use double dollar sign in variable. so remove one dollar ($) sign from variable and error will gone.

Example:

See the below code, specially in red color, it having $$ sign:

$data = array( 'u_login' => $row->u_login,
                        'user_type_id' => $user_type_id,
'user_id'=>$row->user_id,
'transporter_id'=>$transporter_id,
'limit_cr'=>$limit_cr,
'u_c_date'=>$row->u_c_date,
'total_trucks'=>$total_trucks,
'total_liter'=>$total_liter,
'pump_id'=> $$pump_id
                        );

jut remove one $ sign.
Share:

Wednesday, May 06, 2015

How to convert eps file to jpg file

Problem:

How to convert .eps file to .jpg file

Solution:

It is simple, use ImageMagick and below java code. if you expert in PHP or .Net then you can easily convert it same as me.

Example:

import="java.util.*"%>  
import="java.io.*"%>
 
try
    {
        Runtime runTime = Runtime.getRuntime();
        Process process = runTime.exec ("C:/Program Files/ImageMagick-6.5.4-Q16/convert.exe c:/Art1.eps c:/art1.jpg");
        //InputStream inputStream = process.getInputStream();
        //InputStreamReader   inputStreamReader = new InputStreamReader (inputStream);
        //BufferedReader bufferedReader = new BufferedReader(
inputStreamReader);
        ///String line = null;
        //while ( (line = bufferedReader.readLine()) != null )
        //    System.out.println(line);
        int exitVal = process.waitFor();
        System.out.println ("Process exitValue:  " + exitVal );
    }
    catch (Throwable t)
    {
        t.printStackTrace();
    }
Share:

Tuesday, May 05, 2015

How to load JavaScript file async in Magento

Problem:

By async loading JavaScript it will boost up your site, so how to load JavaScript file async in Magento.  In Magento there are two methods to load JavaScript .
1- By addItem
2-By addJs

Solution:

By using async option in <params>async</params> script tag you can load it.

Example:

Open your local.xml file it will be in the "app\design\frontend\default\YOUR-THEME-NAME\layout" folder.

1- By addItem
<action method="addItem">
    <type>skin_js</type>
    <name>js/jquery.mousewheel.min.js</name>
   <params>async</params>
</action>


2-By addJs
<action method="addJs">
     <script>scriptaculous/effects.js</script>
     <params>async</params>
</action>




Share:

Thursday, April 23, 2015

html html5 to Pdf

Generate PDF file of html html5 with div span tags. It really works on liquid layout also!
Try it now!





html html5 to Pdf
Download here:

Part-1 
Part-2
Part-3
Part-4
Part-5
Part-6
Part-7
Part-8
Part-9
Part-10
Part-11

Extract  all files Part-1 to Part-11 and paste all files in one folder and double click on
Html-Html5-to-PDF.exe
Share:

Wednesday, April 22, 2015

File open Dialogbox show error System Threading ThreadStateException

Problem:

I am wondering when you get the error 'System.Threading.ThreadStateException' while using OpenFileDialog in C# Winform application. So how to solve this?

First we see the error details, after that I will show you solution.
See the screenshot below.
System.Threading.ThreadStateException



















Error is:
"An unhandled exception of type 'System.Threading.ThreadStateException' occurred in System.Windows.Forms.dll
Additional information: Current thread must be set to single thread apartment (STA) mode before OLE calls can be made. Ensure that your Main function has STAThreadAttribute marked on it. This exception is only raised if a debugger is attached to the process."

Code is:

System.Windows.Forms.OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.Title = "Select HTML/HTML5 file";
openFileDialog.InitialDirectory = "C:";
openFileDialog.Filter = "HTML files (*.html)|*.html|Flv files (*.htm)|*.htm";
openFileDialog.AutoUpgradeEnabled = true;
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
String Chosen_File = openFileDialog.FileName;
       String inputExt = (Path.GetExtension(Chosen_File).ToLower());
       textBox1.Text = Chosen_File;
       textBox2.Text = Chosen_File + "_New" + inputExt;
}
It will show error on the line

if (openFileDialog.ShowDialog() == DialogResult.OK)


The full error code is:
=============================
System.Threading.ThreadStateException was unhandled
  HResult=-2146233056
  Message=Current thread must be set to single thread apartment (STA) mode before OLE calls can be made. Ensure that your Main function has STAThreadAttribute marked on it. This exception is only raised if a debugger is attached to the process.
  Source=System.Windows.Forms
  StackTrace:
       at System.Windows.Forms.FileDialog.RunDialog(IntPtr hWndOwner)
       at System.Windows.Forms.CommonDialog.ShowDialog(IWin32Window owner)
       at System.Windows.Forms.CommonDialog.ShowDialog()
       at CoreRenderer.Form1.button3_Click(Object sender, EventArgs e) in d:\CurrentProject\WinForm\VS2013Testing\CS\CoreRenderer\CoreRenderer\Form1.cs:line 121
       at System.Windows.Forms.Control.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
       at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
       at System.Windows.Forms.Control.WndProc(Message& m)
       at System.Windows.Forms.ButtonBase.WndProc(Message& m)
       at System.Windows.Forms.Button.WndProc(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
       at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.Run(Form mainForm)
       at CoreRenderer.Program.Main() in d:\CurrentProject\WinForm\VS2013Testing\CS\CoreRenderer\CoreRenderer\Program.cs:line 21
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException:
=============================

Solution:

To overcome this problem you need to use Thread class. See below code that how to fix this error.

Example:

Create a method as below:
public void getfile() {
      System.Windows.Forms.OpenFileDialog openFileDialogAvi = new OpenFileDialog();
      openFileDialogAvi.Title = "Select HTML/HTML5 file";
      openFileDialogAvi.InitialDirectory = "C:";
      openFileDialogAvi.Filter = "HTML files (*.html)|*.html|Flv files (*.htm)|*.htm";
      openFileDialogAvi.AutoUpgradeEnabled = true;
      if (openFileDialogAvi.ShowDialog() == DialogResult.OK)
      {
         String Chosen_File = openFileDialogAvi.FileName;
         String inputExt = (Path.GetExtension(Chosen_File).ToLower());
         Invoke((MethodInvoker)delegate
         {
               textBox1.Text = Chosen_File;
               textBox2.Text = Chosen_File + "_New" + inputExt;
         });
      }
   }


On click button access the above method:

private void button2_Click(object sender, EventArgs e) {
       Thread threadGetFile = new Thread(new ThreadStart(getfile));
       threadGetFile.ApartmentState = ApartmentState.STA;
       threadGetFile.Start();         
}

Share:

Monday, April 20, 2015

How to use Response.Write in ASP.NET MVC 5

Problem:

How to use Response.Write in ASP.NET MVC 5

Solution:

See the below example:

Example:

   @{
        Response.Write("<br/>Emp First Name :");
    }


OR

  @("test")

Share:

Sunday, April 19, 2015

jquery ui dialog box show previous page before show new page's contents

Problem:

If you used jquery ui dialog box to show any dynamic page's contents then I am sure you have faced this problem. when you click first time it will work fine but the second time on click it will show previous page's contents and after  delay of 2 to 3 seconds it will show the contents of the url which you have supplied. this is the bug in jquery ui dialog box.
Consider below code:

<link rel="stylesheet" type="text/css" media="all" href="jquery-ui.css">

<script type="text/javascript" src="jquery-1.10.2.min.js"></script>
<script type="text/javascript" src="jquery-ui.js"></script>

<a href="#" onclick="show_full(1);>View</a>

<script>
function show_full(q_id) {
    var url="show_q_a.php?serial="+new Date().getTime()+"&q_id="+q_id;                   
    $( "#dialog" ).dialog( {
                                autoOpen: false,
                                modal: true,
                                height: 550,
                                width:1000,
                                title: "Question and Answer"
    });
    $("#dialog").load(url);
    $( "#dialog" ).dialog( "open" );
</script>

Solution:

Use <div> and <iframe > tag to prevent the show previous  page problem. see below correct code as a example.

Example:

function show_full(q_id) {
    var url="show_q_a.php?serial="+new Date().getTime()+"&q_id="+q_id;   
    var $dialog = $('<div></div>')
               .html('<iframe style="border: 0px; " src="' + url+ '" width="100%" height="100%"></iframe>')
               .dialog({
                   autoOpen: false,
                   modal: true,
                   height: 550,
                   width: 1231,
                   title: "Question and Answer"
               });
    $dialog.dialog('open');
}
Share:

Friday, April 17, 2015

jquery ui datepicker automatically delete text from input field

Problem:

Did you worked with jquery ui date picker? when assigned a default value to text filed, jquery ui datepicker will automatically delete text from that textbox field. So how to stop it?

Solution:

It seems the bug in jquery ui datepicker which is automatically delete text from input field. to overcome this problem you need to write 22 lines of code as example below:

Example:

// assume that the $edit_diesel_date is already filled with date value.
// write this code very bootom of your page.
function dook() {  $("#diesel_date").val("<?php echo $edit_diesel_date;?>");     }
setTimeout("dook();", 500);
Share:

Ads Inside Post

Powered by Blogger.

Archive