This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
irb(main):040:0> testcases | |
=> ["hello world", "'hello world", "'hello' world", "hello' world"] | |
irb(main):041:0> testcases.each { |i| puts /(?<!')hello(?!')/.match(i) } | |
hello | |
=> ["hello world", "'hello world", "'hello' world", "hello' world"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
audience_range_values = [] | |
age_from = nil | |
audience_range_values << age_from || 3 # does not work, returns book.a | |
print audience_range_values | |
audience_range_values = [] | |
# output [nil] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Many concepts here to revisit, so saving in gist. | |
http://stackoverflow.com/questions/21712814/how-can-i-extract-the-bigger-value-for-each-key-in-a-list-of-hashes-in-ruby/21729254?noredirect=1#comment32860522_21729254 | |
a = [{1=>19.4}, {1=>12.4}, {2=>29.4}, {3=>12.4}, {2=>39.4}, {2=>59.4}] | |
# the below is the main trick, to group the hashes and sorted the key/value pair | |
# in **ascending order**. | |
a.sort_by(&:to_a) | |
# => [{1=>12.4}, {1=>19.4}, {2=>29.4}, {2=>39.4}, {2=>59.4}, {3=>12.4}] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
irb(main):001:0> 'A' * 3 | |
=> "AAA" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# I thought this was neat | |
# Reference: http://stackoverflow.com/questions/21404323/combining-two-different-ranges-to-one-in-ruby | |
[*'0'..'9', *'a'..'z', *'A'..'Z'].shuffle.first(2).join | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function genericallyCallingMap(dna) { | |
var complements = {"C":"G", "G":"C", "T":"A", "A":"U"}; | |
var map = Array.prototype.map | |
var a = map.call(dna, function(x) { | |
return complements[x]; | |
}) | |
return a.join(""); | |
}; | |
function callingMapOnAnArray(dna) { | |
var a = dna.split("").map( function(x) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Bst | |
attr_accessor :data, :left, :right | |
def initialize(data) | |
self.data = data | |
end | |
def insert_r(data) | |
if (self.right ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Element | |
attr_accessor :datum, :next | |
def initialize(datum,next_element) | |
@datum = datum | |
@next = next_element | |
end | |
def reverse |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
new_size(st_index_t size) | |
{ | |
st_index_t i; | |
for (i=3; i<31; i++) { | |
if ((st_index_t)(1<<i) > size) return 1<<i; | |
} | |
#ifndef NOT_RUBY | |
rb_raise(rb_eRuntimeError, "st_table too big"); | |
#endif | |
return -1; /* should raise exception */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--http://forums.coronalabs.com/topic/37362-improvement-to-the-ultimate-configlua-file/ | |
--The effect of that bit of math is to set the content width or height appropriately for letterbox scaling according to the aspect ratio of the device. Why is that good? Because the upper-left corner is now (0,0), and display.contentWidth and display.contentHeight now cover the entire screen. For example, on an iPhone 5, display.pixelHeight is 1136 and display.pixelHeight is 640. If you do the math, you'll see that it'll set width to 320 and height to 568. | |
-- It'll set the width and height appropriately for every single device, no matter what the resolution or aspect ratio. And there's no need to code into your config.lua different blocks for different devices. | |
--the upper-left corner isn't at (0,0). Instead, it's at (display.screenOriginX, display.screenOriginY) | |
local aspectRatio = display.pixelHeight/display.pixelWidth | |
application = | |
{ | |
content = |
OlderNewer