Skip to content

Instantly share code, notes, and snippets.

@mechamogera
mechamogera / jmockit_System_getenv.java
Created May 22, 2012 12:03
jmokitによる環境変数(System.getenv())の追加
package mymock.test;
import junit.framework.TestCase;
import mockit.Mocked;
import mockit.NonStrictExpectations;
import java.util.Map;
public class SystemTest extends TestCase {
private Map<String, String> envs = null;
@mechamogera
mechamogera / capybara_dsl_test.rb
Created May 22, 2012 12:54
capybara(webdriver)を用いてyahooで検索する
# -*- encoding: UTF-8 -*-
gem 'capybara', '>= 1.1.2'
gem 'selenium-webdriver' ,'>= 2.20.0'
require 'capybara'
require 'capybara/dsl'
require "selenium-webdriver"
include Capybara::DSL
# ENV['HTTP_PROXY'] = ENV['http_proxy'] = nil # proxyを使わない場合
@mechamogera
mechamogera / getCsvLastLineFirstColumnValue.js
Created July 2, 2012 12:23
最終行の最初のカラムを数値として取得するjavascriptのサンプル
function getCsvLastLineFirstColumnValue(text) {
var lines = text.split("\n");
var i = 0;
for (i = 0; i < lines.length; i++) {
var items = lines[lines.length - 1 -i].split(",");
var val = parseInt(items[0].replace("\"", ""));
if (isFinite(val)) { // <= NG: val != Number.NaN
return val;
}
}
@mechamogera
mechamogera / show_ec2_dnsname_and_tags.rb
Created August 8, 2012 12:27
全てのEC2インスタンスのDNS名とタグ表示
gem 'aws-sdk'
require 'rubygems'
require 'aws-sdk'
ec2 = AWS::EC2.new(:access_key_id => nil,
           :secret_access_key => nil,
:proxy_uri => ENV['HTTPS_PROXY'] || ENV['https_proxy'] || ENV['HTTP_PROXY'] || ENV['http_proxy'])
ec2 = ec2.regions['ap-northeast-1']
ec2.instances.each do |x|
puts x.dns_name
@mechamogera
mechamogera / show_title.js
Created August 9, 2012 04:30
タイトル表示ブックマークレット
javascript:(function(){window.alert(document.title)})();
@mechamogera
mechamogera / s3_downloader.rb
Created August 9, 2012 06:08
AWSの簡易S3ダウンロードRubyスクリプト
require 'rubygems'
gem 'aws-sdk'
require 'aws'
require 'optparse'
access_key_id = nil
secret_access_key = nil
endpoint = 's3-ap-northeast-1.amazonaws.com'
bucket = nil
object_key = nil
@mechamogera
mechamogera / use_rails_model.rb
Created September 4, 2012 08:14
rails外のスクリプトからモデルを使用してみる
#!/bin/env ruby
RAILS_BASE = "/my/rails/dir/"
require RAILS_BASE + 'config/environment'
dbconfig = YAML.load_file(RAILS_BASE + 'config/database.yml')['production']
ActiveRecord::Base.establish_connection(dbconfig)
p User.all
@mechamogera
mechamogera / Gemfile
Last active March 15, 2018 22:46
AWSの簡易S3アップロードRubyスクリプト
# A sample Gemfile
source "https://rubygems.org"
gem 'aws-sdk'
gem 'mime-types'
@mechamogera
mechamogera / print_access_key_on_ec2.rb
Created September 5, 2012 02:20
EC2上で設定したroleのAccessKeyを取得するRubyスクリプト
require 'uri'
require 'json'
require 'net/http'
role = Net::HTTP.get(URI.parse("http://169.254.169.254/latest/meta-data/iam/security-credentials/"))
ret = Net::HTTP.get(URI.parse("http://169.254.169.254/latest/meta-data/iam/security-credentials/#{role}"))
dat = JSON.parse(ret)
puts dat["AccessKeyId"]
puts dat["SecretAccessKey"]
@mechamogera
mechamogera / HelloWorld.as
Created September 5, 2012 23:51
action script3のhello world
package {
import flash.display.*;
import flash.text.*;
public class HelloWorld extends Sprite {
public function HelloWorld () {
var textField:TextField = new TextField();
textField.text = "Hello World";
addChild(textField);
}