vendredi 21 juillet 2017

How to generate a C# entity of an SQL Server table

  Aucun commentaire
Hey, wassuuuuuuup πŸ˜†πŸ˜†πŸ˜πŸ˜



Here is a trick for generating a C# entity of an SQL Server table.

For doing this, just execute the following SQL script... Don't forget to replace TableName in red with the name of the table...

declare @TableName sysname = 'TableName'
declare @Result varchar(max) = 'public class ' + @TableName + '
{'
select @Result = @Result + '
    public ' + ColumnType + NullableSign + ' ' + ColumnName + ' { get; set; }
'
from
(
    select
        replace(col.name, ' ', '_') ColumnName,
        column_id ColumnId,
        case typ.name
            when 'bigint' then 'long'
            when 'binary' then 'byte[]'
            when 'bit' then 'bool'
            when 'char' then 'string'
            when 'date' then 'DateTime'
            when 'datetime' then 'DateTime'
            when 'datetime2' then 'DateTime'
            when 'datetimeoffset' then 'DateTimeOffset'
            when 'decimal' then 'decimal'
            when 'float' then 'float'
            when 'image' then 'byte[]'
            when 'int' then 'int'
            when 'money' then 'decimal'
            when 'nchar' then 'string'
            when 'ntext' then 'string'
            when 'numeric' then 'decimal'
            when 'nvarchar' then 'string'
            when 'real' then 'double'
            when 'smalldatetime' then 'DateTime'
            when 'smallint' then 'short'
            when 'smallmoney' then 'decimal'
            when 'text' then 'string'
            when 'time' then 'TimeSpan'
            when 'timestamp' then 'DateTime'
            when 'tinyint' then 'byte'
            when 'uniqueidentifier' then 'Guid'
            when 'varbinary' then 'byte[]'
            when 'varchar' then 'string'
            else 'UNKNOWN_' + typ.name
        end ColumnType,
        case
            when col.is_nullable = 1 and typ.name in ('bigint', 'bit', 'date', 'datetime', 'datetime2', 'datetimeoffset', 'decimal', 'float', 'int', 'money', 'numeric', 'real', 'smalldatetime', 'smallint', 'smallmoney', 'time', 'tinyint', 'uniqueidentifier')
            then '?'
            else ''
        end NullableSign
    from sys.columns col
        join sys.types typ on
            col.system_type_id = typ.system_type_id AND col.user_type_id = typ.user_type_id
    where object_id = object_id(@TableName)
) t
order by ColumnId
set @Result = @Result  + '
}'
print @Result

Original Source : https://stackoverflow.com/a/5873231

jeudi 8 juin 2017

How to setup a Cron Job on Ubuntu?

  Aucun commentaire
Hey, Wasuuuuuuup 😝

Today we will learn how to setup / start a Cron Job on Ubuntu.

What is a cron job ?

The software utility Cron is a time-based job scheduler in Unix-like computer operating systems. People who set up and maintain software environments use cron to schedule jobs (commands or shell scripts) to run periodically at fixed times, dates, or intervals. It typically automates system maintenance or administration—though its general-purpose nature makes it useful for things like downloading files from the Internet and downloading email at regular intervals.[1] The origin of the name cron is from the Greek word for time, Ο‡ΟΟŒΞ½ΞΏΟ‚ (chronos).[2] (Ken Thompson, author of cron, has confirmed this in a private communication with Brian Kernighan.)  [By Wikipedia - Read more ...]
We understand now that a cron is a task executed each and every [time interval].

 How to setup my own cron job?

To setup your own cron, you should run the following command :
crontab -e
Then add your task line. Let's take as example this line:
* * * * * /path/to/command 
The task above executes a command each and every minute...



Cron jobs time interval can be customized, read more ...

Hope this article helps you to setup your first cron πŸ˜‰

[FIX] Why the "< ?" tag is not working on php ?

  Aucun commentaire

Heeey, Wassuuuuuuuuuup....

Today we will fix the "<?" tag problem in PHP.

If you are one of those that faced that problem, you probably didn't enabled the "short_open_tag" in your php.ini file by setting the value of the option "short_open_tag" to "On"

To fix the problem you should follow these step.
  1. Locate the php.ini file

    In order to enable the "short_open_tag" option, you must find the php.ini file in your server.
    If you know the location of php.ini file in your server, you an skip this step.
    To locate php.in, create a new file (infos.php) in your html directory:
    nano infos.php
    And parse this line :
    <?php phpinfo(); ?>
    Open your navigator and go to your infos.php page :
    http://YOUR_IP/infos.php
    Now you can see the path of the php.ini file, for me it's : /etc/php5/fpm/php.ini
  2. Change the short_open_tag option

    Now as you are able to locate the php.ini file, you can open it with your preferred editor, I use "nano" .
    nano (your php.ini path)
    Then you will see the "short_open_tag = Off", fix the problem  by setting it to :
    short_open_tag = On
Note : You must restart your php service (apache or php-fpm) in order to apply changes.

That's it! hope it works for you πŸ˜‰

mardi 6 juin 2017

[FIX] Call to undefined method mysqli_stmt::get_result

  Aucun commentaire


Great to see you again,

Today we're gonna fix the problem that shows the message "Call to undefined method mysqli_stmt::get_result".

I actually faced that problem when I was trying to install nginx + php5-fpm + php5-mysql in my server, everything worked for me, except that method "get_result".

So, like any beginner πŸ˜… I googled'it, and I found that I have to install this package "php5-mysqlnd" using the following command:
apt-get install php5-mysqlnd
Hope it works for your  !