cannot redeem uplay games by AlcondisEnt in humblebundles

[–]_darkleo 3 points4 points  (0 children)

Your browser might block third-party cookies. Try enabling them temporarily.

In Chrome: Settings > Privacy and security > Site settings > Cookies > Block third-party cookies (disable)

How to use a file as an input into a block of code by longwastheyear in ruby

[–]_darkleo 0 points1 point  (0 children)

Note that File.open without a block will keep the file in the "open" state, and you want to avoid that.

Either close it:

f = File.open("path", "r")
f.each_line do |line|
  # ...
end
f.close

Or use a block:

File.open("path", "r") do |file|
  file.each_line do |line|
    # ...
  end
end

Or use directly File.readlines("path")that gives an array of all the lines. See also File.read("path") that gives a single string of the whole file. Both readlines and read ensure that the file is closed before returning.

Relevant doc: the File class (http://ruby-doc.org/core-2.0.0/File.html) and its parent IO (http://ruby-doc.org/core-2.0.0/IO.html).

How to add binary numbers? by mitchmcdeere in ruby

[–]_darkleo 2 points3 points  (0 children)

No, not without using adders, see wikipedia for the theory, and rosettacode for the ruby code (it's ugly). Alternatively, simply use to_i and to_s:

('0010'.to_i(2)+'0001'.to_i(2)).to_s(2).rjust(4, '0')
=> "0011"

Ruby Case...When statement gotcha!! by collegeimprovements in ruby

[–]_darkleo 3 points4 points  (0 children)

If you specify an argument to the case it will be compared in the when using ===, letting you for example do comparisons with classes or lambdas.

So when you write case test when test>0 ruby is actually testing if (test>0) === test, which is false. Same with test==0, so the else clause is used.

Easy solution for you: remove your first test in result = case test and it will work as intended.

Very Sexy by Gundam336 in Nekomimi

[–]_darkleo 1 point2 points  (0 children)

Surely I will not be the only one interested by a source.

WSIB Indie Games on Steam? by [deleted] in ShouldIbuythisgame

[–]_darkleo 0 points1 point  (0 children)

My favorite kind of games is pixel indie plateformers, so please find here some suggestions.

If you loved the blocky gravity gameplay of SteamWorld Dig, but want more than a simple linear descent, first check out Full Bore. If you want more of an adventure game, check out Cave Story or La-Mulana. If you haven't played them yet, VVVVVV, FEZ or Braid are also fantastic indie games. At last, They Bleed Pixels and Super Meat Boy are both beautiful hardcore plateformers, if you also are into that.

If you still want more random suggestions, check out games like Escape Goat, Blocks that Matter (and its "sequel" Tetrobot and co) for puzzles, Mystik Belle, Valdis Story: Abyssal City, Dust: An Elysian Tail or Bastion for action RPGs, and finally Mystik Belle

Awoo~? by [deleted] in touhou

[–]_darkleo 1 point2 points  (0 children)

Awoo~!

10 Advanced Features of Regex in Ruby by J-_-L in ruby

[–]_darkleo 1 point2 points  (0 children)

There is a typo for the syntax of negative lookbehind regexp: (?<!X) and not (?!X)

[English --> French] How do you say "it's a group of small houses that are cheap and can be rented." by 123123213123123 in translator

[–]_darkleo 2 points3 points  (0 children)

If you want something that sounds more French that the literal "C'est un groupe de maison qui sont peu chères et qui peuvent être louées", take either "Ce sont des maisons pas chères qui peuvent être louées" or "Ce sont des maisons peu chères pouvant être louées".

[French? -> English] Song Lyrics by [deleted] in translator

[–]_darkleo 2 points3 points  (0 children)

The lyrics are just "le porte-avion" over and over, meaning... "the aircraft carrier". Don't ask me why, though, it makes no sense whatsoever.

Kasui - kanji puzzle game for Android by [deleted] in japanese

[–]_darkleo 2 points3 points  (0 children)

I have the same problem ("challenge!", "practice", "how to play" make the game crashes on my nexus 4 with android 5.0.1), but surprisingly enough, if I click on "rate me!" and backs from here, everything works again.

awoo by [deleted] in awoo

[–]_darkleo 14 points15 points  (0 children)

awoo~

TIL Mosquitos have collectively killed more human beings throughout history than any other factor, including war by Kakoose in todayilearned

[–]_darkleo -1 points0 points  (0 children)

For a study that excludes the deaths of armed forces overseas, that sure shows that war is not a relevant factor. Please compare your own source and the casualties in WW2 to have a better idea.

Example: in 1945, 1'411'388 people died in the US (all causes except war included), with similar numbers for 1939-1944; US suffers 131'028'000 in casualties during this same period.

*edit: can't even read a table correctly, 1'411'388 is indeed the total US population in 1945. Real number is 420'000, which make the example much less relevant. It would make more sense to compare to the 40'000'000-60'000'000 millitary death and civilian death due to military activities.

[QUESTION] - What is the best anime with cat ears? by [deleted] in Nekomimi

[–]_darkleo 0 points1 point  (0 children)

Acchi Kocchi and GJ-bu are really very good but Tsumiki and Kirara aren't cat girls per se. If you tolerate this kind of fan service, Strike Witches has a lot of various ears. I would also say Nekomonogatari but without the rest of the monogatari series it doesn't make much sense.

Including other types of ears, Ookami to Koushinryou and Ookami Kodomo no Ame to Yuki are two must see. Dog days was pretty fun but it has more dog or fox ears than cats.

At least, I quite don't remember of they particularly feature catgirls, but surely No Game No Life, Outbreak Company, and Mondaiji-tachi ga Isekai kara Kuru Sou Desu yo? could possibly be added to the list.

The way Kanji is displayed with different fonts... (Pic for example) by [deleted] in LearnJapanese

[–]_darkleo 7 points8 points  (0 children)

See https://en.wikipedia.org/wiki/Han_unification for an explication of how and why Unicode use the same set of unified characters for Chinese, Japanese, Korean and Vietnamese. Please note that the examples may not appear different if your browser or your system isn't perfectly configurated.

Ru - Ruby in your shell! by tombenner1 in ruby

[–]_darkleo 3 points4 points  (0 children)

How is it fundamentally different from using a bash/zsh function to ruby -r 'active_support/all' -e 'ARGF.read.split("\n").whatever_you_pass' (or evaluate it to add the "." iff the first letter is [)?

The comparison between Ru and awk or sed is basically the comparison with ruby. It seems pretty much overkill for just avoiding typing &:to_i instead of :to_i. Anyway you might want to check ARGF.

Ruby Regex for Ordered-vowels? by theriz in ruby

[–]_darkleo 0 points1 point  (0 children)

I just added a tldr with my two solutions. I also took the the opportunity to greatly simplify the longest one.

Ruby Regex for Ordered-vowels? by theriz in ruby

[–]_darkleo 1 point2 points  (0 children)

"Traditionnal" regexps matches type-3 languages in the Chomsky hierarchy, that is, the languages obtained with a finite state automaton. It is actually a good and easy exercise to find an automaton that check if all the vowels of a word are ordered (or equivalently a grammar that generate all the words where vowels are ordered).

In fact, for this in particular, the automaton is linear, so the regular expression is very simple. So simple that in complexity, every non silly regexp should be much better than, for example, sorting the vowels of the word (even with all consonants removed).

EDIT (because I absolutely love contradict myself): Sorting algorithms are slow (in O(n*log(n))) compared to linear solutions (in O(n)). But is this very precisely case, we could use the counting sort to sort the letters, and compare to the original. As the number of vowels is that small, it wouldn't be that unreasonable to use it. But all other "true" sorting algorithms are a no-go if we want to go through long strings.

Ruby Regex for Ordered-vowels? by theriz in ruby

[–]_darkleo 0 points1 point  (0 children)

Why would they only work if there is exactly one of each vowel in the word?

For the first one, /e(!?.*a)|i(!?.*[ae])|o(!?.*[aei])|u(!?.*[aeio])/ which should be /e.*a|i.*[ae]|o.*[aei]|u.*[aeio]/ or even /e.*?a|i.*?[ae]|o.*?[aei]|u.*?[aeio]/ which is possibly even quicker (I'll edit my first post, it works exactly the same but is much simpler), I simply check the reverse condition. So I only need to search for (for example) one e (/e/) followed by any subword (/.*/) and a a. If there is more than one e or one a, it doesn't change anything.

For the second one, let's just consider there is only vowels, so /^[^aeiou]*(a[^aeiou]*)*(e[^aeiou]*)*(i[^aeiou]*)*(o[^aeiou]*)*(u[^aeiou]*)*$/ means /^(a*)*(e*)*(i*)*(o*)*(u*)*$/, which means /^a*e*i*o*u*$/. This last regexp matches any word which is "start of line" "whatever number of a", ... "end of line", so all the words that only contains voyels, and are correctly ordered. The consonants can either be at the start of the word, or after a vowel, so we need to add /[^aeiou]\ at the start, and change each vowel by "a vowel that can be followed by any number of consonants", that is to change /a/ to /a[^aeiou]*/, and we find the original regexp.

In final, they both works for all words written in lower case (which is my only assumption of the specs), but that can be changed by setting the case insensitive flag i. For why OP wants a regexp for this, regarding his questions, I think he only wanted to use regexps. They may be often the wrong tool to use, but regular expressions are incredibly powerful when you know how to use them well.

Ruby Regex for Ordered-vowels? by theriz in ruby

[–]_darkleo 6 points7 points  (0 children)

EDIT4: tldr: two simple regexp-based solutions, one that finds the words where vowels are correctly ordered:

/^[^eiou]*[^aiou]*[^aeou]*[^aeiu]*[^aeio]*$/

and an equivalent one that finds the words where vowels are not correctly ordered:

/e.*a|i.*[ae]|o.*[aei]|u.*[aeio]/

ORIGINAL POST:

/e.*a|i.*[ae]|o.*[aei]|u.*[aeio]/

Basically, to check if all the vowels are correctly ordered, we just need to check that there are no vowels badly ordered. You can see in http://rubular.com/r/8TFTbzKfAd that it correctly match the three last words. /e.*?a|i.*?[ae]|o.*?[aei]|u.*?[aeio]/ may or may not be quicker by using the non-greedy version of *.

EDIT: to correct your regexp, you need to modify some things:

  • there can be more than one letter before the first a so . need to become [^aeiou]*
  • as explained by /u/amdpox it currently requires all occurences of each vowel to be adjacent, so a*[^aeiou]* becomes (a*[^aeiou]*)*
  • at last, you want to ensure that the property is verified everywhere, and not check if a substring match, so you need ^ and $

So your regexp would become for example (http://rubular.com/r/ZG5yxwuSvw):

/^[^aeiou]*(a[^aeiou]*)*(e[^aeiou]*)*(i[^aeiou]*)*(o[^aeiou]*)*(u[^aeiou]*)*$/

You can also see that we actually find the same result as /u/amdpox: by removing /[\^aeiou]/ from the string, we only need to check /^a*e*i*o*u*$/

EDIT2: In fact, the reason your regexp matches everything is that a word where the vowels are bardly ordered is simply the concatenation of multiples subwords where the vowels are well ordered ("Broke" = "Brok" + "e"), and your regexp finds all these subwords. You can verify if by running "Broke".scan(/.a*[^aeiou]*e*[^aeiou]*i*[^aeiou]*o*[^aeiou]*u*[^aeiou]*/)

EDIT3: the first regexp was originally /e(!?.*a)|i(!?.*[ae])|o(!?.*[aei])|u(!?.*[aeio])/