Monday, January 18, 2016

How to view executed queries in laravel 5

Sometimes we need to view the the queries generated by eloquent either for debugging purpose or to be sure that query generated is correct. To view queries in laravel 5, we have multiple ways.


First enable the query log as it is disabled by default.

DB::enableQueryLog();

Than at the end of your controller action method, you can use

use Illuminate\Support\Facades\DB; //Reference
//
//Execute queries.
//
print_r(DB::getQueryLog());

and the follow up code.

DB::enableQueryLog();
$users = DB::table('users')->get();
$query = DB::getQueryLog();
print_r($query);
  

Beside this, we can use toSql method and also use listen method. If you want to view all queries in a request, than use a listen method. Add following code in service provider boot method.


DB::listen(function($query) {
// $query->sql
// $query->bindings
// $query->time
// 
echo ($query->sql);
});

Wednesday, February 26, 2014

How to install urdu fonts in ubuntu 12.04

Installing Urdu fonts in Linux is simple,  first you need to download urdu fonts and than install it.

Download:

Download urdu fonts


Install:

Jump to your home directory, there is a hidden folder named .fonts.

Extract font files in .fonts directory.

Go to terminal and execute the following command.

sudo fc-cache -vf

Restart the browser, and browse website. If it did not work, please read the following wiki. It describes fonts in general.

https://wiki.ubuntu.com/Fonts







Thursday, January 7, 2010

Using Amazon S3 SDK Pre-signedURL function

Today i was just exploring the amazon sdk. While using the presignedurl function of amazon sdk(C#), i was just curious that what is the server response time , zone. The amazon s3 returns the time in UTC. so simple but i was just curious that if we input time in GMT and it automatically convert it according to requestee IP time zone. i have tried to confirm but first i checked with UTC and it works 100% correctly. The second try i did is that i sent a GMT time and it works too. The amazon convert GMT to UTC according to client location. The sample code look like:


public string GetPreSignedURL(string bucketName, string key)
{
string url = string.Empty;
try
{
AmazonS3 client = Amazon.AWSClientFactory.CreateAmazonS3Client("ur access key", "secret key");

GetPreSignedUrlRequest request = new GetPreSignedUrlRequest().WithProtocol(Protocol.HTTPS).WithBucketName(bucketName).WithKey(key).WithExpires(DateTime.UtcNow.AddMinutes(1));
url = client.GetPreSignedURL(request);
}
catch { }
return url;
}

Tuesday, September 29, 2009

Increase IIS 5 connection limit on windows

On a non server edition of window operating system, we often got the error.
There are too many people accessing the Web site at this time.
OR
HTTP 403.9 - Access Forbidden: Too many users are connected
Internet Information Services


To increase the connection limit, go to :
1 - Go to directory c:\inetpub\AdminScripts
2 - Execute the following command.
adsutil set w3svc/MaxConnections 40

Wednesday, August 26, 2009

Read or Write on Registry in C#

Registry is a special place where applications stores its setting. Although Isolated storage for .net is a preferred way for storing
application settings yet registry has its own benefit. Normally it is difficult to find application created registry entries(if created carefully).
Below is a sample C# code.

//It will create a new subkey if not already created. otherwise it opens the existing one with write access.
RegistryKey objRegistryKey = Registry.CurrentUser.CreateSubKey("App_Name");
//Suppose i want to save last open time when application opened.
objRegistryKey.SetValue("LastOpenTime", DateTime.Now.ToString());


To get the value from registry, you use
string lastOpenDT = objRegistryKey.GetValue("LastOpenTime") as string;

The GetValue return the object type. you can than cast to the appropriate type.


Don't forget to add Microsoft.Win32 namespace.

For further reading,you can see the following two classess at msdn.
Registry,RegistryKey class.

Wednesday, May 20, 2009

multiple submit buttons and the enter key

As you know it is the limitation of asp.net that it has only one form, so if you have another section which needs enter key submission, than you can use default button as used below.
The defaultButton property of Panel or Form is used to ensure Enter Key Submission. Typically people used to Enter Key submission and if it is disabled, it might be annoying certain times.

The defaultButton really provides a way to handle Enter Keys for respective portions of the page when the focus is there.

Example:

<form defaultbutton="button1" runat="server">
<asp:textbox id="textbox1" runat="server"/>
<asp:textbox id="textbox2" runat="server"/>
<asp:button id="button1" text="Button1" runat="server"/>

<asp:panel defaultbutton="button2" runat="server">
<asp:textbox id="textbox3" runat="server"/>
<asp:button id="button2" runat="server"/>
</asp:panel>
</form>

Friday, April 24, 2009

Extract links from html in C#

private List ExtractLinks(string html)
{
List links = new List();

string startSquence = "<a";
string endSequence = "</a>";

html = html.ToLower();

while (html.IndexOf("<a") != -1)
{
int start = html.IndexOf(startSquence) ;
int end = html.IndexOf(endSequence, start+startSquence.Length);

//Extract the link, and add it to the list
if (end > start)
{
string link = html.Substring(start, end + endSequence.Length - start);

//Check b
if (link.Substring(1).IndexOf(startSquence) != -1)
{
html = html.Substring(start + startSquence.Length);
continue;
}

if (link != string.Empty)
{
links.Add(link);
}
}
else if (end < start)
{
html = html.Substring(start + startSquence.Length);
continue;
}
//Trim the raw data
html = html.Substring(end + endSequence.Length);
}
return links;
}