Skip to content

Instantly share code, notes, and snippets.

@thatrubylove
Created May 21, 2015 08:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thatrubylove/69380eecf75b8faed96f to your computer and use it in GitHub Desktop.
Save thatrubylove/69380eecf75b8faed96f to your computer and use it in GitHub Desktop.
Here is the TLDR version:
<sevenseacat> rubycasts_io_: welcome back.
...
<rickjamesthethir> I have this dictionary and i need to do 2 things. separate into words/sequences and then check to make sure that if a sequence is a duplicate then it never gets outputted in the final output
...
<rubycasts_io_> rickjamesthethir, looks like a job for each_cons :D
<rickjamesthethir> problem is this dictionary is 25,000 words. It's super slow to run an array.each {|x| *searching for duplicate in the same big array* }
<rubycasts_io_> rickjamesthethir, use ruby 2+ and use .lazy
...
<Radar> rubycasts_io_: example? :)
<rickjamesthethir> so if I take each part of the 25,000 array and then search for duplicates in the same 25,000 array well thats 25,000 * 25,000 0.0
...
<rickjamesthethir> let me google .lazy
<rubycasts_io_> rickjamesthethir, you also might want to split the list in half ie, binary search
...
<rubycasts_io_> Radar, long time no see (since I havent been on since 2009 or so)
<Radar> rubycasts_io_: indeed :)
<Radar> rubycasts_io_: What was your original name?
<rubycasts_io_> Radar, have you gotten you rubyhero award yet?
<Radar> rubycasts_io_: 2012
<rubycasts_io_> good, you needed it :)
...
<rubycasts_io_> peimei
..
<rubycasts_io_> railsjistsu dreamr
<Radar> I don't remember that name :(
<rubycasts_io_> i had a lot
<rubycasts_io_> im a re-brander
...
<Radar> dreamr? but not Dreamer3?
<rubycasts_io_> nope, he is dif
<Radar> Confusing.
...
<rubycasts_io_> :D
<rubycasts_io_> rubycasts_io_ is much more direct ;)
<Dreamer3> more direct than me?
<Dreamer3> doubtful
<rubycasts_io_> lol
<rubycasts_io_> long time on you too.
...
<rubycasts_io_> it fees very 2008 in here, I love it
...
<rubycasts_io_> rickjamesthethir, also you can import that into SQL first and then use SQL to work the dupes :D
<sandelius> is there a list with reserved column names somewhere?
<rubycasts_io_> rickjamesthethir, if it were me I would probably go that route as it is much better on memory and speed
<Radar> sandelius: "type"
<rubycasts_io_> and I dig sql
<Radar> end of list? :)
<Radar> goodnight folks
<sandelius> Radar ahh nice :)
<rubycasts_io_> night Radar
...
<rubycasts_io_> you know, as many times as I fought with guys like dhh and zenspider (usually on the side of zed or benhardt) it is kind of nice to not be known anymore :D
<sandelius> Radar well how about validate, save etc?
<rubycasts_io_> sandelius, as column names? in the db or in rails?
<rubycasts_io_> attrs in rails shouldnt match existing activerecord method names :)\
...
<sandelius> rubycasts_io_ column names that would make ActiveRecord punch me hard :)
...
<sevenseacat> `type` is the main one to watch out for.
<rubycasts_io_> here is how you get that list
<rubycasts_io_> ActiveRecord::Base.instance_methods
<sevenseacat> thats reserved for polymorphic associations.
<rubycasts_io_> yes, type is STI
<rubycasts_io_> single table inheritance
<sevenseacat> STI, sorry.
<nikamura> Hi, how would i go on permitting https://gist.github.com/Nikamura/962c449577079e8a0d3d there params
<nikamura> params.require(:tags).permit ???
<rubycasts_io_> nikamura, since the keys are dynamic you need something like
...
<rubycasts_io_> params.require(:tags).permit!
...
<rubycasts_io_> which I dont like because it is dangerous
<sevenseacat> how are they dynamic?
<nikamura> yeah, but we use brakeman which throughs an error
<rubycasts_io_> 1
<rubycasts_io_> 10
<rubycasts_io_> 15
<rubycasts_io_> those are not static keys
<rubycasts_io_> they are indices
<nikamura> it’s an id of an item
<sevenseacat> indeed, and the strong parameters syntax allows for that.
<rubycasts_io_> which is dynamic
<sevenseacat> looking it up now
...
<rubycasts_io_> nikamura, then you need to put tags into a root key
<rubycasts_io_> nikamura, something: {tags:[]}
<rubycasts_io_> so that you can permit on the array syntax of tags
<rubycasts_io_> if tags is in the require you cant, if it is in the permit you can
<sevenseacat> http://guides.rubyonrails.org/action_controller_overview.html#strong-parameters see 4.5.2
<rubycasts_io_> yes but that is in the permit not the require
<sevenseacat> also, the last example of 4.5.3.
<rubycasts_io_> which is what I said :)
<rubycasts_io_> in the require it cant be an array or you have to permit all sub keys
<sevenseacat> who said anything about a require anywhere
<nikamura> mhm, probably will have to use permit!
<rubycasts_io_> "<nikamura> params.require(:tags).permit ???"
<rubycasts_io_> that is where
<sevenseacat> so change the require to a permit?
<sevenseacat> then permit the exact options you want
<rubycasts_io_> that would not be 'railsy'
<sevenseacat> the fuck?
<rubycasts_io_> wrap tags in another key
<nikamura> params.permit(:tags)
<nikamura> Unpermitted parameters: utf8, _method, tags, commit
<rubycasts_io_> that way you can require and permit
<sevenseacat> yes, lets make it 'railsy' and do it your way so it can be insecure
<nikamura> oh okay params.permit(tags: {})
...
<nikamura> works
<nikamura> thanks
<sevenseacat> nikamura: so slice out the params you want, first
<rubycasts_io_> sevenseacat, you can fuck off again tonight
<sevenseacat> rubycasts_io_: be careful.
<rubycasts_io_> i spent an hour helping someone you wouldnt last night after you accused me of not being friendly
<sevenseacat> and watch your language.
<rubycasts_io_> keep your negative stuff to yourself
<sevenseacat> i didnt accuse you of anything.
<rubycasts_io_> "<sevenseacat> the fuck?"
<rubycasts_io_> ok captain america
<sevenseacat> yes, thats a bit different than telling someone to fuck off.
<nikamura> params.slice(:tags).permit(tags: [:parent_tag, :description])
...
<nikamura> cheers gutys
<nikamura> guys*
<sevenseacat> nikamura: good stuff :)
<rubycasts_io_> you can address other people you dont need to get in my kool aid
seveneacat!*@* added to ignore list.
<sevenseacat> rubycasts_io_: thats alright, i've warned you to watch yourself, i wont do it again.
<rubycasts_io_> thanks for the warning big boy
<sevenseacat> good of you to assume we're all boys here.
<rubycasts_io_> you are acting tough, thus big boy
<rubycasts_io_> now bugger off pls
<sevenseacat> i did warn you
<rubycasts_io_> you keep saying that
* ChanServ gives channel operator status to sevenseacat
* You have been kicked from #RubyOnRails by sevenseacat (Your behavior is not conducive to the desired environment.)
No channel joined. Try /join #<channel>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment