Skip to content

Instantly share code, notes, and snippets.

@hkhoshraftar
hkhoshraftar / activity.java
Created August 7, 2018 11:39
android check internet connection
private boolean haveInternet(){
NetworkInfo info = ((ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE)).getActiveNetworkInfo();
if (info==null || !info.isConnected()) {
return false;
}
return true;
}
@hkhoshraftar
hkhoshraftar / activity.java
Created August 7, 2018 11:35
Double back press for exit
private static long back_pressed;
@Override
public void onBackPressed()
{
if (back_pressed + 2000 > System.currentTimeMillis()) super.onBackPressed();
else Toast.makeText(getBaseContext(), "Press once again to exit!", Toast.LENGTH_SHORT).show();
back_pressed = System.currentTimeMillis();
}
@hkhoshraftar
hkhoshraftar / dropAll.sql
Created May 20, 2018 06:03
Drop all the tables, stored procedures, triggers, constraints and all the dependencies in one sql statement
/* Drop all non-system stored procs */
DECLARE @name VARCHAR(128)
DECLARE @SQL VARCHAR(254)
SELECT @name = (SELECT TOP 1 [name] FROM sysobjects WHERE [type] = 'P' AND category = 0 ORDER BY [name])
WHILE @name is not null
BEGIN
SELECT @SQL = 'DROP PROCEDURE [dbo].[' + RTRIM(@name) +']'
EXEC (@SQL)
@hkhoshraftar
hkhoshraftar / activity.java
Created May 8, 2018 08:59
android custom content layout programatically
public void setContentView(int layoutResID,int actionbarId) {
View newLayout = getLayoutInflater().inflate(R.layout.template_activity_1,null,false);
ViewGroup viewGroup = newLayout.findViewById(R.id.m_new_root);
ViewGroup.LayoutParams para = new ViewGroup.LayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
View oldRoot =getLayoutInflater().inflate(layoutResID,viewGroup,false);
newLayout.setLayoutParams(para);
viewGroup.addView(getLayoutInflater().inflate(actionbarId,viewGroup,false));
viewGroup.addView(oldRoot);
CREATE FUNCTION [dbo].[fnDatetoUnix] (
@ctimestamp datetime
)
RETURNS integer
AS
BEGIN
/* Function body */
declare @return integer
SELECT @return = DATEDIFF(SECOND,{d '1970-01-01'}, @ctimestamp)
public static IConfigurationRoot configuration;
public static void Main(string[] args)
{
var builder = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true);
configuration = builder.Build();
@hkhoshraftar
hkhoshraftar / Sql db Table to C# class
Last active March 15, 2018 05:32
Generate C# class From Sql table Schema
declare @TableName sysname = 'TableName'
declare @Result varchar(max) = 'public class ' + @TableName + '
{'
select @Result = @Result + '
public ' + ColumnType + NullableSign + ' ' + ColumnName + ' { get; set; }
'
from
(
select