| Snippet ID |
Title |
|
 |
| Packages Of Snippets | | 33 | Language Numbers | zhang bee |
| Some kinds of Numbers are in English! |
| 38 | Surd arithmetic | Dick Pountain |
| Permits arithmetic using irrational roots in symbolic form, like √2 or 3+√5 from a Ruby program. |
| 39 | Surd arithmetic | Dick Pountain |
| Let's you return values including irrational roots like √2 or 3+√5 from a Ruby program, by defining a class Surd. |
| 76 | laplace | Wictor Borisov |
| Laplace transform inverse |
| 77 | laplace | Wictor Borisov |
| Laplace transform inverse |
| 78 | laplace | Wictor Borisov |
| Laplace transform inverse |
| Snippets |
| 8 | Commify a number | Tom Copeland |
| Commifies a number. Preserved from Warren Brown's ruby-talk posting here - http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/78103. |
| 20 | [ 2 , 4 ] * [ 5, 5 ] | Rodrigo Bermejo |
| Array multiplication |
| 89 | Range Sum | Robert Myers |
| function that returns the sum of every number within a range, without the use of looping. |
| 90 | Calculate Air Density | Michael Vera |
| Caclulate Air Density with C++ |
| 92 | Primes / Factoring | Justin Smith |
A class which provides a listing of primes, via an "each" method.
Also provides a function to produce the prime factors of a given number.
Feedback is welcome. |
| 104 | Commify a Number | Craig Kim |
A convenient function to commify a number or number string using Tom Copeland's snippet. Examples:
irb(main):009:0> commify(123456)
=> "123,456"
irb(main):010:0> commify('123456')
=> "123,456"
irb(main):011:0> commify('123456','_')
=> "123_456"
irb(main):012:0> commify(123456,'_')
=> "123_456"
|
| 107 | convert time in seconds to uptime | Erik Hollensbe |
This will take a time in seconds (for instance, from a delta of Time.now.to_i at two different times), and convert that to a number of days, hours, minutes, and seconds.
Note: if you want to add weeks and so on, merely figure out the magic number for that amount and put it at the head of the list, the loop will figure it out.
|
| 135 | Roman Numerals | |
| Completely pointless class that converts integers to Roman numerals and vice versa, also extends the integer class with a "to_roman" method. Using method missing as syntactic sugar for converting numerals to numbers. |
| 150 | Date/Rational/Fixnum#gcd hack increased performance by 15% | Kurt Stephens |
Date uses Rational heavily, which calls Integer#gcd for every new Rational. The Integer#gcd method is generic to handle Bignums, but performs terribly for Fixnum#gcd(Fixnum), which is probably the most often case.
My RubyInline hack saved 15% execution time in a large Rails application:
|
| 152 | Quadratic Formula | patrick fitzstephens |
A quadratic formula script that gets the inputs of the A, B and C numbers and then finds the roots for those numbers.
If you don't know how the quadratic formula works go to: http://www.purplemath.com/modules/quadform.htm |
| 162 | Prime numbers | Michael Behan |
| Extends the Fixnum class with a "primes" method. `100.primes` will return all the prime numbers between 1 and 100. |
| 165 | extendible multidimensional array with compact storage | Jan Wedekind |
| This is an early version of a class for multidimensional arrays. New element-types and coercions can be added later. Elementwise operations (such as "+" and "-") are very slow at the moment. |
| 254 | Number Wang | Philip Matarese |
| An experiment with Ascii Art and Ruby code. |
| 273 | Quick Parse | Tomokiyo Nomura |
| A simpe programmable parser. A Lex class object is created with a rex_rule which is an array of [/regexp as a rule/, a character as a type of token, function to applay the value of token] elements. A Parse class object is created with a parse_rule which is an array of [/regexp as a rule/, type of token after reduction, function to apply when match]. A sample program is attached. |
| 197 | Jaccard's and Simple Matching Coefficients | Derick Fay |
| Calculate Jaccard's Coefficient, Simple Matching Coefficients, and Simple Matching Distance for a pair of vectors. Written for clarity. |
| 198 | math ( SWEDISH ) | Ale cson |
| simple sccript to calculate math? |
| 275 | PEG parser generator class | Tomokiyo Nomura |
| PEG parser gennerator class. The grammar described by PEG will be easily implemented using Peg class. An example program is attached. |
| 302 | Round to closest multiple of... | Skye Weir-Mathews |
| You pass this function a number you want you rounded, and the multiple you want it rounded to and it passes back the rounded number. |
| 343 | Language Numbers | zhang bee |
| Language Numbers |
| 345 | EnglishNumerals | zhang bee |
=begin
While we normally write numbers using Arabic (or since Quiz #22,
Roman) numerals, numbers can also be written out as English phrases.
For example:
7 == seven (the hard way)
42 == forty-two (a very important number)
2001 == two thousand and one (a space odyssey)
1999 == (party like it's) nineteen hundred and ninety-nine
So the quiz is a problem from a Pi Mu Epsilon (US national math club)
newsletter:
"When the integers 1 to 10_000_000_000 are written in the English
language, then sorted as strings, which odd number appears first in
the list?"
- Create Ruby code to translate a number to it's English language form.
- Determine programatically which odd number in 1..10_000_000_000
would sort first if written in English. (Brute force is the obvious
solution, but the computer may have to think about it...)
- Would the answer change for a larger range of values, say 10**30?
- Do French and German Rubyists get a different answer than the
Americans?
=end |
| 445 | MathExt | Dick Pountain |
| Provides a Factorize function and enhances the print formats (to_s method) of Ruby's built-in Complex, Floatand Rational types |
| 446 | Surds | Dick Pountain |
| Adds a new class Surd to Ruby, which permits arithmetic using irrational roots like √2 and √3. Also provides a function to find the roots of a quadratic equation in terms of surds, rather than floats. |
| 481 | Between | Mahmoud Abu Arafeh |
| check if num between r1 and r2 |
| 522 | Use raphaeljs to create graph with ruby data | Daihua ye |
| Use raphaeljs to create graph with ruby data |