Skip to content

Instantly share code, notes, and snippets.

@wvengen
wvengen / README.md
Last active March 25, 2024 07:53
Ruby memory analysis over time

Finding a Ruby memory leak using a time analysis

When developing a program in Ruby, you may sometimes encounter a memory leak. For a while now, Ruby has a facility to gather information about what objects are laying around: ObjectSpace.

There are several approaches one can take to debug a leak. This discusses a time-based approach, where a full memory dump is generated every, say, 5 minutes, during a time that the memory leak is showing up. Afterwards, one can look at all the objects, and find out which ones are staying around, causing the

@tjhanley
tjhanley / stock.rb
Created March 21, 2013 02:53
I thought about the problem a bit more and given we can assume it is a time range if I knew where the maximum number was in the array i could get that index and work backward. Once I thought of the problem that way and with the key statement you gave me to watch out for those ranges that could go up and down. A sample result would look like this…
#!/usr/bin/env ruby -wKU
require "test/unit"
class Stock
# To change this template use File | Settings | File Templates.
def self.find_longest_run(prices=[])
return {:low=>{0.0=>0},:high=>{0.0=>0}} if prices.nil? || prices.size == 0
result = {}
# start at the end
#find the highest value
@tjhanley
tjhanley / LinkedListTest
Last active December 14, 2015 18:39
Linked List in Ruby
$> ./linked_list.rb
Run options:
# Running tests:
......
Finished tests in 0.000599s, 10016.6945 tests/s, 20033.3890 assertions/s.
6 tests, 12 assertions, 0 failures, 0 errors, 0 skips
@tjhanley
tjhanley / add_1_to_n.rb
Last active March 1, 2016 16:06
Simple Problems
def add_1_to_n(n)
return n <= 0 ? 0 : n + add_1_to_n( n - 1 )
end
puts add_1_to_n(10) #=> 55
@tjhanley
tjhanley / bashkeyboardhelp
Created September 30, 2012 17:33
Bash Keyboard Shortcut Helper
BASH_KEYS=$(cat <<EOF
Ctrl + A Go to the beginning of the line you are currently typing on
Ctrl + E Go to the end of the line you are currently typing on
Ctrl + L Clears the Screen, similar to the clear command
Ctrl + U Clears the line before the cursor position. If you are at the end of the line, clears the entire line.
Ctrl + H Same as backspace
Ctrl + R Let’s you search through previously used commands
Ctrl + C Kill whatever you are running
Ctrl + D Exit the current shell
@myronmarston
myronmarston / ways_to_use_vcr.rb
Created April 13, 2012 15:00
Ways to use VCR for a request made by a let block
# 1) Use VCR.use_cassette in your let block. This will use
# the cassette just for requests made by creating bar, not
# for anything else in your test.
let(:foo) { VCR.use_cassette("foo") { create(:bar) } }
it "uses foo" do
foo
end
# 2) Wrap the it block that uses #foo in VCR.use_cassette.
@artero
artero / launch_sublime_from_terminal.markdown
Last active May 15, 2024 03:38 — forked from olivierlacan/launch_sublime_from_terminal.markdown
Launch Sublime Text 2 from the Mac OS X Terminal

Launch Sublime Text 2 from the Mac OS X Terminal

Sublime Text 2 ships with a CLI called subl (why not "sublime", go figure). This utility is hidden in the following folder (assuming you installed Sublime in /Applications like normal folk. If this following line opens Sublime Text for you, then bingo, you're ready.

open /Applications/Sublime\ Text\ 2.app/Contents/SharedSupport/bin/subl

You can find more (official) details about subl here: http://www.sublimetext.com/docs/2/osx_command_line.html

Installation

@zhengjia
zhengjia / capybara cheat sheet
Created June 7, 2010 01:35
capybara cheat sheet
=Navigating=
visit('/projects')
visit(post_comments_path(post))
=Clicking links and buttons=
click_link('id-of-link')
click_link('Link Text')
click_button('Save')
click('Link Text') # Click either a link or a button
click('Button Value')