Pokazywanie postów oznaczonych etykietą tool. Pokaż wszystkie posty
Pokazywanie postów oznaczonych etykietą tool. Pokaż wszystkie posty

wtorek, 19 maja 2020

The Shortest FOSS (Free / Open Source Software) License

Now and then, you may be wondering what is the shortest and simplest possible Open Source license.  Maybe you are contributing some Free Software to the world for your fun, glory and profit, and you want to save precious bytes in your project directory?

The Software Package Data Exchange® (SPDX®) publishes a list of (probably all) Open Source licenses. The page specifies license name, codename, full text, whether it's approved by Open Source Institute and whether it's recognized by the Free Software Foundation as Free/Libre license.

I was curious which one is the most terse, and I wrote a little Python script to scrape the data from SPDX page, parse it and save to CSV.

The script is here: spdx_licenses.py.

Here are the winners.

1. The shortest Open Source license is the diffmark license - it's only 17 words and 88 characters long, but it's neither FSF-approved nor OSI-approved. Personally, I love it. The credits for license text should probably go to Václav Bárta (http://www.mangrove.cz/diffmark/). Use it if you are brave. Quoting in full:
1. you can do what you want with it 2. I refuse any responsibility for the consequences
2. The shortest FSF-approved Open Source license is the FSF All Permissive License. It is 34 words, 224 characters long. Quote:
Copying and distribution of this file, with or without modification, are permitted in any medium without royalty provided the copyright notice and this notice are preserved. This file is offered as-is, without any warranty.
3. The shortest OSI-approved Open Source license is the Fair License. It is 36 words, 229 characters long. Quote:
<Copyright Information> Usage of the works is permitted provided that this instrument is retained with the works, so that any entity that uses the works is notified of this instrument. DISCLAIMER: THE WORKS ARE WITHOUT WARRANTY.
4. The shortest Open Source license which is both FSF-approved and OSI Approved is the ISC License. It is 128 words, 819 characters long. Use it to get your back covered against most lawyers. Quoting:
ISC License Copyright (c) 2004-2010 by Internet Systems Consortium, Inc. ("ISC") Copyright (c) 1995-2003 by Internet Software Consortium Permission to use, copy, modify, and /or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

You may also wonder about the losers. Unsurprisingly, one of the longest licenses is the famous GNU General Public License v3.0 (over 5650 words, 38000 characters) - but it's  beaten by the Adaptive Public License 1.0 which is over 7100 words, 52500 characters! Whoa - pretty long for a free software license.

czwartek, 4 października 2018

Linux, SQLCMD and Vim

Hello everyone!

If you came here you probably already know what is SQL Server SQLCMD utility, and you also know (and either love or hate) the Vim text editor.

Of course, nobody with senses would use the SQLCMD for day-to-day work on Windows (we have GUIs. Management Studio etc).

Yes - I'm one of those guys who stick to GNU/Linux operating system and generally prefer command line interface (CLI) over GUIs.

So let's briefly explain the problem that I had:

SQLCMD interactive mode works (kudos to MS, you can create a working Unix program!), but on the output side, it does not have any paging / text formatting capabilities. It also does not shine on input side, ignoring one of best inventions of the GNU/Linux world which is the readline library.

Basically, this means that working with SQLCMD in interactive mode for anything serious is a mistake. Authoring SQL or reading SQL output is too inconvenient, unless all your queries look like this.

SELECT oneoneone=1, two=3
GO

So, the process to edit any complex SQL query in your CLI text editor is

  1. write your SQL query
  2. save the SQL file
  3. run the SQL file in sqlcmd, either interactive mode (using the :r macro) or batch mode (using the "-i" option).
  4. try to browse through the output on screen
  5. decide that output is too wide, line wrapping makes it unreadable and switch to  "-o" for output
  6. open the output file in any decent text pager / editor (like vim or less)
  7. Inspect the results. Go back to point 1.
Naturally, you could automate it using a bash script, along the lines of

/opt/mssql-tools/bin/sqlcmd <other options> -i my.sql | less


But my goal was to reduce development loop to this:
  1. write your SQL query
  2. run the SQL and see output in any decent text pager / editor
  3. Inspect the results. Go back to point 1.
Long story short - here is the solution for Vim, you can add it to your .vimrc and see for yourself.

Usage: While editing SQL file in normal mode, press letter M on the keyboard and query is executed over SQLCMD and its results appear in bottom window pane.

function! RunBufferInSQLCMD()
  let s:file = expand('%:p')
  if strlen(s:file) > 0
    silent write
    let s:sqlcmd = '/opt/mssql-tools/bin/sqlcmd'
    let s:sqlsrv = 'your.database.windows.net'
    let s:sqldb = 'YourDB'
    let s:sqlusr = 'bobadmin@yours'
    let s:sqlpwd = 'ehkm'
    let s:ofile = substitute(system('mktemp'),"\n",'','')
    let s:mycmd = s:sqlcmd
                  \ . ' -S "' . s:sqlsrv
                  \ . '" -d "' . s:sqldb
                  \ . '" -U "' . s:sqlusr
                  \ . '" -P "' . s:sqlpwd
                  \ . '" -i "' . s:file
                  \ . '" -o "' . s:ofile
                  \ . '"'
    let s:myoutput = system(s:mycmd)
    if strlen(s:myoutput) > 0
      echoerr 'Command output: ' . s:myoutput
    endif
    execute 'silent rightbelow split ' . s:ofile
  else
    echoerr 'Not a file!'
  endif
endfunction

map M :call RunBufferInSQLCMD()<cr>



That's it for today. Nice Vimming!


wtorek, 25 września 2018

pg_terminator: tiny utility for PostgreSQL DBAs

Hello everyone!

depesz just released a new useful tool, pg_terminator
 
I believe it will be useful in Pg DBA's toolbox.

It requires just Ruby, and ruby-pg gem.

You run it like this:

$ pg_terminator etc/pg_terminator/webdb.yaml

and the yaml config looks like this:

log: /tmp/pg_terminator.webdb.log
min_sleep: 1
database:
  dbname: webdb

  host: webdbsrv1
rules:

- name: long-webapp-txn
  action: transaction
  threshold: 180
  type: transaction
  condition: application_name ~ 'webapp' and state <> 'idle'



Here is an example of pg_terminator in action:
 2018-09-25 13:01:27 Sleeping for 20 seconds
2018-09-25 13:01:47 Sleeping for 20 seconds
2018-09-25 13:02:07 Sleeping for 15.0 seconds
2018-09-25 13:02:22 Terminated a query (pid: 2242) because of rule #1: long-txn
2018-09-25 13:02:22 Sleeping for 37.987898 seconds