Skip to content

Instantly share code, notes, and snippets.

View yswallow's full-sized avatar

Sanagi yswallow

View GitHub Profile
@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;
@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 / 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 / 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 / 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 / twitter_links_only.rb
Created February 23, 2013 08:32
リンクのついてないツイートなんて不要だ。
@yswallow
yswallow / gist:5134507
Created March 11, 2013 14:12
git status から変更された.rbファイル名だけを表示する
$ git status | ruby -ne '/modified:\s+(.+?\.rb)/ =~ $_ ; print $1," " if $1'
=>
a.rb
b.rb
@yswallow
yswallow / totsuzen.rb
Created March 13, 2013 06:16
_人人人人人人人人_ > 突然のやる気 <  ̄Y^Y^Y^Y^Y^Y^Y^Y ̄
#coding: UTF-8
module Totsuzen
def totsuzen(str = "突然の死")
str_length = 0
str.each_char do |c|
str_length += (c.bytesize > 1) ? 2 : 1
end
str_length /= 2
result = "_人#{ "人" * str_length }人_\n"
result << "> #{str} <\n"
@yswallow
yswallow / yosan_up.rb
Created March 14, 2013 13:57
JR四国のサイトから予讃線・上りの時刻表の画像ファイルをダウンロードするスクリプト
require 'open-uri'
Dir.mkdir("yosan_up") unless FileTest.exist? "yosan_up"
("01".."18").each do |i|
url = "http://www.jr-eki.com/timetable/yosan_up-seto/img/#{i}.gif"
image = open(url).read
File.write("yosan_up/" + i + ".gif",image)
end
@yswallow
yswallow / soinsubunkai.c
Created March 20, 2013 03:21
素因数分解をするプログラム。 掃除してたら出てきたから書きなおしてみた。(昔は割ったあとのfloat==intかどうかで判断してたなんて言えない)
#include <stdio.h>
#include <stdlib.h>
int main(int argc,char *argv[])
{
unsigned int a,b,amari,i;
if(argc<2)
{
printf("整数を入力してください。\n");