Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
ulmont
Sep 15, 2010

IF I EVER MISS VOTING IN AN ELECTION (EVEN AMERICAN IDOL) ,OR HAVE UNPAID PARKING TICKETS, PLEASE TAKE AWAY MY FRANCHISE

prisoner of waffles posted:

tef or others, can you think of any others that might make the list?

https://www.mkssoftware.com/docs/man1/ls.1.asp

quote:

ls [-AabCcdFfghikLlmnopqRrstux1] [-timeout seconds] [-X attr] [pathname...]

Adbot
ADBOT LOVES YOU

VikingofRock
Aug 24, 2008




prisoner of waffles posted:

git has to be among the top 10 command line programs for sheer complexity of the possible valid command-line inputs.

tef or others, can you think of any others that might make the list?

find has a ton of options which I've seen used in fairly creative ways. sed always seems to have a bunch of interesting and obscure uses, too. And of course awk can be used for all kinds of things but that one might be cheating because awk is basically a full programming language.

bob dobbs is dead
Oct 8, 2017

I love peeps
Nap Ghost
isn't sed also turing-complete

e: yes
http://www.catonmat.net/blog/proof-that-sed-is-turing-complete/

looks like ls is actually not turing-complete, tho

mystes
May 31, 2006

NihilCredo posted:

yeah, we have f# and c# script files (actually f# scripting predates powershell by a year), they're way better than pshell for writing scripts longer than two lines.

all they really need is a decent sysdamin / web client / file munching library to be imported by default, and the c# / f# interpreters to be shipped by default with the runtime and imported into PATH by default

pshell should have focused entirely on being a modern replacement for cmd.exe with a focus on discoverability (check), consistency (meh) and usability (bleah)
It's funny because powershell has been very successful at achieving its goal of being a .net-based dynamically typed replacement for unix shells, and it's better than bash IMO, but basically the fundamental goal of trying to be like unix shells was misguided. It would have been so much less effort for them to try to make c# more suitable for the sort of thing people normally do using shell scripting and the result would have so much better.

akadajet posted:

people say this, but i've never seen anybody use f#
It's a nice language but you basically already have to know c# and ocaml to learn it, and Microsoft doesn't seem that serious about it so there are frequently issues with the tooling. It's sort of frustrating for these reasons, so in most cases it's easier just to use c#.

Finster Dexter
Oct 20, 2014

Beyond is Finster's mad vision of Earth transformed.
My favorite man git page used to be git-rebase, until they changed it.

quote:

git-rebase - Forward-port local commits to the updated upstream head

lmao that's like 90% git-specific jargon

VikingofRock
Aug 24, 2008





Neat! I actually think find is probably Turing complete too. The reason I specifically called out awk there because it was designed to be more of a full programming language than the other two. E.g. from the man page:

quote:

The awk utility shall execute programs written in the awk programming language, which is specialized for textual data manipulation.

mystes
May 31, 2006

Incidentally, I think one thing Powershell has really done a good job of proving is that piping objects between commands works much better than piping text. It's too bad there haven't been any serious efforts to make something like powershell but statically typed (for some reason it seems like whenever people try to make shell-like environments for other programming languages, they are determined to stick to piping around text whenever possible).

Finster Dexter
Oct 20, 2014

Beyond is Finster's mad vision of Earth transformed.

mystes posted:

Incidentally, I think one thing Powershell has really done a good job of proving is that piping objects between commands works much better than piping text. It's too bad there haven't been any serious efforts to make something like powershell but statically typed (for some reason it seems like whenever people try to make shell-like environments for other programming languages, they are determined to stick to piping around text whenever possible).

A static-typed shell env would own. That being said, wasn't the lovely WinFS sort of headed in that direction? IIRC, they were going towards an object-oriented file system and a statically typed scripting lang would've actually worked pretty well in that OOP hellscape.

Tangentially, I can't find the WinFS schema disgram, as it was a truly impressive example of enterprise software design. This blog post inadvertantly illustrates how bad this was:

https://blogs.msdn.microsoft.com/winfs/2005/09/08/visualizing-winfs-types/

Hunter2 Thompson
Feb 3, 2005

Ramrod XTreme
wondering if i can get some feedback on a recent phone interview

for the interview i wrote a moving average class.

it has a circular buffer where (assuming a full buffer) the oldest sample is overwritten as a new sample is written in:

code:
    void add_sample(double sample)
    {
        m_sum -= m_samples[m_write];
        m_sum += sample;
        m_samples[m_write++] = sample;
        m_write %= m_samples.size();
    }
    
    double get_average() const
    {
        return m_sum / m_samples.size();
    }
it seems to work alright

the interviewer also asked how to return the minimum-valued sample in the averaging window in < lg(n) time. I suggested keeping a binary search tree alongside the circular buffer and performing the same deletes/overwrites to it along with the array.

i'm not sure if that's a good answer now since i just read that "classic" binary search trees can't have duplicates. the interviewer also seemed to suggest that only a binary search tree was necessary to solve the problem (not both a buffer and tree), but i can't seem to figure out how that would work.

thoughts on the above? nothing like interviews to make you feel dumb

gonadic io
Feb 16, 2011

>>=
lots of static typed langs have a repl and a command api

DONT THREAD ON ME
Oct 1, 2002

by Nyc_Tattoo
Floss Finder
e: argh beaten ^

does anything meaningful differentiate what we think of as a shell from a language REPL?

animist
Aug 28, 2018
the rare good shitpost from r/programming: a PCRE regex that matches "A B C" where A+B=C

https://regex101.com/r/YCTmCs/3

Finster Dexter
Oct 20, 2014

Beyond is Finster's mad vision of Earth transformed.

DONT THREAD ON ME posted:

e: argh beaten ^

does anything meaningful differentiate what we think of as a shell from a language REPL?

In my mind, it should provide a simple interface to your host environment. REPLs don't really do that? I mean, you could argue that a REPL provides this, but in c#, for example, it takes multiple lines of code to start up a process and I wouldn't want to type System.Process.Start("turd --help") or whatever just to get help with the turd tool.

brand engager
Mar 23, 2011

hosed up that they called it detached head and not dullahan mode

FamDav
Mar 29, 2008

meatpotato posted:

wondering if i can get some feedback on a recent phone interview

for the interview i wrote a moving average class.

it has a circular buffer where (assuming a full buffer) the oldest sample is overwritten as a new sample is written in:

code:
    void add_sample(double sample)
    {
        m_sum -= m_samples[m_write];
        m_sum += sample;
        m_samples[m_write++] = sample;
        m_write %= m_samples.size();
    }
    
    double get_average() const
    {
        return m_sum / m_samples.size();
    }
it seems to work alright

the interviewer also asked how to return the minimum-valued sample in the averaging window in < lg(n) time. I suggested keeping a binary search tree alongside the circular buffer and performing the same deletes/overwrites to it along with the array.

i'm not sure if that's a good answer now since i just read that "classic" binary search trees can't have duplicates. the interviewer also seemed to suggest that only a binary search tree was necessary to solve the problem (not both a buffer and tree), but i can't seem to figure out how that would work.

thoughts on the above? nothing like interviews to make you feel dumb

you can make your BST and your buffer cotenant by either using the buffer as the backing storage for BST nodes or having your BST nodes include prev/next links to embed a doubly-linked list

since you're eating lg(n) inserts anyways you might as well use a min-heap to get worst-case lg(n) insert and constant-time minimum retrievals

Doom Mathematic
Sep 2, 2008

ulmont posted:

ls [-AabCcdFfghikLlmnopqRrstux1] [-timeout seconds] [-X attr] [pathname...]

It's the most remarkable word I've ever seen!

mystes
May 31, 2006

gonadic io posted:

lots of static typed langs have a repl and a command api
It's mostly an issue of ergonomics. It's pretty inconvenient to do simple shell-script like stuff in most languages. Powershell is cool because just poking around in directories, moving stuff, etc. is just as fast as in bash.

There are some repl environments for python that are sort of the right idea, but what I really want is something similar for a statically typed language that has good type inference. Also, I want proper tab completion in the shell. I'm not aware of anything right now that checks all these boxes.

I think c# could be made to work but I don't think the current repls are suitable right now.

anthonypants
May 6, 2007

by Nyc_Tattoo
Dinosaur Gum

animist posted:

the rare good shitpost from r/programming: a PCRE regex that matches "A B C" where A+B=C

https://regex101.com/r/YCTmCs/3
doesn't seem to match 0 1 1 or 1 0 1

DONT THREAD ON ME
Oct 1, 2002

by Nyc_Tattoo
Floss Finder

mystes posted:

It's mostly an issue of ergonomics. It's pretty inconvenient to do simple shell-script like stuff in most languages. Powershell is cool because just poking around in directories, moving stuff, etc. is just as fast as in bash.

There are some repl environments for python that are sort of the right idea, but what I really want is something similar for a statically typed language that has good type inference. Also, I want proper tab completion in the shell. I'm not aware of anything right now that checks all these boxes.

I think c# could be made to work but I don't think the current repls are suitable right now.

it would not be that difficult to design some sort of shell prelude that makes f#/haskell feel a lot like bash but with types.

might be kinda fun to try it in rust.

gonadic io
Feb 16, 2011

>>=

mystes posted:

It's mostly an issue of ergonomics. It's pretty inconvenient to do simple shell-script like stuff in most languages. Powershell is cool because just poking around in directories, moving stuff, etc. is just as fast as in bash.

There are some repl environments for python that are sort of the right idea, but what I really want is something similar for a statically typed language that has good type inference. Also, I want proper tab completion in the shell. I'm not aware of anything right now that checks all these boxes.

I think c# could be made to work but I don't think the current repls are suitable right now.

This is build with that in mind, tab completion would depend on your editor though as it's regular haskell types
http://www.haskellforall.com/2015/01/use-haskell-for-shell-scripting.html?m=1

VikingofRock
Aug 24, 2008




DONT THREAD ON ME posted:

it would not be that difficult to design some sort of shell prelude that makes f#/haskell feel a lot like bash but with types.

might be kinda fun to try it in rust.

It already exists: https://hackage.haskell.org/package/turtle

e: dammit gonadic io!

gonadic io
Feb 16, 2011

>>=
Or there's http://ammonite.io/ for scala

mystes
May 31, 2006

gonadic io posted:

This is build with that in mind, tab completion would depend on your editor though as it's regular haskell types
http://www.haskellforall.com/2015/01/use-haskell-for-shell-scripting.html?m=1
I haven't tried Turtle but it seems to just be oriented around running unix commands. I guess maybe I should try it because at the least that would make it easier to explain why it's not what I'm looking for.

gonadic io
Feb 16, 2011

>>=

mystes posted:

I haven't tried Turtle but it seems to just be oriented around running unix commands. I guess maybe I should try it because at the least that would make it easier to explain why it's not what I'm looking for.

1) what else do you want from a shell I'm confused
2) if you want to do text processing or something that's not running a single unix command you have all regular haskell functions at your fingertips

or did you mean windows? I'm not sure Gabriel is aware that windows exists no idea if it works there or not

gonadic io
Feb 16, 2011

>>=

VikingofRock posted:

e: dammit gonadic io!

don't test me on my monadic io

VikingofRock
Aug 24, 2008




mystes posted:

I haven't tried Turtle but it seems to just be oriented around running unix commands. I guess maybe I should try it because at the least that would make it easier to explain why it's not what I'm looking for.

It's more of a reimplementation of common unix commands' core functionalities, and instead of just doing text transformations it has Haskell's type system. So really I'd say it's less "Turtle is oriented around running unix commands" and more "Turtle often names its functions after similar Unix commands".

I've never used Turtle interactively as my main shell or anything, but I've used it to write what would have been medium-length shell scripts and it's pretty nice for that.

Hunter2 Thompson
Feb 3, 2005

Ramrod XTreme

FamDav posted:

you can make your BST and your buffer cotenant by either using the buffer as the backing storage for BST nodes or having your BST nodes include prev/next links to embed a doubly-linked list

since you're eating lg(n) inserts anyways you might as well use a min-heap to get worst-case lg(n) insert and constant-time minimum retrievals

drat, ive literally never thought about mingling different types of data structures like that. that's eye-opening stuff, thank you. maybe one day i won't be a terrible programmer.

