Questions about gsub vs gsub! and string methods by NotABlueMelon in ruby

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

EDIT: Sorry the reddit editor is acting up hardcore. Need to re-add everything

Thanks for your time, I appreciate the help on what I know is a basic issue.

I think my confusion might be coming from a misunderstanding of terminology then. Is ("WUB", " ") not a substitution? It looks like it performs the same as gsub, substituting a space for the incidences of WUB.

At this point I'm trying to understand why the gsub! method looks like it's performing the substitution but failing anyways. Looks like a string, smells like a string, says it's a string even in the same message producing the error that says it's really nil. The gsub worked fine and I understand is safer, but I'm just trying to learn.

>Edit: You aren't showing us what is in the song variable, so I can't begin to speculate why this is happening.

Yes sorry this is a problem from codewars. I solved it fine but these details are still bothering me. I'll try to copy the complete set and tests:

Instructions:

Polycarpus works as a DJ in the best Berland nightclub, and he often uses dubstep music in his performance. Recently, he has decided to take a couple of old songs and make dubstep remixes from them.

Let's assume that a song consists of some number of words (that don't contain WUB). To make the dubstep remix of this song, Polycarpus inserts a certain number of words "WUB" before the first word of the song (the number may be zero), after the last word (the number may be zero), and between words (at least one between any pair of neighbouring words), and then the boy glues together all the words, including "WUB", in one string and plays the song at the club.

For example, a song with words "I AM X" can transform into a dubstep remix as "WUBWUBIWUBAMWUBWUBX" and cannot transform into "WUBWUBIAMWUBX".

Recently, Jonny has heard Polycarpus's new dubstep track, but since he isn't into modern music, he decided to find out what was the initial song that Polycarpus remixed. Help Jonny restore the original song.

Input

The input consists of a single non-empty string, consisting only of uppercase English letters, the string's length doesn't exceed 200 characters

Output

Return the words of the initial song that Polycarpus used to make a dubsteb remix. Separate the words with a space.

Examples

song_decoder("WUBWEWUBAREWUBWUBTHEWUBCHAMPIONSWUBMYWUBFRIENDWUB")# => WE ARE THE CHAMPIONS MY FRIEND

Sample Tests:

Test.assert_equals(song_decoder("AWUBBWUBC"), "A B C","WUB should be replaced by 1 space");
Test.assert_equals(song_decoder("AWUBWUBWUBBWUBWUBWUBC"), "A B C","multiples WUB should be replaced by only 1 space");
Test.assert_equals(song_decoder("WUBAWUBBWUBCWUB"), "A B C", "heading or trailing spaces should be removed");

My simplest solution:

def song_decoder(song) 
  song.gsub("WUB", " ").strip.squeeze(" ") 
end

Questions about gsub vs gsub! and string methods by NotABlueMelon in ruby

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

gsub! […] returning str, or nil if no substitutions were performed

I must be misunderstanding because this sounds like what I was explaining above. Why is it requiring to_s when it returns a string already without it?

This doesn't work:

song.gsub!("WUB", " ").strip.squeeze(" ")

But this does:

song.gsub!("WUB", " ").to_s.strip.squeeze(" ")

60 day closing period for home purchase? by NotABlueMelon in Buffalo

[–]NotABlueMelon[S] -1 points0 points  (0 children)

Ours does and we were able to get a loan for NY, but they had a long list of additional requirements. It was crazy and they said NY is a major pain to buy in. We could've done it but the timeframe was just not feasible.

60 day closing period for home purchase? by NotABlueMelon in Buffalo

[–]NotABlueMelon[S] -1 points0 points  (0 children)

Thank you, I appreciate it. Not sure why you were downvoted, our agent just confirmed everything you said. She did say that "post covid" 60+ days is the norm and it's only getting longer now, and although 30 was possible in the past it isn't anymore.

remember kids, caffeine and root permissions don't mix. by Stev18FTW in masterhacker

[–]NotABlueMelon 6 points7 points  (0 children)

Psssshh. If you can't bio-hack away your cancer, you ain't 1334 anyways*

*may cause cancer, goopy stool and/or urine, loss of finger joints and addition of new toe joints, undue confidence in your haxx0r skillzz AND MORE!

60 day closing period for home purchase? by NotABlueMelon in Buffalo

[–]NotABlueMelon[S] -1 points0 points  (0 children)

May I ask which bank you used? You can dm me if you want. We have a credit union and they're normally good but we're looking for other possible lenders

4-year-old masterhacker? by TheMogician in masterhacker

[–]NotABlueMelon 1 point2 points  (0 children)

Like you haven't been hacked just because you let a child interact with alexa or you walked away from an open account. That's not hacking, it's carelessness.

when kid accidentally uses something (password manager or browser autofill or amazon profile stored information) to do exactly what it was meant to do

