Thứ Ba, ngày 19 tháng 4 năm 2016

Getting Started With ASP.NET 5 On Ubuntu 14.04.2 LTS

Getting Started With ASP.NET 5 On Ubuntu

 16. June 2015 22:59
Ever since the .NET stack went open source last year, there is a huge excitement among the developers about the .NET stuff and developing apps using .NET which are no longer limited to Windows platform. I tried to install ASP.NET VNext on Ubuntu VM in which I terribly failed in the first go. Why? because the tutorial I used was quite old and I messed up the installation of pre-requisites. But I get everything working in the second try. So here are the steps and commands that will get you started with ASP.NET VNext on Ubuntu.
I am setting up a fresh VM for development on Ubuntu 14.04.2 LTS
Installing Mono
First thing is to install Mono. For folks who are new to Linux environment, Mono is a community driven project which allows developers to build and run .NET application on Linux platforms. Here is the set of commands that I have to execute to install Mono.
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF
echo "deb http://download.mono-project.com/repo/debian wheezy main" | sudo tee /etc/apt/sources.list.d/mono-xamarin.list
sudo apt-get update
Install the latest version of Mono available.
sudo apt-get install mono-complete
To check if Mono is successfully installed or to determine the version of Mono on you machine run the below command in the terminal.
mono --version
Installing LibUV
As stated on Github:
Libuv is a multi-platform asynchronous IO library that is used by the KestrelHttpServer that we will use to host our web applications.
Running the below command will install LibUV along with the dependencies require to build it.
sudo apt-get install automake libtool
Getting the source and building and installing it.
curl -sSL https://github.com/libuv/libuv/archive/v1.4.2.tar.gz | sudo tar zxfv - -C /usr/local/src
cd /usr/local/src/libuv-1.4.2
sudo sh autogen.sh
sudo ./configure
sudo make 
sudo make install
sudo rm -rf /usr/local/src/libuv-1.4.2 && cd ~/
sudo ldconfig
Here is a note at Githb repo that explains what the above set of commands are doing.
NOTE: make install puts libuv.so.1 in /usr/local/lib, in the above commands ldconfig is used to update ld.so.cache so that dlopen (see man dlopen) can load it. If you are getting libuv some other way or not running make install then you need to ensure that dlopen is capable of loading libuv.so.1
Getting .NET Version Manager (DNVM)
DNVM is a command line tool which allows you to get new build of the DNX (.NET Execution Environment) and allows you to switch between them. To get DNVM running fire the below command in the terminal.
curl -sSL https://raw.githubusercontent.com/aspnet/Home/dev/dnvminstall.sh | DNX_BRANCH=dev sh && source ~/.dnx/dnvm/dnvm.sh
To check if the DNVM is successfully installed on your machine, type DNVM in the terminal. The output should be something like this:
At any point of time if you want to list out the installed DNX runtimes, run the below command
dnvm list
The next step after this, is to upgrade the DNVM so you can use the dnx and dnu commands. Run the following command in the terminal
dnvm upgrade
Once this is done, we are all set to run ASP.NET VNext application on Ubuntu box. Clone the aspnet/Home repository from Github. If you don't have Git installed then install it with this simple command.
sudo apt-get install git
For simplicity, I have created a new directory on Ubuntu desktop named vnext. You can name the directory as you wish. Navigate to this directory in the terminal and clone the aspnet/Home repository.
git clone https://github.com/aspnet/Home.git
After cloning of repository is done, navigate to the 1.0.0-beta4 directory.
You can see three sample applications that you can test. For this tutorial I am going to checkout HelloMvc application. Get inside theHelloMvc directory and then, run the command 
dnu restore
This will take some time to execute. I didn't face this problem but there is a chance that someone will. When you run this command, theproject.json.lock file gets created and the restore of the package will start. In the end when the restore is finalizing, it may say permission is denied. To resolve this error you can change the permission of the folder by running the following command.
sudo chmod -R 755 HelloMvc
You should always change permission to 755 for directories and 644 for files.
After the execution is completed, you can start the server by running the command.
dnx . kestrel
This command will work for both web and mvc application. If you plan to test out the console application then you can run the following command.
dnx . run
The server runs at port 5004. Fire up the browser and type in http://localhost:5004/
Hope this is helpful for the first time users of Linux.

Chủ Nhật, ngày 20 tháng 3 năm 2016

MSSQL - find a SubString in a field of tables AND find which tables have reference to this table

DECLARE
    @search_string  VARCHAR(100),
    @table_name     SYSNAME,
    @table_schema   SYSNAME,
    @column_name    SYSNAME,
    @sql_string     VARCHAR(2000)

SET @search_string = 'CCC Helpdesk'

DECLARE tables_cur CURSOR FOR SELECT TABLE_SCHEMA, TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE'

OPEN tables_cur

FETCH NEXT FROM tables_cur INTO @table_schema, @table_name

WHILE (@@FETCH_STATUS = 0)
BEGIN
    DECLARE columns_cur CURSOR FOR SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = @table_schema AND TABLE_NAME = @table_name AND COLLATION_NAME IS NOT NULL  -- Only strings have this and they always have it

    OPEN columns_cur

    FETCH NEXT FROM columns_cur INTO @column_name
    WHILE (@@FETCH_STATUS = 0)
    BEGIN
        SET @sql_string = 'IF EXISTS (SELECT * FROM ' + QUOTENAME(@table_schema) + '.' + QUOTENAME(@table_name) + ' WHERE ' + QUOTENAME(@column_name) + ' LIKE ''%' + @search_string + '%'') PRINT ''' + QUOTENAME(@table_schema) + '.' + QUOTENAME(@table_name) + ', ' + QUOTENAME(@column_name) + ''''

        EXECUTE(@sql_string)

        FETCH NEXT FROM columns_cur INTO @column_name
    END

    CLOSE columns_cur

    DEALLOCATE columns_cur

    FETCH NEXT FROM tables_cur INTO @table_schema, @table_name
END

CLOSE tables_cur

DEALLOCATE tables_cur

================================================================================================================================

SELECT
    fk.name 'FK Name',
    tp.name 'Parent table',
    cp.name, cp.column_id,
    tr.name 'Refrenced table',
    cr.name, cr.column_id
FROM
    sys.foreign_keys fk
INNER JOIN
    sys.tables tp ON fk.parent_object_id = tp.object_id
INNER JOIN
    sys.tables tr ON fk.referenced_object_id = tr.object_id
INNER JOIN
    sys.foreign_key_columns fkc ON fkc.constraint_object_id = fk.object_id
INNER JOIN
    sys.columns cp ON fkc.parent_column_id = cp.column_id AND fkc.parent_object_id = cp.object_id
INNER JOIN
    sys.columns cr ON fkc.referenced_column_id = cr.column_id AND fkc.referenced_object_id = cr.object_id
WHERE
tr.name = 'QueueDefinition'
ORDER BY
    tp.name, cp.column_id

Thứ Tư, ngày 17 tháng 2 năm 2016

MySQL convert datetime to Unix timestamp

Try this Query for CONVERT DATETIME to UNIX TIME STAMP
SELECT UNIX_TIMESTAMP(STR_TO_DATE('Apr 15 2012 12:00AM', '%M %d %Y %h:%i%p'))
This Query for CHANGE DATE FORMATE
SELECT FROM_UNIXTIME(UNIX_TIMESTAMP(STR_TO_DATE('Apr 15 2012 12:00AM', '%M %d %Y %h:%i%p')),'%m-%d-%Y %h:%i:%p')
SELECT UNIX_TIMESTAMP(STR_TO_DATE('30.1.2016', '%d.%m.%Y'))*1000;
-> '1454086800000'

SELECT FROM_UNIXTIME('1454086800','%d-%m-%Y %h:%i%p');
-> '30-01-2016 12:00AM'

Thứ Ba, ngày 16 tháng 2 năm 2016

Top 10 Best Free Data Recovery Software of 2016

Top 10 Best Free Data Recovery Software of 2016

best-free-data-recovery-tool
ShortBytes: FossBytes brings you a list of the Best data recovery software of 2016 which are totally free. These data recovery tool save a lot of hassles after we accidently delete some important files or we do not take backups before formatting a hard drive. Using these free recovery software, you can recover your data back on your PC.

W
e lose our important data from hard disk by accidentally pressing the Delete key. Sometimes, a software bug or virus can also corrupt your hard disk. In that case, you need the best data recovery software or a recovery tool to recover your important data back at any cost.
At this point of time, a data recovery software come in handy. We have compiled a list of best free data recovery software considering factors such as whether the software can recover RAW, Unallocated, Corrupt or Formatted Hard Disk; its ability to recover from different file systems such as FAT, FAT32, HFS, NTFS etc.; the array of devices supported; time taken for file recovery and user friendliness to name a few. Here is a list of-
TOP 10 BEST DATA RECOVERY SOFTWARE 2016 FOR FREE:
1. Recuva:

The fact that Recuva is on the top of the best data recovery software list, may not come as a surprise to the most of you. Some of the features that bring Recuva on top of the list of Best recovery software software are:
Superior file recovery
Advanced deep scan mode
Secure overwrite feature that uses industry & military standard deletion techniques and,
Ability to recover files from damaged or newly formatted files
Easy User interface
2. TestDisk:

A list of best data recovery software can hardly be termed as being complete without a mention of TestDisk. Packed with features and a file recovery system that can easily overshadow that of any other data recovery software, TestDisk has a lot to offer for both novices and experts. Here are some of the TestDisk’s features:
Allows users to recover/rebuild the boot sector
Fix or recover deleted partition table besides being able to reliably undelete files from FAT, exFAT, NTFS and ext2 file systems.
Available on all major platforms such as Microsoft Windows, Mac OS X etc and is in fact quite popular as it can be found on various Linux Live CD’s.
Although being a command line tool, TestDisk may not be suitable for some users for data recovery.
3. Undelete 360:

With the looks of a typical Office application, theUndelete 360 is built on a fast yet efficient algorithm which enables the user to undelete files. Here are some of the features of Undelete 360:
Works on a variety of devices such as Digital cameras, USB’s etc.
It includes a data-wiping tool, a Hex Viewer along with the ability to preview files before recovery.
Does a great job in recovering recently deleted files as compared to other free data recovery software
Also able to recover files of a wide variety of types such as DOC, HTML, AVI, MP3, JPEG, JPG, PNG, GIF, etc.
However, scanning speed needs major improvement and it also lags out its competition in terms of recovering data.
4. PhotoRec:

Definitely one of the best data recovery software out there, PhotoRec is widely acclaimed for its powerful file recovery over a wide variety of devices ranging from digital cameras to hard-disks. Here are some of the features of PhotoRec recovery tool:
Compatible with almost all major platforms such as Microsoft Windows, Linux, Mac OS X etc.
Comes packed with the ability to recover more than 440 different file formats.
Features such as the ‘unformat function’ and the ability to add your own custom file types do come in handy.
Although I wouldn’t advise this free data recovery software to beginners as it is completely devoid of a GUI and uses a command line interface which may intimidate some users.
5. Pandora Recovery:

Pandora recovery is one of the most reliable and effective best free data recovery software out there. Pandora recovery tool has a lot to offer to its users. Here are some of the features of this tool:
Ability to recover deleted files from NTFS and FAT-formatted volumes
Preview deleted files of certain types (image and text files) without performing recovery
Surface scan ( which allows you to recover data from drives that have been formatted) and the ability to recover archived, hidden, encrypted and compressed files it packs quite a punch.
Its interface is very easy to get a hang of and provides an explorer-like view along with colour coded & recovery percentage indicators.
However, its file detection system is not that reliable and needs to be improved further. The software could be made portable as well so that it doesn’t consume any space on the hard disk and thereby not consume space that a file which we wish to recover once consumed.
6. MiniTool Partition Recovery:
Standard undelete programs like Recuva, Pandora etc. are perfect for recovering a few delted files, but what if when you have lost an entire partition? Then you will probably need a specialist application like MiniTool Partition Recovery. Here are some of the great features of this recovery tool specialized in partition recovery:
An easy wizard-based interface
Specialized in data recovery on an entire partition
Point MiniTool Partition Recovery tool at the problematic drive and it will scan for the missing partition.
Generates a recovery report which will let you know what the program has found to help you in data recovery
Can’t use data recovery on a bootable disc here.
7. Wise Data Recovery:
Wise data recovery tool is one of the fastest undelete tools among the best data recovery softwares. Besides being faster, it also comes with some of nice features. Here is a list of it’s features:
Easy and an intuitive interface
Can recover deleted files from local drives, USB drives, cameras, memory cards, removable media devices etc.
Faster search filter by selecting in-built file extension groups using the file’s type.
Compatible from WIndows XP to WIndows 8
Although the scanning is fast, the program has no deep scan mode which it could mean a slightly reduced chance of recovering the most hard to recover files.
8. Puran file Recovery:
Puran file recovery works in 3 main recovery modes. These recovery modes are:
Default Quick Scan (It simply reads the FAT or NTFS file system for deleted files from the recycle bin etc.)
Deep Scan (includes scanning all available free space) and,
Full Scan (checks all space on the device for the best chance of recovery)
Works from Windows XP to Windows 8
Using the “Find lost files” option turns Puran File Recovery into a tool to recover all files from a lost or damaged partition. Something else you can do is edit the custom scan list which stores file signatures for more accurate recovery of badly damaged data.
9. PC Inspector File recovery
PC Inspector File Recovery Works well on both FAT and NTFS drive even if the boot sector has been erased or damaged. Here are some of the features of this recovery tool.
Simple search dialog to help locating files by name
Recovered files can be restored in a local hard disk or network drives.
Can recover image and video of several types of files in different formats such as ARJ, AVI, BMP, DOC, DXF, XLS, EXE, GIF, HLP, HTML, JPG, LZH, MID, MOV, MP3, PDF, PNG, RTF, TAR, TIF, WAV and ZIP.
Can scan just specific areas of the disc with the Cluster scanner
Works perfectly from Windows XP to Windows 7
However the interface is a little confusing mess of tabs. So, be careful with this tool.
10. Restoration
Restoration data recovery program take the final position in the list of top 10 best data recovery software tool. It is no different and is similar to the other free undelete apps on this list. Even if it is on the tenth position, here are a few things that we liked about this data recovery tool:
Very simple and easy to use
No confusing and no cryptic buttons or any complicated file recovery procedures
It can recover data and files from hard drives, memory cards, USB drives, and other external drives as well.
Does not need to be installed and can run data recovery from a floppy disk or USB drive.
Supports Windows Vista, XP, 2000, NT, ME, 98, and 95 and also, successfully tested Windows 7 and Windows 10.
Sometimes, runs into a problem with Windows 8
Editor’s pick: 
I would personally recommend Piriform’s Recuva to all our readers hands down. With superior file recovery , an advanced deep scan mode, a secure overwrite feature that uses industry & military standard deletion techniques and the ability to recover files from damaged or newly formatted files , Recuva is undeniably one of the best free data recovery tools out there. Its portability (the ability to run without installation) is one feature that sets it apart from the others.
The User Interface wouldn’t let you down either with a file-recovery wizard and an application manual mode available to your disposal which provides colour coding (indicating the probability of the recovery of a file) along with the ability to preview files before undeleting them. Recuva is definitely a notch above all others and undoubtedly the most complete and reliable free data recovery software available today.
Also read: Top 10 Best Free Antivirus Software Of 2016

Have some other data recovery software in mind? Give us your suggestions in the comments below.

Song đề tù nhân

một khái niệm cơ bản trong Lý thuyết Trò chơi, có thể cho chúng ta một cái nhìn mới về vấn đề này. Đây là một thí nghiệm tưởng tượng trong Toán học. Giả định có hai nghi phạm bị bắt, mỗi người phải lựa chọn hoặc giữ im lặng hoặc thú tội với cảnh sát.

Điều kiện đưa ra là nếu cả hai cùng thú tội, mỗi người phải ngồi tù hai năm. Nếu không ai lên tiếng, mỗi người chỉ chịu án một năm. Tuy nhiên, nếu một người nhận tội, người kia vẫn chối, thì người nhận tội sẽ được trả tự do, kẻ chối tội sẽ phải bị giam ba năm.

Trong ví dụ này, cả hai nghi phạm sẽ cùng được lợi nhiều nhất khi cùng hợp tác là giữ im lặng. Điều đáng nói là mỗi người phải đưa ra quyết định mà không chắc chắn về lựa chọn của người kia, vì thế họ không đủ tin tưởng để hợp tác. Do đó mỗi nghi phạm sẽ vì tối ưu hóa lợi ích cá nhân mà nhận tội, để cả hai phải nhận bản án bất lợi nhất: hai năm tù cho mỗi người.

Mô hình toán học này cho thấy quyết định của mỗi cá nhân, nếu như độc lập và không có niềm tin, sẽ dẫn đến kết quả xấu cho cả tập thể.

Chủ Nhật, ngày 27 tháng 12 năm 2015

Using Spring Session for Securing RestFull webservice in Spring MVC web application

Getting started with Spring Security, Spring Session and Redis

You want to build a scalable cloud ready application? Great! Let’s have a look how to build a server Spring Boot REST endpoint and secure it with stateless Spring Security. We want to authenticate every request with basic authentication OR with a token when the user has sent its credentials once. When a user authenticates with basic authentication we store a session ID in Redis with Spring Session and return it to the user to in the following requests.
If you haven’t heard of Spring Boot before, be sure to read up on it on: What are Microservices or Build your own Linkshortener API.

Standard HTTP Session in Java (JEE)

There are a quite a few shortcommings in Application Servers HTTP session implementations that we want to avoid:
  • Have you ever tried to enable HTTP Sessions replication and clustering on Tomcat? It’s not an easy thing to do.
  • Sessions are tightly coupled with the HTTP protocol, but there are other scenario’s where you’d like to access the session like when using JMS. Or keeping sessions alive when using WebSockets.
  • How do you go about when you want to allow users to have multiple sessions, one for each tab (like in Gmail)?

Get started with Spring Session

With Spring Session all these issues are solved without any effort. This makes it easy to scale your cloud application since it doesn’t need to store sessions on disk anymore. As long as your Application Server uses a HttpSession, you can get started in a couple of easy steps. Let’s get started with a simple Spring Boot application with Spring Security for securing a RESTful service and store sessions in Redis:
Application.java
@SpringBootApplication
public class Application {

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}
pom.xml

  
    org.springframework.session
spring-session-data-redis 1.0.1.RELEASE org.springframework.boot spring-boot-starter-security org.springframework.boot spring-boot-starter-web
This would give us a working web application, that is secured by default because we include the Spring Boot Security Starter dependency. For ease of use we’ll start an in-memory database with one user present to use for authentication. We will authenticate every request with Basic Authentication and also create a HeaderHttpSessionStrategyto tell Spring to use a X-Auth-Token header for retrieving the session.
SecurityConfiguration.java
@Configuration
@EnableWebSecurity
@Order(SecurityProperties.ACCESS_OVERRIDE_ORDER)
public class SecurityConfig extends WebSecurityConfigurerAdapter {
    @Override
    protected void configure(AuthenticationManagerBuilder builder) throws Exception {
        builder.inMemoryAuthentication()
            .withUser("user").password("password").roles("USER");
    }

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http
            .authorizeRequests()
            .anyRequest().authenticated()
            .and()
            .requestCache()
            .requestCache(new NullRequestCache())
            .and()
            .httpBasic();
    }

    @Bean
    public HttpSessionStrategy httpSessionStrategy() {
        return new HeaderHttpSessionStrategy();
    }
}

Hello Redis - a NoSQL key-value database

We don’t want to to reauthenticate every request by going to the database, this is why we will store a Session ID in Redis. This Session ID will be passed to the client after authenticating the first time, and from then on it can send this as a request header for all subsequent requests which will verify the user is authenticated.
If you look at the Spring Session documentation you’ll see that they always use an@EmbeddedRedisConfiguration to start an embedded Redis instance, it’s pretty unclear that this is NOT yet available in Spring Session. They included some addtional classes in all their examples to get this to work, we’ll have to wait for Spring Session GitHub ticketuntil this will actually be implemented in Spring itself. For now I have a simple Configuration class that starts an instance without any customization, by using the Embedded redis depdency.
pom.xml

    com.github.kstyrc
embedded-redis 0.6
EmbeddedRedisConfiguration.java
@Configuration
@EnableRedisHttpSession
public class EmbeddedRedisConfiguration {
    private static RedisServer redisServer;

    @Bean
    public JedisConnectionFactory connectionFactory() throws IOException {
        redisServer = new RedisServer(Protocol.DEFAULT_PORT);
        redisServer.start();
        return new JedisConnectionFactory();
    }

    @PreDestroy
    public void destroy() {
        redisServer.stop();
    }
}
And to finish it off we’ll expose one endpoint to actually verify the outcome of our security configuration.
UserController.java
@RestController
public class UserController {

    @RequestMapping("/api/users")
    public String authorized() {
        return "Hello Secured World";
    }
}
We can verify the behaviour of our application by using curl:
curl -v http://localhost:8080/api/users
< HTTP/1.1 401 Unauthorized
* Server Apache-Coyote/1.1 is not blacklisted
< Server: Apache-Coyote/1.1
< X-Content-Type-Options: nosniff
< X-XSS-Protection: 1; mode=block
< Cache-Control: no-cache, no-store, max-age=0, must-revalidate
< Pragma: no-cache
< Expires: 0
< X-Frame-Options: DENY
< WWW-Authenticate: Basic realm="Realm"
< Content-Type: application/json;charset=UTF-8
< Transfer-Encoding: chunked
< Date: Thu, 21 May 2015 21:44:26 GMT
Now let’s do that again, but this time add Basic Authentication with our in-memory database user:
curl -v http://localhost:8080/api/users -u user:password
< HTTP/1.1 200 OK
* Server Apache-Coyote/1.1 is not blacklisted
< Server: Apache-Coyote/1.1
< X-Content-Type-Options: nosniff
< X-XSS-Protection: 1; mode=block
< Cache-Control: no-cache, no-store, max-age=0, must-revalidate
< Pragma: no-cache
< Expires: 0
< X-Frame-Options: DENY
< x-auth-token: ef555ceb-1c77-4fdd-8e42-e04399fe5b95
< Content-Type: text/plain;charset=UTF-8
< Content-Length: 19
< Date: Thu, 21 May 2015 21:47:30 GMT
We send our credentials and received a x-auth-token in the response, which we can use in the following requests to authenticate:
curl -v http://localhost:8080/api/users -H "x-auth-token: ef555ceb-1c77-4fdd-8e42-e04399fe5b95"
< HTTP/1.1 200 OK
* Server Apache-Coyote/1.1 is not blacklisted
< Server: Apache-Coyote/1.1
< X-Content-Type-Options: nosniff
< X-XSS-Protection: 1; mode=block
< Cache-Control: no-cache, no-store, max-age=0, must-revalidate
< Pragma: no-cache
< Expires: 0
< X-Frame-Options: DENY
< Content-Type: text/plain;charset=UTF-8
< Content-Length: 19
< Date: Thu, 21 May 2015 21:50:24 GMT

Thứ Tư, ngày 25 tháng 11 năm 2015

Tutorial to create Drill Down Reports using Jasper Reports

Link demo: https://www.youtube.com/watch?v=w6fq1kdeElY
All in one images:
Step 1: open Hyperlink of a field in main report
Step 2: Select Link Target = Self   ;   Slect Link Type = ReportExecution
Step 3: Find on Target Report (DrillDown Report) two main input-parameters to open the report via link from main report. (in my case the drilldown report just need one parameter (requestID) and the Path will be got from Properties popup window of target report.


Now you can cook your linking report (main report) with all what I show here: