News for hackers. Stuff that matters.
Re:Suicide Linux by kingvash on Thursday October 26, 2017 @05:20PM (#15563117)
I've added a counter (of successful commands in a row) to my bashrc. I've seen it as high as 120.

  function promptCommand()
  {
    LAST_STATUS=$?
    # Set title of window to dir, then add new line to prompt.
    PS1='\[\e]0;\w\a\]\n'
    if [ $LAST_STATUS -eq 0 ]; then
      ((successes++))
      PS1+='\[\033[1;32m\][$successes]'
    else
      successes=0
      PS1+='\[\033[1;31m\][0 $LAST_STATUS]'
    fi  
    PS1+='\[\033[0;32m\] '
    PS1+='\w $(date +%H:%M) \$ \[\033[0m\]'
  }

  lastStatus=0
  successes=-1
  PROMPT_COMMAND="promptCommand"
My prompt:

  [0] /home/bar/g3 14:19 $ echo "boo"
  boo

  [1] /home/bar/g3 14:19 $
Re:Suicide Linux by kedean on Thursday October 26, 2017 @06:48PM (#15563916)
Man, I hope you don't use grep very often (by default it uses exit code 1 when it doesn't find anything).
Re:Suicide Linux by function_seven on Thursday October 26, 2017 @08:10PM (#15564444)
If it didn't exist in the first place, then you had no business searching for it. You should have just known not to look. :)
Re:Suicide Linux by Lio on Friday October 27, 2017 @04:27AM (#15566609)
I like this joke, it kind of reminds me of the difference between `find_by_id` and `find` in ruby on rails.

In the former, if a result can't be found it will return `nil` but in the latter it expects the record to exist and so will raise an exception if it can't be found.

Re:Suicide Linux by rusk on Friday October 27, 2017 @05:45AM (#15566930)
Python: `Dict.get(k)` (`null`) vs `Dict[k]` (`IndexError`)
Re:Suicide Linux by philsnow on Friday October 27, 2017 @11:17AM (#15569200)
that sounds so backwards. `find_by_id` is a lookup, not a search; it seems implied to me that the ID should exist and if it doesn't that's an exception. Whereas `find` is a search and it's not atypical for search results to be empty.
Re:Suicide Linux by rapind on Friday October 27, 2017 @01:59PM (#15570733)
Since I think rails 4 or earlier it's preferred to use `find_by(id: 4)`, but could instead be `find_by(email: "[email protected]")`, or even `find_by(first_name: "Franky', last_name: "Tomato")`.

IMO returning nil instead of an exception for the above is practical for me. Much easier to work with.

Having `find(4)` raising an exception is because you'll typical use it in your member actions for a controller where it's reasonable to want an exception if something can't be found.

It's just Rails being Rails (practical sometimes at the expense of possible interpretation of correctness). You do have to retain stuff like this in your head, but it becomes habit pretty quickly.

Re:Suicide Linux by maxscam on Tuesday October 31, 2017 @02:02AM (#15591377)
This begs the question of what the hell is the point of the bang convention e.g. find! in this case.
Re:Suicide Linux by rapind on Tuesday October 31, 2017 @11:58PM (#15598707)
I've never seen `find!`. If that's a thing, then I have no idea why.

I've have found `find_by!` useful though. Say you want to raise an exception with `find_by!(email: "[email protected]")` or `find_by!(slug: "parameterized-string")` etc.

Re:Suicide Linux by Shorel on Friday October 27, 2017 @05:18AM (#15566830)
I've heard that joke once, but in C++
Re:Suicide Linux by friendzis on Friday October 27, 2017 @12:53AM (#15565801)
Negative result is still a result. I sometimes use `grep -r` to check whether "does this set of files contain this particular string?" and "no" is a useful answer :)
Re:Suicide Linux by prginthebox on Friday October 27, 2017 @04:07AM (#15566534)
twas a joke.
Re:Suicide Linux by mortehu on Thursday October 26, 2017 @07:41PM (#15564258)
Just pipe the output through cat. By default, the "pipefail" option is not set, so

    echo foo | grep bar | cat
is successful. Of course, this works for any command.
Re:Suicide Linux by nerdponx on Thursday October 26, 2017 @08:22PM (#15564515)
Alternatively and less wastefully:

    echo foo | grep bar || true
Re:Suicide Linux by teddyh on Thursday October 26, 2017 @09:22PM (#15564834)
Alternatively and shorter:

    echo foo | grep bar || :
Re:Suicide Linux by omginternets on Friday October 27, 2017 @06:36AM (#15567133)
>grep

Not to mention tar which is just impossible to get right on the first try.

Re:Suicide Linux by Yizahi on Friday October 27, 2017 @09:48AM (#15568194)
Especially when disarming a nuke
Re:Suicide Linux by nobodyorother on Friday October 27, 2017 @10:47AM (#15568857)
Nuke-practice is why I only use tar these days.
Re:Suicide Linux by 0xJRS on Friday October 27, 2017 @11:14AM (#15569168)
>cheat tar
Re:Suicide Linux by bohinjc on Friday October 27, 2017 @12:06PM (#15569706)
This reminds me about https://www.xkcd.com/1168/
Re:Suicide Linux by craftyguy on Friday October 27, 2017 @02:33AM (#15566189)
just add a '|| true' at the end of every call to grep!
Re:Suicide Linux by anon335dtzbvc on Friday October 27, 2017 @04:30AM (#15566621)
just add a '|| true' at the end of every call!
Re:Suicide Linux by mondoshawan on Friday October 27, 2017 @10:35AM (#15568720)
If you're looking for just mistypes, use status 128.