## #ruby - 18 March 2019

« Back 1 day

[04:43:16]
marz_d`ghostman:
When your app uses secret keys and stuff for api calls, where's the best place to put it? as environment variable on the system?

[04:45:19]
havenwood:
marz_d`ghostman: Rails uses encrypted credentials these days. Lots of folk still use environment variables.

[04:46:29]
marz_d`ghostman:
havenwood: I'll take a look at encrypted credentials, thanks, I'm currently using environment variable by the way, was just wondering if there is a more secure way to do it :)

[04:47:17]
havenwood:
marz_d`ghostman: Here's simple encryption with the JOSE gem, fwiw: https://gist.github.com/havenwood/e18de5fa23ec1c49e3feab493d579909

[14:13:13]
xco:
Hi. What will be the best way to determing if a string has repeating strings? for example this should return true “abcabcabcabc”

[14:21:08]
xco:
so basically the challenge i picked says this “We'll define a string as prime if it cannot be constructed by concatenating some (more than one) equal strings together.”

[14:48:31]
ytti:
like for example, you only need to figure out the lengths which are divisible by the total length of the string

[15:20:16]
phaul:
&>> require 'prime'; 'abcabc'.yield_self { |s| s.length.prime_division.any? { |p, _| p < s.length && s[0,p] * (s.length / p) == s } }

[15:21:35]
grr12314:
&>> require 'prime'; 'zzzzz'.yield_self { |s| s.length.prime_division.any? { |p, _| p < s.length && s[0,p] * (s.length / p) == s } }

[15:23:41]
phaul:
&>> require 'prime'; 'abcdabcd'.yield_self { |s| s.length.prime_division.any? { |p, _| p < s.length && s[0,p] * (s.length / p) == s } }

[15:28:25]
grr12314:
the block could also be s.chars.each_slice(X).to_a.uniq.size==1 or something :p

[15:35:12]
phaul:
it would also be broken for prime length single char strings like 'aaa' assuming that's supposed to be repeating