Set Up Proxy Environment Variables

Add the following one-liner at the end of .bashrc script:

export {http,https,ftp}_proxy='http://<user>:<password>@<proxy-server>:<port>'

For example: export {http,https,ftp}_proxy='http://10.0.2.2:3128'

For this to take effect, restart terminal or run source with . ~/.bashrc

After that, check for the presence of the environmental variables with printenv | grep proxy

yields the following output:

http_proxy=http://10.0.2.2:3128
ftp_proxy=http://10.0.2.2:3128
https_proxy=http://10.0.2.2:3128

GNU Emacs error on elementary OS

Problem: GNU Emacs-24 crashes at startup on elementary OS. This is due to incompatibility between the graphical toolkit used in the Emacs package.

X protocol error: BadMatch (invalid parameter attributes) on protocol request 139
When compiled with GTK, Emacs cannot recover from X disconnects.
This is a GTK bug: https://bugzilla.gnome.org/show_bug.cgi?id=85715
For details, see etc/PROBLEMS.
Fatal error 6: Aborted
Backtrace:
emacs[0x4f74cb]
emacs[0x4dcf3e]
emacs[0x4f7513]
emacs[0x4b219b]
emacs[0x4b420c]
emacs[0x4b426d]
/usr/lib/x86_64-linux-gnu/libX11.so.6(_XError+0x12b)[0x7f78f57b654b]
/usr/lib/x86_64-linux-gnu/libX11.so.6(+0x3b5e7)[0x7f78f57b35e7]
/usr/lib/x86_64-linux-gnu/libX11.so.6(+0x3b695)[0x7f78f57b3695]
/usr/lib/x86_64-linux-gnu/libX11.so.6(_XReply+0x1e8)[0x7f78f57b4578]
/usr/lib/x86_64-linux-gnu/libX11.so.6(+0x325e0)[0x7f78f57aa5e0]
...
Aborted (core dumped)

Solution: Setting the environment variable XLIB_SKIP_ARGB_VISUALS=1 allows Emacs to start. So use this command line to start Emacs in the terminal:

XLIB_SKIP_ARGB_VISUALS=1 emacs

Or better yet, create a launcher in ~/.local/share/applications by copying the emacs24.desktop file, and change the Exec line to

Exec=/usr/bin/env XLIB_SKIP_ARGB_VISUALS=1 /usr/bin/emacs24 %F

See [Adding Desktop Entries to System] for more information on desktop files.

Replace all empty character-fields in an MSSQL table with NULL

One good way is to build a dynamic SQL statement, and then run it with sp_executesql. The syntax of the sp_executesql statement is as follow: (See detail documentation of the statement on Microsoft Developer Network site)

sp_executesql [@stmt=] statement
[
  {, [@params=] N'@parameter_name data_type [OUT|OUTPUT][,...n]'} 
     {, [@param1=]'value1'[,...n]}
]
  1. Declare a unicode variable for the dynamic SQL statement:

    DECLARE @sSQL nvarchar(max) = ''
  2. Build your dynamic SQL statment.

    1. For example, if you wish to replace all empty character fields in table [myBlog] then the statement would be:

      SELECT
      @sSQL = @sSQL + 'UPDATE [' + TABLE_NAME + '] SET [' +
          COLUMN_NAME + '] = NULL WHERE ([' + COLUMN_NAME +
          '] = '''')' + CHAR(13)
      FROM INFORMATION_SCHEMA.COLUMNS
      WHERE (TABLE_NAME='myBlog') AND (DATA_TYPE LIKE '%char%')
      
    2. Or, if you wish to replace all of them in all the tables of the current database:

      SELECT
      @sSQL = @sSQL + 'UPDATE [' + TABLE_NAME + '] SET [' +
          COLUMN_NAME + '] = NULL WHERE ([' + COLUMN_NAME +
          '] = '''')' + CHAR(13)
      FROM INFORMATION_SCHEMA.COLUMNS
      WHERE (DATA_TYPE LIKE '%char%')
      
  3. Execute the dynamic SQL statement.

    EXEC sp_executesql @sSQL
    

SQL Server Logs

Reading the SQL Server error logs.

sp_readerrorlog

sp_readerrorlog is a stored procedure in the master database. It checks that the user is part of the securityadmin, then calls xp_readerrorlog. Header of the log gives server information and location of the log files.

Parameters
Order Type Description
1 int number of the log file. default is 0 for current file
2 int LogType, default 1. 1 = SQLServer logs, 2 = SQLAgent logs, 3 = full text logs
3 varchar(255) default NULL — search string for the log entry
4 varchar(255) default NULL — search string for the log entry
5 datetime from date-time
6 datetime to date-time
7 varchar Order, default to “ASC”. “ASC” or “DESC

Start a new error log

sp_cycle_errorlog

By default the number of logs is 7.