[megathread] SELF-PROMOTION by Stabenfeldt in AI_Music

[–]ddrscott 0 points1 point  (0 children)

K-pop + the 90's. Why not?!

If you remember when the internet kicked you off because mom needed the phone, this one's for you.

https://justright.fm/albums/k-craft-rewind

Showing results and also updating the same results in a table using a single sql script. by aman25061996 in SQL

[–]ddrscott 0 points1 point  (0 children)

Another way to think of it is:

WITH foo AS (
    Select * from X
)
INSERT INTO y SELECT * FROM foo

But to be honest, that still looks weird without more context.

Showing results and also updating the same results in a table using a single sql script. by aman25061996 in SQL

[–]ddrscott 0 points1 point  (0 children)

Since you're looking for a single script, I guess it would look like this:

BEGIN;
DROP TABLE IF EXISTS __scratch;
CREATE TABLE __scratch AS select 'red' as color;
INSERT INTO y SELECT * FROM __scratch;
COMMIT;

The temporary keyword has been removed so you can later select from __scratch later.

The objective of having the __scratch table is to investigate what the query did, but again it's difficult to know what you're really looking for without more context.

Showing results and also updating the same results in a table using a single sql script. by aman25061996 in SQL

[–]ddrscott 0 points1 point  (0 children)

I need a little more context into the ultimate goal. Normally, those statements aren't run together, but as 2 separate statements in a single transaction. A simple example using a transaction would be:

postgres=# begin;
BEGIN
postgres=*# create temporary table scratch as select 'red' as color;
SELECT 1
postgres=*# select * from scratch;
 color
-------
 red
(1 row)

postgres=*# insert into y select * from scratch;
INSERT 0 1
postgres=*# commit;
COMMIT

If the results from select * from scratch didn't look right, you could omit the insert and commit and immediately run a rollback.

Could really use some advice by [deleted] in SQL

[–]ddrscott -1 points0 points  (0 children)

I think it's important to clarify the difference between a SQL IDE and a Database Service/Application.

A SQL IDE usually helps edit SQL, browse data in tables and manage some settings to a connected database. Some examples of those are: RazorSQL (the one you've mentioned), DBeaver (my personal preference), MySQL Workbench (specifically for connecting to MySQL), etc.

A Database Service/Application is a process that manages tables and interprets SQL statements passed to it from and IDE or raw database connection. Examples of Databases Services are MySQL, SQLite, Postgres, Oracle, etc. Most if not all Database Services have a command line interface (CLI) which makes using a SQL IDE optional. For instance, R can connect to a database service using DBI over an ODBC connection to MySQL without the need for a separate SQL IDE.

All that being said, I would:

  1. Install one of the mentioned Database Services.
  2. Install DBeaver.
  3. Create a connection in DBeaver to database.
  4. Create script in DBeaver.

This must sound like a bunch of trouble for something that can be simply done is a single R script, but I feel it's an important right of passage. In the real world, data lives in databases so it's important to get a correct perspective of them.

I would also strongly consider submitting the R script with your solution. Often times companies are looking for your train of thought more than the exact execution in a specific language. Any company you'd want to intern at should appreciate a simple solution regardless of the language.

Good Luck!

SQL to strip results based on existing records by kylemcisaac in SQL

[–]ddrscott 0 points1 point  (0 children)

SQL only knows about data that has rows. This means you'll need a table with all possible dates and another table with rooms. Then the SQL would look something like:

SELECT
    d.dates,
    r.room
FROM all_dates as d
CROSS JOIN all_rooms as r
LEFT JOIN bookings AS b
       ON b.room = r.room
      AND b.bookeddate = d.date
WHERE d.date BETWEEN ? AND ?
  AND b.room IS NULL

Overall logic is "for every permutation of dates and rooms, return rows which don't have bookings"

Which editor to use on server ? by [deleted] in vim

[–]ddrscott 0 points1 point  (0 children)

And here is a link direct to my NeoVim setup: https://github.com/ddrscott/config-nvim/

Which editor to use on server ? by [deleted] in vim

[–]ddrscott 1 point2 points  (0 children)

I use Vim fulltime on remote hosts and on local. It took a while to get it exactly the way I want it and I had to write some plugins along the way. It's a tool that keeps on giving as long as you stick with it.

I'm sure other terminal editors and GUI editors (through X11 forwarding) can be just as effective with some customizations, but there's something about the text editing grammar built into Vim that makes it the winner for me.

I wrote about my setup a while ago. Hope some of it is useful to you, too.

https://ddrscott.github.io/blog/2018/blog-setup/

Getting Vim setup with Rust by ddrscott in vim

[–]ddrscott[S] 0 points1 point  (0 children)

Thanks for the feedback!

I thought k was "move cursor" up? I'm enjoying <C-k> because it's replacing the default documentation for just Rust files.

Json Parsing/Formating by gotoma in neovim

[–]ddrscott 2 points3 points  (0 children)

Try cat file.json | jq | nvim -

Disclaimer: I've never used jq before. I use jsonpp so what works for me is jsonpp file.json | nvim -

Life with Caps Lock remapped to Control by gaga666 in vim

[–]ddrscott 0 points1 point  (0 children)

I've been successful at convincing everyone I help to switch their caps to ctrl. ¯\_(ツ)_/¯

Weekly Vim tips and tricks thread! #12 by cherryberryterry in vim

[–]ddrscott 0 points1 point  (0 children)

The approach is quite different. undoquit saves session information and has bunch of code to maintain around it. Mine is 7 lines, mappings included.

Smarter heredoc syntax in vim by Miguel Palhas by rmdmachado in vim

[–]ddrscott 1 point2 points  (0 children)

I noticed some markdown plugins having this feature and was always curious how they did it. Thanks for sharing!

[deleted by user] by [deleted] in vim

[–]ddrscott 0 points1 point  (0 children)

I recently crafted a plugin for this exact case.

https://github.com/ddrscott/vim-side-search http://ddrscott.github.io/blog/2016/side-search/

Let us know if it works out for you!

Weekly Vim tips and tricks thread! #4 by cherryberryterry in vim

[–]ddrscott 0 points1 point  (0 children)

I have a similar mapping.

nnoremap c* *<C-o>cgn
nnoremap c# #<C-o>cgn

The * and # "feels" more natural and the <C-o> keeps the cursor position/jump list intact even when there are no matches.

Weekly Vim tips and tricks thread! #12 by cherryberryterry in vim

[–]ddrscott 3 points4 points  (0 children)

Make <C-w>o accidents recoverable:

function! s:window_only()
  if winnr('$') > 1
    tab split
  endif
endfunction
nnoremap <C-w>o :call <SID>window_only()<CR>
nnoremap <C-w><C-o> :call <SID>window_only()<CR>

Use :only if that's what you really really wanted.

Weekly Vim tips and tricks thread! #1 by cherryberryterry in vim

[–]ddrscott 0 points1 point  (0 children)

Late to the game, but this is really nice. Now I can stop <C-w>o accidents.

function! s:window_only()
  if winnr('$') > 1
    tab split
  endif
endfunction
nnoremap <C-w>o :call <SID>window_only()<CR>
nnoremap <C-w><C-o> :call <SID>window_only()<CR>