just to make sure i understand, here's a breakdown of how i think each solution you mentioned could work. mind double-checking my understanding?

1. BST uses circular buffer as backing storage for its nodes
- use a classic 'bst_node' type containing left/right 'bst_node' pointers and a value
- circular buffer stores 'bst_node' types instead of naked values
- (assuming a full buffer) writes delete a node and insert a new node. bst property is enforced on deletes and inserts.
- time complexity typical case lg(n), but worst O(n) for find minimum, inserts and deletes.

2. BST nodes include prev/next links to embed a doubly-linked list
- No circular buffer involved, only using the modified bst now
- modified 'bst_node' type has a value and 'bst_node' pointers for left, right, prev, next
- keep list head and tail pointers
- (assuming number of stored nodes is equal to the window size) add_sample drops the list head, appends to the tail. bst property enforced on inserts and deletes.
- time complexity typical case lg(n), but worst O(n) for find minimum, inserts and deletes.

3. use a min-heap
- Similar to #2 but using a min-heap embedding a doubly-linked list instead of a BST embedding a doubly-linked list
- Constant-time minimum lookups, average constant-time inserts and deletes, worst-case lg(n) inserts and deletes.

gonadic io
Feb 16, 2011

>>=

meatpotato posted:

drat, ive literally never thought about mingling different types of data structures like that. that's eye-opening stuff, thank you. maybe one day i won't be a terrible programmer.

not to belittle the rest of your point but people that know these datastructure/interview tricks are still terrible programmers like the rest of us. some of this stuff took 10+ years for researchers to figure out and you can onyl really do it if you knew in advance so people that ask this in interviews are terrible too unless youre job is to write an actual compiler stdlib.

good interviews questions are stuff like: client asks for x give me a minimal working implementation here's your ide and your google let's pair.

Hunter2 Thompson
Feb 3, 2005

Ramrod XTreme

gonadic io posted:

not to belittle the rest of your point but people that know these datastructure/interview tricks are still terrible programmers like the rest of us. some of this stuff took 10+ years for researchers to figure out and you can onyl really do it if you knew in advance so people that ask this in interviews are terrible too unless youre job is to write an actual compiler stdlib.

good interviews questions are stuff like: client asks for x give me a minimal working implementation here's your ide and your google let's pair.

oh, for sure --i slaved for four years in the code mines gluing simple pieces of code together and did an okay job at it without using much of anything from a data structures and algorithms class

i unironically got excited when i realized you could embed two data structures to order/arrange the same data in memory different in ways. it should have been obvious, but like you said, a lot of this stuff took decades to figure out. i think it's good to feel some occasional enjoyment from this interview prep poo poo because a lot of it is boring as gently caress

gonadic io
Feb 16, 2011

>>=

meatpotato posted:

i think it's good to feel some occasional enjoyment from this interview prep poo poo because a lot of it is boring as gently caress

yes I agree I enjoy programming lots and it's great when people get excited about stuff I didn't mean to harsh your "this is neat" buzz

MononcQc
May 29, 2007

I am a user who always used hg but has been forced to use git out of tiredness of assholes asking to migrate all the things to git and github. It ended up being easier to to just switch than use software I like and think is good because of network effects and it is loving bad

