Skip to content

Instantly share code, notes, and snippets.

@hkhoshraftar
hkhoshraftar / 0_reuse_code.js
Created January 8, 2016 11:54
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@hkhoshraftar
hkhoshraftar / BooksGalleryFragment.java
Created July 8, 2016 15:29
Simple RecyclerView Adapter
public class DataAdapter extends RecyclerView.Adapter<DataAdapter.ViewHolder> {
ArrayList<String> countries;
public DataAdapter(ArrayList<String> countries) {
this.countries = countries;
}
@Override
public DataAdapter.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.card_row, viewGroup, false);
@hkhoshraftar
hkhoshraftar / centos-create-root-user
Created December 2, 2017 07:11
Create root user #centos
adduser username
passwd username
usermod -aG wheel username
su - username
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
CREATE FUNCTION [dbo].[fnDatetoUnix] (
@ctimestamp datetime
)
RETURNS integer
AS
BEGIN
/* Function body */
declare @return integer
SELECT @return = DATEDIFF(SECOND,{d '1970-01-01'}, @ctimestamp)
@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);
@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 July 24, 2018 14:05
CALL GOOGLE MAP VIEW
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setData(Uri.parse("geo:35.734481, 51.406799?z=20"));
startActivity(intent);
@hkhoshraftar
hkhoshraftar / openPort.sh
Created August 21, 2018 07:59
#linux #centos #firewall #port
firewall-cmd --zone=public --add-port=3306 /tcp --permanent
firewall-cmd --reload