Skip to content

Instantly share code, notes, and snippets.

@cieux1
cieux1 / replace_part_of_csv_w_condition.rb
Last active December 17, 2015 13:29
URLと数が入った2つのcsvの同URL部分の数の上書き
def make_hash(csv)
# オーガニックcsvからURLと流入のハッシュ作成
hash = {}
open(csv) do |f|
while line = f.gets
/(.*?)\t(\d+)/ =~ line.sub("index.html", "")
hash[$1] = $2
end
end
hash
@cieux1
cieux1 / get_all_imgs_in_dirs.rb
Created March 31, 2013 09:13
ディレクトリ内の画像ファイルを一覧表示するhtmlを作成
def has_img_ext(f)
/(png|gif|jpg)$/ =~ f
end
files = Dir.glob("**/*.**")
puts "<html>"
files.each do |f|
puts "<img src=\"#{f}\" /><p>#{f}</p>" if has_img_ext(f)
end
@cieux1
cieux1 / analytics-core-api-memo
Created March 13, 2013 09:37
google docにanalyticsのデータを読み込む時のメモ
apiを使ってgoogle docにデータを自動読み込み
http://analytics.blogspot.jp/2012/08/automate-google-analytics-reporting.html
URLメイカー
http://ga-dev-tools.appspot.com/explorer/
使用可能なメトリクス
https://developers.google.com/analytics/devguides/reporting/core/dimsmets
@cieux1
cieux1 / make_bread.rb
Last active December 12, 2015 07:49
パンの焼き方
require 'oven'
require 'big_bowl'
class Bread
def initialize
first_ingredients = {
'Warm Water' => '220 ml', # add 5% more if half_milk
'flour' => '300 g'
'Yeast' => '6 g',
'Salt' => '6 g',
@cieux1
cieux1 / encode_files.rb
Created January 5, 2013 01:00
dir内のcsvファイルをutf-8からsjisに変換
# -*- encoding: utf-8 -*-
def encode_this(all_files)
all_files.each do |s|
f = open(s)
line = f.read.encode('sjis', 'utf-8')
file_name = "new_" + s
open(file_name, "w") do |w|
w.write line
end
@cieux1
cieux1 / gist:4133731
Last active October 13, 2015 03:38
へろこんめも
$ heroku login
$ heroku create app名
$ heroku config
# 環境変数確認
$ heroku config:add TZ=Asia/Tokyo
$ heroku run console
@cieux1
cieux1 / add_up_same_dir_counts.rb
Created November 15, 2012 09:02
csv内の同ディレクトリの数字をまとめる
#! /usr/bin/local/ruby
# -*- encoding: utf-8 -*-
def add_up_same_dir_counts(domain_name, file_name)
h = Hash.new
open(file_name) do |file|
while line = file.gets
if line =~ /(www\.#{domain_name}\/index\.html),(\d+?),/
h[$1] = $2.to_i
elsif line =~ /(www\.#{domain_name}\/.*?\/).*?,(\d+?),/
@cieux1
cieux1 / get_closest_id_name.js
Created September 28, 2012 02:34
google analytics event tracking : get closest id name when a user clicked a link or a button
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')]);
});
});
});
@cieux1
cieux1 / fetch_book_info_from_amazon.rb
Created September 20, 2012 08:38
amazon-ecsでisbnから商品情報をとってきてハッシュに入れる
require 'rubygems'
require 'amazon/ecs'
def fetch_info(isbn)
item_hash = {}
Amazon::Ecs.options = {
:associate_tag => 'YOUR_AMAZON_TAG',
:AWS_access_key_id => 'YOUR_ACCESS_KEY',
:AWS_secret_key => 'YOUR_SECRET_KEY'
@cieux1
cieux1 / count_div_tags.rb
Created August 21, 2012 09:14
count div and /div tags and see if they are the same numbers
#! /usr/bin/local/ruby
# -*- encoding: utf-8 -*-
files = Dir.glob("**/*.tpl")
file_count = 0
files.each do |file_name|
htmlname = File.dirname(file_name) + "/" + File.basename(file_name)
open(file_name) do |f|
div_open, div_close = [],[]