Kohana – list all database tables

by on Mar.03, 2015, under Kohana, PHP

foreach(Database::instance()->list_tables() as $table_name)
{
    //blah blah
}
Comments Off more...

Add charts to your PHP application

by on Feb.17, 2015, under HTML & CSS, Javascript & Ajax, PHP

Home page:
http://www.chartjs.org/

Documentation:
http://www.chartjs.org/docs/

Download:
https://github.com/nnnick/Chart.js

Example:

var data = [
	{
		value: 10,
		color:"#4F9B1F",
		highlight: "#4F9B1F",
		label: "Online"
	},
	{
		value: 5,
		color: "#D11717",
		highlight: "#D11717",
		label: "Offline"
	},
	{
		value: 3,
		color: "#7A7A7A",
		highlight: "#7A7A7A",
		label: "Dead"
	}
]
 
Chart.defaults.global.responsive = true;
 
window.onload = function(){
	var ctx = document.getElementById("chartarea").getContext("2d");
	window.myPie = new Chart(ctx).Pie(data);
};
<div id="chartContainer">
    <canvas id="chartarea"/>
</div>
Comments Off more...

Get the UTC offset for the specified local time

by on Feb.13, 2015, under C#

public String GetUtcOffset
{
    return TimeZone.CurrentTimeZone.GetUtcOffset(DateTime.Now);
}
Comments Off more...

Get operating system language in c#

by on Feb.12, 2015, under C#

GetSystemDefaultLCID

Returns the locale identifier for the system default locale, identified by LOCALE_SYSTEM_DEFAULT.

[DllImport("kernel32.dll")]
public static extern uint GetSystemDefaultLCID();
Comments Off more...

How to check the machine type in C#

by on Feb.11, 2015, under C#

public enum ChassisTypes
{
	Other = 1,
	Unknown,
	Desktop,
	LowProfileDesktop,
	PizzaBox,
	MiniTower,
	Tower,
	Portable,
	Laptop,
	Notebook,
	Handheld,
	DockingStation,
	AllInOne,
	SubNotebook,
	SpaceSaving,
	LunchBox,
	MainSystemChassis,
	ExpansionChassis,
	SubChassis,
	BusExpansionChassis,
	PeripheralChassis,
	StorageChassis,
	RackMountChassis,
	SealedCasePC
}
 
public ChassisTypes GetCurrentChassisType()
{
	try
	{
		ManagementClass mc = new ManagementClass("Win32_SystemEnclosure");
		foreach (ManagementObject mo in mc.GetInstances())
			foreach (int i in (UInt16[])(mo["ChassisTypes"]))
				if (i > 0 && i < 25)
					return (ChassisTypes)i;
		return ChassisTypes.Unknown;
	}
	catch
	{
		return ChassisTypes.Unknown;
	}
}
Comments Off more...

Identifying the GPU using C#

by on Feb.11, 2015, under C#

public static String GetGPU()
{
	ManagementObjectSearcher mos = 
		new ManagementObjectSearcher("SELECT * FROM Win32_DisplayConfiguration");
 
	String GPU = "";
	foreach (ManagementObject mo in mos.Get())
		foreach (PropertyData property in mo.Properties)
			if (property.Name == "Description")
				GPU = property.Value.ToString();
	return GPU;
}

According to Microsoft, Win32_DisplayConfiguration is obsolete for Windows newer than Windows Vista. But it still works for Windows 7 and Windows 8.

Option 2

public static String GetGPU()
{
	ManagementObjectSearcher mos =
		new ManagementObjectSearcher("SELECT * FROM Win32_VideoController");
 
	String GPU = "";
	foreach (ManagementObject mo in mos.Get())
		foreach (PropertyData property in mo.Properties)
			if (property.Name == "Caption")
				GPU += property.Value.ToString() + " ";
	return GPU;
}
Comments Off more...

Identifying the CPU architecture type using C#

by on Feb.02, 2015, under C#

public String GetCpuArchitecture()
{
	ManagementObjectSearcher mos = new ManagementObjectSearcher("SELECT Architecture FROM Win32_Processor");
	ManagementObjectCollection moc = mos.Get();
	ManagementObjectCollection.ManagementObjectEnumerator moe = moc.GetEnumerator();
	moe.MoveNext();
	ushort arch = (ushort)moe.Current["Architecture"];
 
	switch (arch)
	{
		case 0:
			return "x86";
		case 1:
			return "MIPS";
		case 2:
			return "Alpha";
		case 3:
			return "PowerPC";
		case 6:
			return "Itanium";
		case 9:
			return "x64";
		default:
			return "Unknown Architecture";
	}
}
Comments Off more...

Getting visitors country from their IP

by on Feb.01, 2015, under Pecl, PHP

geoip_country_code_by_name

The geoip_country_code_by_name() function will return the two letter country code corresponding to a hostname or an IP address.

geoip_country_name_by_name

The geoip_country_name_by_name() function will return the full country name corresponding to a hostname or an IP address.

Comments Off more...

Getting visitors country from their IP

by on Feb.01, 2015, under PHP

geoplugin

geoPlugin is a free and easy webmaster resource to provide geolocation technology to your pages.

$xml = simplexml_load_file('http://www.geoplugin.net/xml.gp?ip='.$visitor_ip_address);
 
foreach ($xml as $key => $value)
{
    echo $key , '= ' , $value ,  '<br>';
}
Comments Off more...

How to configure cookies in Kohana

by on Jan.28, 2015, under Kohana, PHP

Put this in your bootstrap.php file:

Kohana_Cookie::$salt = md5('?jrA#VXrEH-f@?8!vuve6VCGgcjm#ar?BBAG'); //change it
Kohana_Cookie::$expiration = 86400; //1 day
Kohana_Cookie::$domain = '.mydomain.com';
Kohana_Cookie::$secure = TRUE; //allow cookies to be accessed only on a secure connection
Kohana_Cookie::$httponly = TRUE; //make cookies inaccessible to Javascript
Comments Off more...

%d bloggers like this: