Skip to content

Instantly share code, notes, and snippets.

@shunsugai
shunsugai / compare.rb
Created September 25, 2011 15:58
Test.
#encoding: utf-8
class String
def make_ngram(n)
ary = self.split(//)
ngram_ary = []
p = ary.length
for i in 0..(p - n) do
ngram_ary << ary[i...(i + n)]
end
class Foo
def self.foo(method)
define_method(method) do
puts "Foo##{method} called."
end
end
foo :bar
foo :baz
end
class Bar
class << self
def self.bar(method)
define_method(method) do
puts "Bar.#{method} called."
end
end
bar :foo
bar :baz
#tweetから記事リンクがあるものだけを取得する。
#coding utf-8
require 'twitter'
require 'net/http'
require 'uri'
class LinkGrabber
def initialize(user)
@shunsugai
shunsugai / check_rss.rb
Created July 19, 2012 01:42
RSSがWellformedかどうかを調べる
#coding: UTF-8
require 'rss'
class RSSChecker
def initialize
@blogs =
[
"http://lifehack2ch.livedoor.biz/index.rdf",
"http://www.scienceplus2ch.com/index.rdf",
"http://blog.livedoor.jp/domesaka/index.rdf",
@shunsugai
shunsugai / sample.xml
Created July 25, 2012 15:46
samplexml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="sample">
<item>FOO</item>
<item>BAR</item>
<item>BAZ</item>
</string-array>
</resources>
@shunsugai
shunsugai / MyAdapter.java
Created July 29, 2012 09:06
AndroidのListViewで非同期で画像を表示する
package com.sugaishun.sample;
import java.io.InputStream;
import java.net.URL;
import java.util.List;
import java.util.Locale;
import org.joda.time.DateTime;
import android.content.Context;
@shunsugai
shunsugai / ImageCache.java
Created July 29, 2012 09:45
AndroidのListViewで非同期で画像を表示する
package com.sugaishun.sample;
import java.util.HashMap;
import android.graphics.drawable.Drawable;
public class ImageCache {
private static HashMap<String, Drawable> cache = new HashMap<String, Drawable>();
public static Drawable get(String key) {
@shunsugai
shunsugai / removeAd.js
Created August 6, 2012 05:11
removeAd
var classes = [
'plugin-free_area plugin-box',
'maist'
];
var ids = [
'ad'
];
var removeAdByClass = function(className) {
@shunsugai
shunsugai / android_gradient.xml
Created August 26, 2012 06:07
Android rich gradient drawable
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<!-- ベースのグラデーション -->
<item android:state_pressed="true">
<shape android:shape="rectangle">
<gradinent
android:angle="270"
android:endColor="#009FD9"
android:startColor="#55CBF6" />
</shape>