NotarySojac's Profile
Reputation: 49
Craftsman
- Group:
- Contributors
- Active Posts:
- 424 (0.44 per day)
- Joined:
- 30-September 10
- Profile Views:
- 12,500
- Last Active:
May 15 2013 11:39 AM- Currently:
- Offline
Previous Fields
- Country:
- Who Cares
- OS Preference:
- Who Cares
- Favorite Browser:
- Opera
- Favorite Processor:
- Who Cares
- Favorite Gaming Platform:
- Who Cares
- Your Car:
- Who Cares
- Dream Kudos:
- 50
Posts I've Made
-
In Topic: Starting out a new gem, skeleton generator
Posted 8 May 2013
Just to make this thead a little more classy, I'll update with what I've settled into doing.
To rapidly generate a new prototype gem, I've installed ore which sets up the skeleton for me.
$ gem install ore
Now when I want to create a new library (typically I see the need for a new lib when I'm smack in the middle of another project) I just need to invoke ore on the commandline.
$ cd ~/dev/ruby $ mine app_name
It consults the defaults specified here:
(~/.ore/options.yml)
bundler: true gemspec_yml: true rubygems_tasks: true rspec: true standard_prototype: true
The ensures that the project has a Gemfile, rspec testing files and a decent Rakefile. Also ato the bottom it says standard_prototype: true. That's a template I jotted up today. I cached it on github and can installed it on the commandline with the below command.
$ ore install https://github.com/TheNotary/standard_prototype
That template adds a bin folder and allows the gem to be called on the command line via gem_name blah which just puts the word blah to the screen. -
In Topic: Starting out a new gem, skeleton generator
Posted 8 May 2013
I started playing around with google to configure bundler for this, and that lead to a gem called ore which does pretty much exactly what I need (though I'd like to tweak the rakefile it generates and the docs are a little iffy on how templating works).
$ gem install ore $ mine project_name --rspec --bundler
-
In Topic: string encoding in Ruby
Posted 5 May 2013
waleedshiekh, on 04 May 2013 - 10:52 PM, said:I did this
def encode(input) groupsOfChars = [] input.each_char do |c| if groupsOfChars.empty? || groupsOfChars.last[0] != c groupsOfChars << [c, 1] else groupsOfChars.last[1] += 1 end end groupsOfChars end
I tried to use the final groupOfChars in the function and tried to follow the approach that if char then insert else take sum of the one then insert. I'm very new to Ruby. I know Java programming that's why I'm having issues.
That code is pretty tight, I expected the algo to look a little more painful on the eyes, actually.
Here's an algo I came up with using #drop_while and #take_while to sort of 'sculpt' the array. It's less efficient, but with Ruby, the emphasis is placed on code beauty and maintainability (until you start missing important benchmark figures, that is).
def flatten_stack(str) a = str.split('') # convert the string into an array output = [] while (a.length != 0) do # loop until our read array is depleted char_of_clump = a.first clump = a.take_while { |el| el == char_of_clump } # grab the nth clump from the array a = a.drop(clump.length) # remove the clump of chars from the array we're reading since we're done with them output << [char_of_clump, clump.length] end output end # begin: str = "aaabbcbbaaa" p flatten_stack(str)
I couldn't figure out how to use #chunk to get the job done though it seems like such a function would excel in chunking scenarios like this one. -
In Topic: string encoding in Ruby
Posted 3 May 2013
waleedshiekh, on 02 May 2013 - 09:10 AM, said:I want to encode a string in Ruby such that output should be in pairs so that I could decode it. I want to encode in such a way that each pair contains the next distinct letter in the string, and the number consecutive repeats.
e.g If I encode "aaabbcbbaaa" output should
[["a", 3], ["b", 2], ["c", 1], ["b", 2], ["a", 3]]
Hey waleedshiekh, welcome to the forums. Around here, it's considered polite to post the current state of your code when asking for help. It's a way of proving that you're not a useless computer science major who has no intent of learning how to program (they show up in the other forums A LOT, so it's become a pretty big issue).
I couldn't resist your puzzle so I came up with a solution that uses the array methods #take_while and #drop to sort out the issue in a fairly articulate manor. Feel free to share your code if you hit a dead end. And thanks for the puzzle, it's good to keep sharp on these kinds of array problems. -
In Topic: Someone wanna give me a head start here?
Posted 14 Apr 2013
My Information
- Member Title:
- D.I.C Regular
- Age:
- Age Unknown
- Birthday:
- Birthday Unknown
- Gender:
-
- Programming Languages:
- C#, Ruby, Rails, js, css, AutoIT, vbs
Contact Information
- E-mail:
- Private
|
|


Find Topics
Find Posts
View Reputation Given

|
Comments
ATC3
13 Dec 2011 - 08:36