Skip to content

Instantly share code, notes, and snippets.

@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')

Javascript Notes

syntax

function f(parameter1, paremeter2) { // define function
		argument1 = parameter1; // pass parameters in as arguments
		argument2 = parameter2;
 return argument1 + argument2;
@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
@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 / 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 / problem11.rb
Created October 1, 2012 16:38
Project Euler: Problem 11
grid_string = <<EOS
08 02 22 97 38 15 00 40 00 75 04 05 07 78 52 12 50 77 91 08
49 49 99 40 17 81 18 57 60 87 17 40 98 43 69 48 04 56 62 00
81 49 31 73 55 79 14 29 93 71 40 67 53 88 30 03 49 13 36 65
52 70 95 23 04 60 11 42 69 24 68 56 01 32 56 71 37 02 36 91
22 31 16 71 51 67 63 89 41 92 36 54 22 40 40 28 66 33 13 80
24 47 32 60 99 03 45 02 44 75 33 53 78 36 84 20 35 17 12 50
32 98 81 28 64 23 67 10 26 38 40 67 59 54 70 66 18 38 64 70
67 26 20 68 02 62 12 20 95 63 94 39 63 08 40 91 66 49 94 21
24 55 58 05 66 73 99 26 97 17 78 78 96 83 14 88 34 89 63 72
@raywu
raywu / problem9.rb
Created March 19, 2012 03:42
Project Euler problem 9
found = false
(1..1E3).each { |x|
(1..1E3).each { |y|
puts "a = #{x}, b = #{y}, c = #{1000 - x - y}, product = #{x * y * (1000 - x - y)}"
found = true if x ** 2 + y ** 2 == (1000 - x - y) ** 2
break if found
}
break if found
}
@raywu
raywu / development.rb
Created March 18, 2012 15:59
OmniAuth authentication keys environment handling
Tourious::Application.configure do
# Settings specified here will take precedence over those in config/application.rb
TWITTER_KEY = 'Development Keys'
TWITTER_SECRET = 'Development Secret'
FACEBOOK_KEY = 'Development Keys'
FACEBOOK_SECRET = 'Development Secret'
# In the development environment your application's code is reloaded on
# every request. This slows down response time but is perfect for development
@raywu
raywu / user.rb
Created March 18, 2012 15:37
User model, modified omniauth sessions scraper, and created a smoke-screen search
class User < ActiveRecord::Base
has_many :events
has_many :ratings
has_many :messages
belongs_to :profile
def self.create_with_omniauth(auth)
create! do |user|
user.provider = auth["provider"]
user.uid = auth["uid"]
@raywu
raywu / seeds.db
Created March 18, 2012 15:32
Enumerate database seeds
questions = [
'How spontaneous of a traveler are you?',
'Do you drink alcohol?',
'Do you smoke cigarettes?',
'Do you like to know how things work?',
'I always like to try new things:',
'How religious are you?',
'In general, it is important to follow the rules:',
'Are you sensitive to others\' needs?'
]