also the command I can never use without doc is any of 'find' or 'tar' (if tar -xvf <tar.gz file> won't cut it)


E: I use find * | grep <pattern I am looking for>

Lime
Jul 20, 2004

meatpotato posted:

3. use a min-heap
- Similar to #2 but using a min-heap embedding a doubly-linked list instead of a BST embedding a doubly-linked list
- Constant-time minimum lookups, average constant-time inserts and deletes, worst-case lg(n) inserts and deletes.

since you only add and remove samples from the ends of the embedded list, you can use singly-linked nodes and just keep two pointers for head and tail outside the min-heap

Hunter2 Thompson
Feb 3, 2005

Ramrod XTreme
ah, that's true for #2, using a linked-list embedded in a BST, as well, isn't it?

Lime
Jul 20, 2004

oh yeah for sure

DONT THREAD ON ME
Oct 1, 2002

by Nyc_Tattoo
Floss Finder
man that's such a hard problem for an interview imo. i mean, give me a few hours and some loving space and i'll work through it and come up with a good solution but there's no way i'd get through that under pressure.

bob dobbs is dead
Oct 8, 2017

I love peeps
Nap Ghost

MononcQc posted:

I am a user who always used hg but has been forced to use git out of tiredness of assholes asking to migrate all the things to git and github. It ended up being easier to to just switch than use software I like and think is good because of network effects and it is loving bad

also the command I can never use without doc is any of 'find' or 'tar' (if tar -xvf <tar.gz file> won't cut it)


E: I use find * | grep <pattern I am looking for>

ack-grep, silver surfer (ag-grep), ripgrep

pick one (ripgrep is your default, it's fastest)

tar is kind of a pain

bob dobbs is dead fucked around with this message at 22:12 on Sep 5, 2018

mystes
May 31, 2006

OK, I tried turtle.

Finding the total size of the most recent 5 files in powershell and turtle (admittedly I suck at haskell so the haskell version is probably not the best solution).

Powershell:
code:
dir | Sort-Object -Descending -Property LastWriteTime | select -first 5| Measure-Object -Property length -sum | select -expand sum
Turtle:
code:
{-# LANGUAGE OverloadedStrings #-}

import Turtle

import qualified Control.Foldl as Fold
import Data.List

toList :: MonadIO io => Shell a -> io [a]
toList s = fold s Fold.list

getStat x = (\y -> (x, y)) <$> (stat x)

compareFiles (x, y) (x', y') = compare (modificationTime y') (modificationTime y)

main :: IO()
main = do
    l <- toList (ls ".")
    l2 <- sequence (map getStat l)
    let l3 = take 5 (sortBy compareFiles l2)
    let sizes = map (\(x, y) -> fileSize y) l3
    print (sum sizes)
I don't think I'm going to use turtle as my normal shell for simple scripting any time soon.

Shaggar
Apr 26, 2006
What i want wrt powershell is linq syntax. something like (dir).OrderByDescending(i=>i.LastWriteTime).Take(5).Sum(i=>i.length)

suffix
Jul 27, 2013

Wheeee!

meatpotato posted:

wondering if i can get some feedback on a recent phone interview

for the interview i wrote a moving average class.

it has a circular buffer where (assuming a full buffer) the oldest sample is overwritten as a new sample is written in:

code:
    void add_sample(double sample)
    {
        m_sum -= m_samples[m_write];
        m_sum += sample;
        m_samples[m_write++] = sample;
        m_write %= m_samples.size();
    }
    
    double get_average() const
    {
        return m_sum / m_samples.size();
    }
it seems to work alright

the interviewer also asked how to return the minimum-valued sample in the averaging window in < lg(n) time. I suggested keeping a binary search tree alongside the circular buffer and performing the same deletes/overwrites to it along with the array.

i'm not sure if that's a good answer now since i just read that "classic" binary search trees can't have duplicates. the interviewer also seemed to suggest that only a binary search tree was necessary to solve the problem (not both a buffer and tree), but i can't seem to figure out how that would work.

thoughts on the above? nothing like interviews to make you feel dumb

decent answers imo

you could keep a range minimum query table updated with ln(n) time per insertion, not too hard to code in c

for o(1):
keep a double-ended queue of (position, value) pairs that will have two invariants
- from oldest to newest value
- from lowest to highest value
when you insert a new sample
- pop the oldest sample off the start if it's too old
- pop all values bigger than this value off the end - they will drop off before the new value, so they can never be the minimum
- insert the new value

id visualize it by considering the two cases of always-increasing and always-decreasing samples -
for always-decreasing we can just throw away the old samples, for always-increasing we need to keep them stacked away until it's their time to be the minimum

Adbot
ADBOT LOVES YOU

eschaton
Mar 7, 2007

Don't you just hate when you wind up in a store with people who are in a socioeconomic class that is pretty obviously about two levels lower than your own?

Finster Dexter posted:

My favorite man git page used to be git-rebase, until they changed it.


lmao that's like 90% git-specific jargon

git-start-stash is pretty good:

quote:

start any non-forward-ported upstream stashes to various annotated non-named local indices

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply