Skip to content

Instantly share code, notes, and snippets.

@urara
urara / url_shorter2015.rb
Last active August 29, 2015 14:21
現状の全力
require 'webrick'
h,s,o={},WEBrick::HTTPServer.new(:Port=>3333),[*?a..?z]
s.mount_proc('/'){|q,b|t,r=h[q.unparsed_uri[1..-1]],((0..4).map{o[rand(26)]}.*'')
q.request_method=='GET'?b.set_redirect(WEBrick::HTTPStatus::Found,t):(h[r]=q.body)&&b.body="http://localhost:3333/#{r}"}
s.start
@urara
urara / URL_Shortener.rb
Last active August 29, 2015 14:00 — forked from taichi/Rx.java
Rubyで書いた、もっと行けるはず
require 'webrick'
h, s, o = {}, WEBrick::HTTPServer.new(:Port => URI.parse('http://localhost:3333/').port), [('a'..'z'), ('A'..'Z'), ('0'..'9')].map { |i| i.to_a }.flatten
for url in ARGV
h[(0...5).map { o[rand(o.length)] }.join] = url
end
p h
s.mount_proc('/'){|req, res| res.set_redirect(WEBrick::HTTPStatus::Found, h[req.unparsed_uri[1..-1]]) }
s.start
@urara
urara / url_shorter.rb
Created April 20, 2014 14:21
url短縮サービス、引数でURL渡すとリストで返るよ
require 'webrick'
url_hash = {}
sv = WEBrick::HTTPServer.new(:Port => URI.parse('http://localhost:3333/').port)
o = [('a'..'z'), ('A'..'Z'), ('0'..'9')].map { |i| i.to_a }.flatten
for url in ARGV
url_hash[(0...5).map { o[rand(o.length)] }.join] = url
end
p url_hash
sv.mount_proc('/'){|req, res|
res.set_redirect(WEBrick::HTTPStatus::Found, url_hash[req.unparsed_uri[1..-1]])
@urara
urara / getFileOwnerName.rb
Created February 13, 2013 17:32
関数とかにはしてない、使うならその内するかも、結果から感じ取れるはず。
require 'etc'
p Etc.getlogin
p s= File::stat("/Users/hoge/fuga.rb").uid
p Etc.getpwuid(s).name
@urara
urara / getTweet.rb
Last active December 11, 2015 09:28
get tweet from ruby library(Twitter 4.4.4)
# coding: utf-8
require "twitter"
require 'pp'
YOUR_CONSUMER_KEY = "hoge"
YOUR_CONSUMER_SECRET = "hoge"
YOUR_OAUTH_TOKEN = "hoge"
YOUR_OAUTH_TOKEN_SECRET = "hoge"
Twitter.configure do |config|
@urara
urara / .vimrc
Last active December 10, 2015 00:58
いつかさいきょうにしたい.vimrcNeoBundleで欲しいもの集めた主にRubyとJavaScript編集用新たな環境ではコメントにあるコマンドを入力してNeoBundle取得する
set nocompatible " be iMproved
filetype off
if has('vim_starting')
set runtimepath+=~/.vim/bundle/neobundle.vim
call neobundle#rc(expand('~/.vim/bundle/'))
endif
" originalrepos on github
NeoBundle 'Shougo/neobundle.vim'
NeoBundle 'Shougo/vimproc', {
@urara
urara / gist:3828692
Created October 3, 2012 18:09
Excelからの読み込み、書き出し http://jp.rubyist.net/magazine/?0004-Win32OLE
#! ruby -Ks
# -*- coding: sjis -*-
require 'win32ole'
module Worksheet
def [] y,x
cell = self.Cells.Item(y,x)
if cell.MergeCells
cell.MergeArea.Item(1,1).Value
@urara
urara / gist:3228969
Created August 1, 2012 17:23
RegExp、こんな感じかな?(微妙に意図する所と変わってしまった、%dとかみたいに動く)
function printf(format){
for(var i = 1; i < arguments.length; i++){
var pattern = /\{\w\}/;
//var pattern = new RegExp('\\{' + (i -1) + '\\}', 'g');
format = format.replace(pattern, arguments[i]);
}
document.writeln(format);
}
@urara
urara / gist:3217877
Created July 31, 2012 15:36
JavaScriptテスト
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=UTF-8" />
<title>Hello World ! </title>
</head>
<body>
<script>
var data = [];
if (typeof data == 'object' & data instanceof Array) {
document.writeln("It's Array!!");
@urara
urara / gist:3052919
Created July 5, 2012 10:44
巨大なファイルの文字列置換
#encode :utf-8
Encoding.default_external = 'utf-8'
i = 1
befline = ""
open("test.log").each do |line|
line = befline + line
line.gsub!(/test/im, 'nya-')
#line.gsub!(/te.st/im, 'Pr\noj')
open("result.txt", "a"){|f| f.write line}
i = i + 1