Skip to content

Instantly share code, notes, and snippets.

@mechamogera
mechamogera / jmockit_System_getenv.java
Created May 22, 2012
jmokitによる環境変数(System.getenv())の追加
View jmockit_System_getenv.java
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
capybara(webdriver)を用いてyahooで検索する
View capybara_dsl_test.rb
# -*- 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 Jul 2, 2012
最終行の最初のカラムを数値として取得するjavascriptのサンプル
View getCsvLastLineFirstColumnValue.js
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 Aug 8, 2012
全てのEC2インスタンスのDNS名とタグ表示
View show_ec2_dnsname_and_tags.rb
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 Aug 9, 2012
タイトル表示ブックマークレット
View show_title.js
javascript:(function(){window.alert(document.title)})();
@mechamogera
mechamogera / s3_downloader.rb
Created Aug 9, 2012
AWSの簡易S3ダウンロードRubyスクリプト
View s3_downloader.rb
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 Sep 4, 2012
rails外のスクリプトからモデルを使用してみる
View use_rails_model.rb
#!/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 Mar 15, 2018
AWSの簡易S3アップロードRubyスクリプト
View Gemfile
# A sample Gemfile
source "https://rubygems.org"
gem 'aws-sdk'
gem 'mime-types'
@mechamogera
mechamogera / print_access_key_on_ec2.rb
Created Sep 5, 2012
EC2上で設定したroleのAccessKeyを取得するRubyスクリプト
View print_access_key_on_ec2.rb
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 Sep 5, 2012
action script3のhello world
View HelloWorld.as
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);
}