Skip to content

Instantly share code, notes, and snippets.

View yswallow's full-sized avatar

Sanagi yswallow

View GitHub Profile
@yswallow
yswallow / encode.rb
Created December 2, 2012 03:07
Nokogiriの文字化け対策
require 'nokogiri'
require 'open-uri'
require 'kconv'
url = ARGV[0] ? ARGV[0].chomp : "http://blogs.yahoo.co.jp/ikedadamu/6739054.html"
encode = ARGV[1] ? ARGV[1].chomp : nil
page = Nokogiri::HTML(open(url),encode)
puts page.to_html.toutf8
@yswallow
yswallow / expand_url.rb
Created November 17, 2012 11:52
短縮URLの展開
require 'net/http'
require 'uri'
def expand_url(url)
uri = url.kind_of?(URI) ? url : URI.parse(url)
begin
Net::HTTP.start(uri.host, uri.port) do |io|
r = io.head(uri.path)
r['Location'] ? expand_url(r['Location']) : uri.to_s
end
@yswallow
yswallow / twitter_client.rb
Created October 21, 2012 13:59
Twitterのクライアントを調べる
# encoding: UTF-8
require 'twitter'
Twitter.configure do |config|
config.consumer_key = 'consumer_key'
config.consumer_secret = 'consumer_secret'
config.oauth_token = 'oauth_token'
config.oauth_token_secret = 'oauth_token_secret'
end
@yswallow
yswallow / helloworld
Created April 25, 2012 09:59
C言語とRubyのどちらでも動くHelloWorld
#include <stdio.h> /*
=begin
*/
//C言語の記述
int main(void)
{
printf("Hello,World!\n");
return 0;
}
/*
@yswallow
yswallow / gist:1789357
Created February 10, 2012 12:27
print_num_as_char
#include <stdio.h>
#include <string.h>
int main(void)
{
FILE *fpb;
char str[100],filename[100];
//char str2[]=".c"
char check;
int length,flength,i;