News for hackers. Stuff that matters.

jfhufl

Re:Regex character "$" doesn't mean "end-of-string" on Wednesday March 20, 2024 @12:21PM (#39768704)
Yep, makes sense, thanks!
Re:Regex character "$" doesn't mean "end-of-string" on Wednesday March 20, 2024 @12:05PM (#39768450)
Well, learned something today after reading a bit further in the thread:

    ruby -e 'x = "a\n25\n" ; if x =~ /^\d+$/ ; puts "yes" ; else ; puts "no" ; end'
    yes
Good to know.
Re:Regex character "$" doesn't mean "end-of-string" on Wednesday March 20, 2024 @12:00PM (#39768401)
Unsure what you mean?

    $ ruby -e 'x = "25" ; if x =~ /^\d+$/ ; puts "yes" ; else ; puts "no" ; end'
    yes
    $ ruby -e 'x = "25\n" ; if x =~ /^\d+$/ ; puts "yes" ; else ; puts "no" ; end' 
    yes
    $ ruby -e 'x = "a25\n" ; if x =~ /^\d+$/ ; puts "yes" ; else ; puts "no" ; end'
    no
Also, you'd want to use something that parameterizes the query with '?' (I use the Sequel gem) instead of just stuffing it into a sql string.
Re:The Eagle Obsession – Space: 1999 documentary on Friday February 23, 2024 @04:11PM (#39486151)
Dinky Toys!!! I had Eagles, ships from UFO, a Klingon ship...loved them!
Re:I think I need to go lie down on Thursday November 16, 2023 @03:39PM (#38295126)
Wow, I did something like that for my senior project back in '94 using Inventor on an SGI workstation.
If you still have IMAP access, thunderbird supports OAuth2 for connecting to O365 IMAP. tbsync for calendar access. Seems to work pretty well currently.
I think that's the major problem with software engineering in general: when is software "done" ?
Re:How I See Numbers on Thursday March 03, 2022 @07:07PM (#30548819)
I have Number-Form and Time-Space synesthesia - helps with remembering numbers and dates:

https://en.wikipedia.org/wiki/Number_form

https://www.discovermagazine.com/health/the-rare-humans-who-...

Re:The Curse of NixOS on Monday January 24, 2022 @06:13PM (#30065463)
Would Nix benefit from something like the old CMU depot program?

http://www.cs.cmu.edu/afs/.cs.cmu.edu/help/content/unix_linu...

Consolidating everything you want into /usr/local (exclude packages you don't want). I used to use this at my old job before package managers were ubiquitous.

Re:I Can’t See You but I’m Not Blind on Tuesday December 14, 2021 @12:20PM (#29554268)
Interesting - I may have hyperphantasia? Most of my thoughts are accompanied by images, and I can rotate and unfold things. It's so vivid I seem to have two types of synesthesia:

    https://en.wikipedia.org/wiki/Number_form
    https://www.discovermagazine.com/health/the-rare-humans-who-see-time-and-have-amazing-memories
Re:JWT Tokens are NOT safe on Thursday June 24, 2021 @09:39PM (#27626232)
Nothing is "secure or not" - technologies/mitigations are secure against particular attacks. HTTPS is generally secure against passive network eavesdropping, but does nothing to stop local file inclusion in a web app.

Just because there are attacks or ways around a particular defense doesn't mean it's worthless, that's why we have defense in depth.

Re:Escaping strings in Bash using !:q on Friday October 02, 2020 @01:37PM (#24664960)
This works too:

    % cat /tmp/sh
    var=variables
    x=$(
    cat <<EOT
    This string has 'single' and "double" quotes and can interpolate '$var'
    EOT
    )
    echo $x

    % bash /tmp/sh
    This string has 'single' and "double" quotes and can interpolate 'variables'
Re:Show HN: Ruby One-Liners Cookbook on Wednesday September 30, 2020 @12:31PM (#24640552)
I get a lot of mileage out of

    command | ruby -e 'ARGF.each { |line| #do stuff with line }'
Re:Cool but obscure X11 tools on Friday August 16, 2019 @10:43AM (#20715618)
xclip : https://github.com/astrand/xclip

    (long pipeline that generates lots of output) | xclip
Or even just

    xclip < /some/file
Now paste where necessary.
Re:Use mmap with care on Thursday May 02, 2019 @01:13PM (#19810085)
getmntent(3)
Re:For the Love of Pipes on Tuesday January 22, 2019 @10:45AM (#18969061)
Hmmm, well that's why I like Ruby and other languages with functional approaches. Method chaining and blocks are very similar to pipes to me.

    cat /etc/passwd | grep root | awk -F: '{print $3}'

    ruby -e 'puts File.read("/etc/passwd").lines.select { |line| line.match(/root/) }.first.split(":")[2]'
A little more verbose, but the idea is the same.

https://alvinalexander.com/scala/fp-book/how-functional-prog...

Re:How Space and Time Could Be a Quantum Error-Correcting Code on Thursday January 03, 2019 @02:43PM (#18818497)
The only reason I have any vague understanding of this article is all thanks to PBS Space Time on Youtube.

It's an amazing series. Must watch if you want to know how much we humans understand about our universe.

Reminds me of the organ banks in Niven's Known Space, Series. Governments made being sent to the "organ banks" the favored punishment for crimes. Also gave way to OrganLegging:

  https://en.wikipedia.org/wiki/Organlegging
Lovely.
Re:Ask HN: Best Command-Line Applications? on Sunday November 18, 2018 @10:30PM (#18484037)
Like so?

    % echo 'one\ntwo\nthree' | sed -e 's,$, four,'
    one four
    two four
    three four
Re:Study: Artificial sweeteners toxic to digestive gut bacteria on Thursday October 04, 2018 @11:15AM (#18140630)
I've found that stevia sweeteners with inulin (not insulin) seen to be beneficial for my gut bacteria. Actually seems to help with "loose days".

Sweetleaf is generally what I use.

Re:Fastcat – A Faster `cat` Implementation Using Splice on Wednesday August 01, 2018 @01:50PM (#17664967)
One good reason (IMO) for doing "cat file |" is it's easier to grab the command from your history and change it to something like "grep foo file |" rather than if you had run "cmd < file".
Funny, I love Ruby and it's my primary language of choice, but I'm a heretic, using braces whenever I can:

    # events per day
    ndbh.fetch('select ts from tbl').all.map { |row| 
        row[:ts]
    }.map { |t|
        t.strftime('%Y-%m-%d')
    }.each { |day|
        days[day] += 1
    }
(yes this could be conciser)

This is generally frowned on, and I'm sure everyone who likes having this style

   foo
     .map {}
     .select {}
     .blah {}
will frown as well, but it's so much more visually appealing to me, coming from a C/perl background when I first encountered Ruby (many years ago).

Funny how important syntax is. So easy to look at code in another style/language and go THATS NOT RIGHT!!

Re:The Forgotten Mystery of Inertia on Tuesday October 17, 2017 @11:35AM (#15491791)
Seems to me the main difference is that all the particles in the gyro are trying to go in a straight line, but can't due to being a part of a rigid structure. You should be able to tell the difference by dropping a ball bearing. It will land "straight down" if it's gravity, but move "to the side" if it's rotating.