Friday, August 18, 2023

Install Visual Studio Code on Arch Linux

 To install visual studio code on arch linux, go to below link.

https://aur.archlinux.org/packages/visual-studio-code-bin

Clone the mentioned Git Clone URL and download on your system. Once download complete, go to folder and run following command.

makepkg -si




Thursday, November 24, 2022

Openvpn Decoding PKCS12 Failed

Recently I got following error on arch linux while trying to connect openvpn.

Decoding PKCS12 failed. Probably wrong password or unsupported/legacy encryption

The solution is to re-encrypt the key file to non legacy algorithm. e.g.

openssl pkcs12 -in old_key.p12 -out new_key.p12 -aes256 -legacy

Tuesday, January 31, 2017

Compiz bug - ubuntu

There is a bug in compiz that causes crash if you click the application that has multiple windows open. The error message normally is:

“Sorry Ubuntu * has experienced an internal error” /usr/bin/compiz

It's fix is simple. Install compize configuration settings and than follow these steps.

1. open ccsm (from terminal)
2. Go to Preferences
3. Go to Plugin list
4. Disable "Automatic Plugin Sorting"
5. Select scale in the right list
6. Click on "<" button
7. Enable"Automatic Pluging Sorting"
8. Reopen ccsm and enable scale
9. Make sure that scale is not the last in the list
[Source] https://bugs.launchpad.net/ubuntu/+source/unity/+bug/1497163


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;
}

Wednesday, April 22, 2009

how to modify web.config in asp.net using C#

You can modify web.config at run time. For exmaple to add a property in app settings section of web.config, you can use the following c# code

Configuration myConfiguration = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~");
myConfiguration.AppSettings.Settings.Add("CommentsLimit", "10");
myConfiguration.Save();


To update the existing property:
Configuration myConfiguration = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~");
myConfiguration.AppSettings.Settings["CommentsLimit"].Value = "20";
myConfiguration.Save();

Thursday, April 9, 2009

virtual keyword in C#

If a base class method is to be overriden, it is defined using the keyword virtual
The class member method may be overriden even if the virtual keyword is not used, but its usage makes the code more transparent & meaningful.

When the override keyword is used to override the virtual method, in a scenario where the base class method is required in a child class along with the overriden method, then the base keyword may be used to access the parent class member. The following example will be helpful to understand.

public class Shape
{
string name;
public virtual void SetName(string name)
{ this.name = name; }
}


public class Circle : Shape
{
//This method is being overriden
public override void SetName(string name)
{
base.SetName("circle"); //We are calling parent class method
}
}

Wednesday, April 8, 2009

How to Backup MySQL Database automatically in linux

The command for back up a mysql database is:

15 2 * * * root mysqldump -u root -pPASSWORD --all-databases | gzip > /mnt/disk2/database_`data '+%m-%d-%Y'`.sql.gz

The first part is "15 2 * * *". The five fields mean "minute, hour, day of month, month, day of week" respectively. The character '*' stands for "any".
The next, "root", means "run following command as root account".

You can use cron job so that it takes backup daily.

Friday, March 20, 2009

World Sleep Day 2009

World Sleep Day is an international annual event, intended to be a celebration of sleep and a call to action on important issues related to sleep, including medicine, education, social aspects and driving. It aims to lessen the burden of sleep problems on society through better prevention and management of sleep disorders. World Sleep Day 2009 is being held on March 20th, under the slogan ‘Drive alert, arrive safe’. This year’s theme is transportation, focussing on safety, travel and driving alertness.

The first World Sleep Day was launched on March 14th 2008. Events involving local groups took place in public settings around the world and online with the unveiling of a declaration, presentation of educational materials, and exhibition of videos.



The World Sleep Day declaration is as follows:

  • Whereas, sleepiness and sleeplessness constitute a global epidemic that threatens health and quality of life,

  • Whereas, much can be done to prevent and treat sleepiness and sleeplessness,

  • Whereas, professional and public awareness are the firsts steps to action,

  • We hereby DECLARE that the disorders of sleep are preventable and treatable medical conditions in every country of the world.

The World Sleep Day Committee would like you to assist in raising awareness of World Sleep Day 2009 by carrying out related activities in your country. World Sleep Day Committee members:
Antonio Culebras, co-chair
Liborio Parrino, co-chair
Richard Allen,
Sudhansu Chokroverty,
Christian Guilleminault,
Mario Terzano,
Robert Thomas,
Claudia Trenkwalder,
Allan O’Bryan, WASM Executive Director.





Source:http://worldsleepday.wasmonline.org/

Thursday, March 5, 2009

How to validate integer in c#

In C#, we often need to validate that the value is an int. So most developers use try catch block as below.
try
{
int t = Convert.ToInt32("wrongval");
}
catch
{
}

while the best approach to test must be:

int num = 0;
Int32.TryParse("wrongval", out num); //It will not throw any exception, In case of failure, it set the value of num to zero and also return FALSE.


if you see the performance of above two methods, you will be amazed that the TryParse method is 1000 times faster than Convert.ToInt32.

Saturday, February 14, 2009

force one instance of an application in .NET

To force a single instance of an application, either fetch all processess and check your application process name that is it already there or not. Another option is to use Mutex class.

bool NoInstanceCurrently;
System.Threading.Mutex mutex = new System.Threading.Mutex(false, "applicationname", out NoInstanceCurrently);
if (NoInstanceCurrently == false)
{

MessageBox.Show("Another Instance is Running", "ApplicationName", MessageBoxButtons.OK, MessageBoxIcon.Stop);
return;
}

Play sound from Window Form in C#

Playing a sound from window forms in C# is simple because of SoundPlayer class from System.Media namespace.

SoundPlayer objSoundPlayer = new SoundPlayer("sound1.wav");
objSoundPlayer .Play();

Saturday, January 31, 2009

Single line If Statement.

string name = Session["UserName"];

if(string.isNullOrEmpty(name))
Response.Write("welcome guest");
else
Response.Write("welcome "+name);

You can write it in single line as below.

Response.Write((string.isNullOrEmpty(name)) ? "Welcome guest" : "Welcome "+name);

The HTML Label Tag Benifits

Make your forms accessible to screen readers
Make your forms easy to click on
Give your CSS more to hold on to


To see more detail, check this Link

Use generics with drop down list

You can use generice to bind with drop down list. Suppose you have a class Country.

public class Country
{
int id;
string countryName;

public int ID
{
get { return id; }
}


public string CountryName
{
get { return countryName; }
set { countryName = value; }
}
}

List objCountry = new List();
objCountry = objCountry.FetchCountries();
ddlCountryList.DataSource = objCountry;
ddlCountryList.DataTextField = "CountryName";
ddlCountryList.DataValueField = "ID";
ddlCountryList.DataBind();

The ddlCountryList is an asp.net drop down list control.