This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #! /usr/bin/local/ruby | |
| # -*- encoding: utf-8 -*- | |
| class Vender | |
| @@customer = 0 | |
| def initialize(location="那覇", drink="Fantaウコン") | |
| @location = location | |
| @drink = drink | |
| @price = rand(9999) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #! /usr/bin/local/ruby | |
| # -*- encoding: utf-8 -*- | |
| pattern = 'foo' | |
| puts "pattern to match: " + pattern | |
| count = 0 | |
| match_count = 0 | |
| error_count = 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #! /usr/bin/local/ruby | |
| # -*- encoding: utf-8 -*- | |
| pattern = 'foo' | |
| new_pattern = 'bar' | |
| puts "pattern to be replaced: " + pattern | |
| puts "new pattern: " + new_pattern | |
| count = 0 | |
| replace_count = 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| jQuery(function($) { | |
| var _thisUrl = $(location).attr('href'); | |
| $.each($('a,area,input:image,input:submit'), function() { | |
| var _thisId = $(this).closest("[id]").attr("id"); | |
| $(this).click(function() { | |
| _gaq.push(['_trackEvent', _thisUrl, _thisId, $(this).attr('href')]); | |
| }); | |
| }); | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require "csv" | |
| #to begin with... save visits number as pv.csv, conversion number as cv.csv. | |
| def make_hash(file) | |
| h = {} | |
| s = CSV.open(file, "r") | |
| s.each do |row| | |
| # use row[1] for pageviews, row[2] for visits | |
| h[row[0]] = row[2].delete(",") if row[0] =~ /YOUR\.SITE\.COM\// |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # makes 2 csv files. kw has keywords. ko has no keywords but much easier to filter words and find duplicate texts. | |
| # works only utf8 htmls. | |
| # needs lots of refactoring... | |
| require 'rubygems' | |
| require 'hpricot' | |
| require 'open-uri' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| words = ["foobar", "bar"] | |
| words.each do |w| | |
| if w !~ /foobar/ && w =~ /bar/ | |
| puts w | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| contents = File.read(ARGV[0]) | |
| matched = [] | |
| matched << contents.scan(/puts "(.*?)"/) | |
| puts matched | |
| # % ruby find-and-output.rb hogehoge.rb > output.txt |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #! /usr/bin/local/ruby | |
| # -*- encoding: utf-8 -*- | |
| def prime?(num) | |
| 2.upto(num-1) do |x| | |
| if num % x == 0 | |
| true | |
| break | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #! /usr/bin/local/ruby | |
| # -*- encoding: utf-8 -*- | |
| #1 | |
| a = Array.new(100) {|x| x+1} | |
| #2 | |
| a2 = a.map {|x| x*100} | |
| a.map! {|x| x*100} # destructive |
OlderNewer