Skip to content

Instantly share code, notes, and snippets.

@tomoyamkung
tomoyamkung / array-to-tempfile.rb
Created July 29, 2013 04:17
[Ruby]Arrayを Tempfile に書き出すモジュール
#! ruby
#-*- encoding: utf-8 -*-
module ArrayToTempfile
require 'tempfile'
def write_array_to_tempfile(basename, array)
@tempfile = Tempfile.new(basename)
array.each do |line|
@tempfile.puts(line)
@tomoyamkung
tomoyamkung / array-to-file.rb
Last active August 18, 2017 01:40
[Ruby]Arrayをファイルに書き出すモジュール
#! ruby
#-*- encoding: utf-8 -*-
module FileWriter
LINEFEED_CODE_LF = "\n"
def write(path, content, linefeed_code = nil)
file = File.open(path, "w")
content.each do |line|
if linefeed_code == nil
@tomoyamkung
tomoyamkung / file-to-array.rb
Last active December 20, 2015 08:39
[Ruby]ファイルの内容をArrayに書き出すモジュール
#! ruby
#-*- encoding: utf-8 -*-
module FileReader
DELETE_LINEFEED_CODE = true
KEEP_LINEFEED_CODE = !DELETE_LINEFEED_CODE
def read(path, delete_linefeed_code = true)
content = Array.new
File.open(path, "r") do |file|
@tomoyamkung
tomoyamkung / redcarpet.rb
Last active December 20, 2015 06:49
[Ruby]Markdownをパースするスニペット
#! ruby
#-*- encoding: utf-8 -*-
module MarkDownParser
require 'redcarpet'
def parse_with_redcarpet(str)
return Redcarpet::Markdown.new(Redcarpet::Render::HTML).render(str)
end
@tomoyamkung
tomoyamkung / pom.xml
Last active December 19, 2015 17:59
[Java]Mavenのmaven-antrun-pluginを使ってディレクトリを作成する
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>gen-dir</id>
<phase>validate</phase>
@tomoyamkung
tomoyamkung / embed.html
Created July 12, 2013 07:28
[JavaScript]jQuery.socialbutton プラグインを自分のブログに組み込むときに作成したスクリプト。
<!-- ボタンを設置したい場所に次を埋め込む -->
<ul id="social_buttons">
<li class="tweet"></li> <!-- twitter -->
<li class="evernote"></li> <!-- Evernote -->
<li class="facebook_like"></li> <!-- Facebook -->
<li class="hatena"></li> <!-- はてなブックマーク -->
<li > <!-- Pocket -->
<a data-pocket-label="pocket" data-pocket-count="horizontal" class="pocket-btn" data-lang="en"></a>
<script type="text/javascript">!function(d,i){if(!d.getElementById(i)){var j=d.createElement("script");j.id=i;j.src="https://widgets.getpocket.com/v1/j/btn.js?v=1";var w=d.getElementById(i);d.body.appendChild(j);}}(document,"pocket-btn-js");</script>
</li>
@tomoyamkung
tomoyamkung / GoogleAnalyticsTrack.java
Last active December 19, 2015 09:09
[Android]Google Analytics へのトラッキングを行うクラス
/**
* Google Analytics へのトラッキングを行うクラス。
*
* @author tomoyamkung
*
*/
public class GoogleAnalyticsTrack {
private Tracker tracker;
@tomoyamkung
tomoyamkung / FileUtil.java
Created June 13, 2013 07:07
[Java]ファイルに関するユーティリティ
/**
* File オブジェクトとそのオブジェクトが表す実ファイルを作成する。
*
* @param parent ファイルを作成するディレクトリ
* @param fileName ファイル名
* @return 作成したファイルオブジェクト
* @throws IOException ファイルの作成に失敗した場合
*/
public static File create(File parent, String fileName) throws IOException {
File file = new File(parent, fileName);
@tomoyamkung
tomoyamkung / DirectoryUtil.java
Created June 13, 2013 06:59
[Java]ディレクトリに関するユーティリティ
/**
* ディレクトリを作成する。
*
* @param 作成するディレクトリのパス
* @throws IOException
*/
public static File createDirectory(String path) throws IOException {
File dir = new File(path);
if(!dir.exists()) {
FileUtils.forceMkdir(dir);
@tomoyamkung
tomoyamkung / OpenDefaultBrowser.java
Last active April 8, 2020 23:45
[Android]WebView に表示されているリンクをデフォルトブラウザで開く
/* (non-Javadoc)
* @see android.app.Activity#onCreate(android.os.Bundle)
*/
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// :
// :
WebView webView1 = (WebView)findViewById(R.id.webView1);