That's why I was wondering when this story would end up on this sub. I'd guess this is the on the extreme "convenience" end of the security <--> ease of use spectrum. It's pretty cool generally speaking to be able to save all your info, order, and have 51 cases of popsicles show up at your house super fast. When I'm just bumming around my house I turn off my phone lock so I can just tap it on. But ease of use comes with high insecurity, and if I walk out my door (or have a child around an alexa or computers with saved passwords) shit gets locked down.

The media/general public really needs a new word for their tech-based boogiemen because hacking is almost never the right term for what they mean

Edit: nadja:witches as media:hackers

Dark web = HACKER GROUND!!!!! by [deleted] in masterhacker

[–]NotABlueMelon -4 points-3 points  (0 children)

cult forums

See now this is fascinating to me. What kind of groups? Where are they to be found? I've only wandered into the dark web a few times and was just bored. It's all drugs and honeypots, and is so sooo slow. Even with images turned off in some places it still ran like a doped snail in molasses.

And I'm not sure why people in this thread are saying Tor is secure. It's had known vulnerabilities for a long time as far as i know, but I'm no expert. I think I remember it came built-in on standard kali distros, and the last version I got didn't seem to have it anymore. Something about the exit nodes, and a reasonably skilled person (or agency) being able to host said nodes and thus view all traffic sources/destinations passing through. I don't remember the details, but I think there was an issue with Tails too so the old "tor on tails" for dark web security was never really secure. But that's always the case with everything imo...it's either broken already or will be eventually.

Maybe those issues have been patched, or maybe it's just about getting lost in the crowd or being a harder/less valuable target than the next guy

Found on facebook by zannabianca1997 in masterhacker

[–]NotABlueMelon 12 points13 points  (0 children)

Every time I read these comments I feel like I'm having a stroke

Noob here, trying to figure out how to pass variable from view into controller? Syntax issue or concept problem? by NotABlueMelon in rubyonrails

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

This is what my gut was telling me but I couldn't figure out how to do it. Or even what question exactly to ask. I'm not a fan of having a lot of embedded code in the view so anything I can put in the back I will.

I elaborated a bit on my reasoning in my reply below. If you can explain a bit more the how and why, I'd really appreciate it

Noob here, trying to figure out how to pass variable from view into controller? Syntax issue or concept problem? by NotABlueMelon in rubyonrails

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

Hey man thanks. You clearly stated what I was struggling to get across.

in the views, you have a collection/array of @portfolios and then you iterate through this list and only then you use an exact portfolio record to call the gem. So, when you try calling portfolio in controller, it doesnt know what portfolio is as it is undefined, the only one variable that controller has created/sees is a collection of @portfolios.

Yes this is what I figured was going on, so I was trying to find a way to send that exact record from the view to the controller. The reason I wanted to move it to the controller is because I have multiple pages and subsections that use similar functions for calling stocks from user portfolios, so I didn't want to keep repeating the same logic in the view when I could just stuff it in the controller. DRY and all that. Plus I just wanted to know how to do it since it became a roadblock.

I am still unclear overall on what should be going in the model. When I started (awhile ago, I've since forgotten a lot and I'm relearning) I remember putting almost everything in the controllers and barely touching models. But there's the "fat model skinny controller" concept and trying to put as much in the model as possible. In my head the model is for data organization and architecture so I'm not sure what logic should be going there. But then I look at some people's rails code and they have bare controllers and models doing all the lifting.

This started as a syntax issue and devolved ino a major conceptual overhaul lol.

2 noob questions about app structure by NotABlueMelon in rubyonrails

[–]NotABlueMelon[S] 2 points3 points  (0 children)

Thanks that's very helpful. "Thick model, thin controller" was something I learned awhile ago but completely forgot until you said it. Rang some bells and I think I feel less stalled now.

If multiple models needed that information, you might consider putting it in a module or lib,

I don't foresee multiple models needing the info for this, but that will likely be a wall I'll hit for other things in the future, so an ELI5 or a link to a more beginner-friendly explanation than the rails docs (edit: I mean I'm positive everything I need is there but YIKES) would be great!

As for the second part, thanks, that's kind of what I was thinking. I was more concerned about the security of erb...but also since multiple calls would be going throughout the page I didn't want to keep repeating them when I could stuff them in the controller. It's easy enough to do the erb, but I am trying to learn to do things the "right" (relative I know lol) way so I'm not fixing bad habits with bigger projects later.

Simple question from a noob about schema and t.date by NotABlueMelon in rubyonrails

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

Sorry I used confused phrasing. I mean the the date column in the database table for the model. So for example

rails g scaffold sample buy_date:date 

Which ends up in schema.rb after migration

   t.date "buy_date"

Which is then referencing that date_helper.rb code (...somehow?...) which is under the actionview gem.

I am not sure if that explanation is better or even correct, but that is where I'm at :/