Skip to content

Instantly share code, notes, and snippets.

@raywu
raywu / ProjectEuler12.rb
Created October 17, 2012 03:20
Attempt to re-write the code
#Problem 12:
# The sequence of triangle numbers is generated by adding the natural numbers. So the 7th triangle number would be 1 + 2 + 3 + 4 + 5 + 6 + 7 = 28. The first ten terms would be:
# 1, 3, 6, 10, 15, 21, 28, 36, 45, 55, ...
# Let us list the factors of the first seven triangle numbers:
# 1: 1
# 3: 1,3
# 6: 1,2,3,6
@raywu
raywu / ConsoleRubyGems.rb
Created October 20, 2012 06:06
RubyGems.org doesn't work in China
$ bundle install
Fetching gem metadata from http://rubygems.org/.
Error Bundler::HTTPError during request to dependency API
Fetching full source index from http://rubygems.org/
^C
Quitting...
@raywu
raywu / guess.rb
Created March 3, 2013 12:31
Bruce Tate's 7 Languages in 7 weeks, Ch. 2.2, Bonus Question: If you're feeling the need for a little more, write a program that picks a random number. Let a player guess the number, telling the player whether the guess is too low or too high.
def guess
x = rand(10)
puts "I have a number between 0-10 in mind? What is your best guess?"
y = gets.chomp!.to_i
if x == y
print "you got it!"
elsif x < y
print "You are about #{y-x} too high in your guess.\n"
print "Hint, x is #{x}"
else x > y

Javascript Notes

syntax

function f(parameter1, paremeter2) { // define function
		argument1 = parameter1; // pass parameters in as arguments
		argument2 = parameter2;
 return argument1 + argument2;
@raywu
raywu / repace-date-string.gs
Created August 24, 2017 20:36
replace date string in Google Documents using Apps Script
var monthNames = [
"January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"
];
function onOpen() {
var ui = DocumentApp.getUi();
// Or FormApp or SpreadsheetApp.
ui.createMenu('Macro')
.addItem('Update last modified date', 'replaceFormattedDate')