Advertisement
Guest User

Untitled

a guest
Oct 24th, 2014
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.96 KB | None | 0 0
  1. 16:19 jespanda: :/
  2. 16:19 jespanda: question
  3. 16:19 jespanda: if i am editing routes, i have /123-blah, but I just want /123, how do i get that?
  4. 16:21 wsong: k
  5. 16:21 ian: routes in what
  6. 16:21 ian: wsong: bye
  7. 16:21 ian: wait
  8. 16:21 ian: are you not saying goodbye
  9. 16:21 wsong: ?
  10. 16:21 wsong: oh
  11. 16:21 ian: I thought I was going to be super smart and call it before you said so
  12. 16:21 wsong: wrong window
  13. 16:21 jespanda: routes in ruby
  14. 16:21 ian: damnnnn
  15. 16:21 wsong: close call though
  16. 16:22 wsong: you wanna watch the game somewhere today, btw?
  17. 16:22 ian: matt is coming into town and we're supposed to hang out
  18. 16:22 ian: I dunno where or when
  19. 16:22 ian: still waiting to hear back
  20. 16:23 Asterism: oh fuck
  21. 16:23 Asterism: mali index patient came in on a bus
  22. 16:23 ian: mali index?
  23. 16:23 Asterism: bleeding the whole way, and misdiagnosed as typhoid
  24. 16:23 ian: oooo fuck
  25. 16:23 jAg: hahhahahahahahahahahahah.....fuck
  26. 16:24 Asterism: rip
  27. 16:24 Asterism: basically worst case scenario here
  28. 16:24 jespanda: mali index?
  29. 16:24 jespanda: anyone able to help with the route problem?
  30. 16:24 Asterism: patient zero
  31. 16:24 jespanda: news link
  32. 16:25 wsong: jespanda: are you just trying to change the string?
  33. 16:25 wsong: or do you mean in like rails or whatever
  34. 16:25 jespanda: yes
  35. 16:25 skimbrel: jespanda: ruby != rails
  36. 16:25 Asterism: it's worth noting that ebola's batting average against Americans being treated in American hospitals is south of 33%
  37. 16:25 jespanda: in ruby
  38. 16:25 Asterism: 0.33 I guess
  39. 16:25 wsong: oh
  40. 16:25 wsong: well, is the “-blah” part always the same length?
  41. 16:25 jespanda: no
  42. 16:25 wsong: you could just split on hyphens
  43. 16:25 jespanda: random srting
  44. 16:25 wsong: and just drop the last bit
  45. 16:25 Asterism: which leves to a bunch of reassuring/non-reassuring inferences
  46. 16:25 jespanda: random strings
  47. 16:25 skimbrel: what do you have, and what do you want
  48. 16:25 jespanda: i just want whatever digits are in the front
  49. 16:25 jespanda: i was trying to regex it
  50. 16:25 jAg: tropical diseases aren't nearly as effective against modern western medicine?!! COlor me shocked
  51. 16:25 jAg: "Forty-three people, including 10 health workers, who came into contact with her have been identified and isolated."
  52. 16:25 jespanda: but it spat out the id without the changes
  53. 16:25 skimbrel: /(\d+).+?/
  54. 16:25 Asterism: inference A) some of those weird ass experimental therapies actually work (not reassuring, since we're pretty much out)
  55. 16:26 skimbrel: then retrieve the first group
  56. 16:26 skimbrel: i forget how you get groups out of a match in rubby
  57. 16:26 Asterism: inference B) early contact tracing leading to early hospitalization significantly increases survival rate (kind of reassuring; these systems will be stressed in a major outbreak)
  58. 16:26 evan___ has joined (~Palaver@152.sub-70-208-91.myvzw.com)
  59. 16:26 Asterism: inference C) higher standards of pallative care significantly increases survival rate (pretty reassuring)
  60. 16:28 jespanda: to_s.gsub(/^\d*/, '')
  61. 16:28 jespanda: gsub(/^\d*/, '')
  62. 16:28 jespanda: is what i have
  63. 16:28 skimbrel: are you trying to do it in place?
  64. 16:28 jespanda: i would expect to at least remove part of the string
  65. 16:28 jespanda: i have 1234-abcd
  66. 16:28 wsong: i think you need square brackets
  67. 16:28 wsong: if you’re trying to do a character class
  68. 16:29 jespanda: when i did that, the entire string just disappears
  69. 16:30 wsong: how about
  70. 16:30 jespanda: hence my confusion
  71. 16:30 wsong: to_s.gsub(/[^0-9]/, ‘’)
  72. 16:30 wsong: i don’t know ruby, but i think gsub will match on a character-by-character basis
  73. 16:31 wsong: yeah
  74. 16:31 jespanda: nope, i still get the full string
  75. 16:31 evan___ has left IRC (Ping timeout: 255 seconds)
  76. 16:31 wsong: huh
  77. 16:31 wsong: i’m trying it out here:
  78. 16:31 wsong: http://repl.it/languages/Ruby
  79. 16:31 steggybot__: repl.it
  80. 16:32 wsong: and this does the right thing
  81. 16:32 wsong: "/123-blah".to_s.gsub(/[^\d]/, '')
  82. 16:32 wsong: that should be equivalent to this, btw
  83. 16:32 wsong: "/123-blah".gsub(/[^0-9]*/, '')
  84. 16:32 wsong: is that what you’re entering?
  85. 16:32 wsong: keep in mind that that’ll return the string you want
  86. 16:32 wsong: the original string will, i think, be unmodified
  87. 16:32 wsong: (ruby has immutable strings, right?)
  88. 16:32 jespanda: i start with /boo/:id
  89. 16:32 jespanda: i am feeding it into bar(:id)
  90. 16:33 jespanda: and i want bar to do the transformation for me
  91. 16:33 skimbrel: and which piece do you want out
  92. 16:33 wsong: well, do you want to actually modify the string
  93. 16:33 wsong: or do you want bar to return a string
  94. 16:33 wsong: if ruby’s anything like python, you can’t modify strings
  95. 16:34 wsong: anyways, i gotta go into a meeting, but good luck
  96. 16:34 jespanda: new_id = '%{id}'.to_s.gsub(/[^0-9]/, ‘’)
  97. 16:34 jespanda: is what i currently have
  98. 16:34 jespanda: where new_id is hopefully the sanitized version
  99. 16:34 skimbrel: can we describe the problem in english
  100. 16:35 skimbrel: and then construct the appropriate code
  101. 16:35 skimbrel: you have: a string of the form “123-abc-def”
  102. 16:35 skimbrel: and you want “123”?
  103. 16:35 skimbrel: or you want “-abc-def”
  104. 16:36 jespanda: i want 123
  105. 16:36 jespanda: i just want the numbers
  106. 16:36 whunt has left IRC (Ping timeout: 272 seconds)
  107. 16:37 skimbrel: ok
  108. 16:37 skimbrel: you need to use a group
  109. 16:38 jespanda: why is that?
  110. 16:38 skimbrel: because groups capture the things you match with them
  111. 16:38 skimbrel: and then you can extract that matched substring from the match object:
  112. 16:38 skimbrel: and you shouldn’t be using gsub
  113. 16:38 Asterism: what's wrong with /^(\d+)-\S+$/
  114. 16:38 skimbrel: instead of trying to delete things you don’t care about, match the thing you do want
  115. 16:39 skimbrel: yes, exactly that thing asterism just said
  116. 16:39 Asterism: and yeah, you want string#match
  117. 16:39 skimbrel: int_id = /(\d+).*/.match(id)[1]
  118. 16:39 skimbrel: http://www.ruby-doc.org/core-2.1.3/Regexp.html#method-i-match
  119. 16:39 steggybot__: Class: Regexp (Ruby 2.1.3)
  120. 16:39 Asterism: that too
  121. 16:42 Asterism: alright
  122. 16:42 Asterism: that's it
  123. 16:42 Asterism: bill kirstol has gone off the deep end
  124. 16:42 Asterism: https://twitter.com/BillKristol/status/524920942049648640
  125. 16:43 skimbrel: also jespanda you shouldn’t need to use “%{id}” if id is already a string
  126. 16:43 skimbrel: rofl, cheney-giuliani
  127. 16:44 whunt has joined (~whunt@216.2.42.42)
  128. 16:44 heidi has joined (~heidi@216.2.42.42)
  129. 16:45 jespanda: skimbrel, i am getting this error now
  130. 16:45 jespanda: undefined method `[]' for nil:NilClass
  131. 16:45 Asterism: jespanda: okay, just use this
  132. 16:45 Asterism: http://rubular.com/
  133. 16:45 steggybot__: Rubular: a Ruby regular expression editor and tester
  134. 16:46 skimbrel: if you got nil then it means your match didn't.
  135. 16:46 Asterism: for the record, skimbrel's code works fine in 1.9.3
  136. 16:46 skimbrel: what the fuck did they change in 2.0?
  137. 16:46 Asterism: um
  138. 16:47 Asterism: almost nothing
  139. 16:47 Asterism: so i'm going to say that it's the string's fault
  140. 16:47 skimbrel: oh heh
  141. 16:47 jAg: man, Asterism, i want whatever he's smoking
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement