Skip to content

Instantly share code, notes, and snippets.

View google urlshortner with ruby
require "net/http"
require "net/https"
require "rubygems"
require "json"
HOST="www.googleapis.com"
PORT=443
API_URL="/urlshortener/v1/url?key=YOUR-API key"
def shorten_url long_url
@suganoo
suganoo / gist:5477068
Created Apr 28, 2013
railsでデータベーステーブルの参考例
View gist:5477068
class CreateUsers < ActiveRecord::Migration
def self.up
create_table :users do |t|
t.string :uid, :null => false
t.string :name, :null => false
t.timestamps
end
add_index :users, [:uid]
end
View gistテスト.md

gist のサンプル

どんな風に表示されるのかな

@suganoo
suganoo / ArgumentParse
Created Sep 5, 2017
ArgumentParserの使い方
View ArgumentParse
import argparse
if __name__ == "__main__":
### define config
parser = argparse.ArgumentParser(description='This script is ...')
parser.add_argument("-c", "--configpath", required=True, help='config file path')
parser.add_argument("-l", "--logtype", required=True, help='logtype ex. hogefuga')
args = parser.parse_args()
hg = Hogehoge(args.configpath, args.logtype)
@suganoo
suganoo / echoで色を付ける
Last active Sep 5, 2017
echoの出力で色づけする方法
View echoで色を付ける
echo -e "\e[30m黒色"
echo -e "\e[31m赤色"
echo -e "\e[32m緑色"
echo -e "\e[33m黄色"
echo -e "\e[34m青色"
echo -e "\e[35m赤紫色(マゼンタ)"
echo -e "\e[36m水色(シアン)"
echo -e "\e[37m白色"
@suganoo
suganoo / logging property
Last active Sep 5, 2017
logging propertyのフォーマット
View logging property
[loggers]
keys=root,hogehogetool
[handlers]
keys=defaultHandler,hogehogetoolHandler
[formatters]
keys=simpleFormatter
[logger_root]
@suganoo
suganoo / ConfigParser使い方
Last active Sep 5, 2017
ConfigParserの使い方
View ConfigParser使い方
import ConfigParser
inifile = ConfigParser.SafeConfigParser()
inifile.read("xxxxxx/config.ini")
param = inifile.get("common", "hogehoge_param")
aws_key_id = inifile.get("aws","aws_key")
@suganoo
suganoo / tqdm pattern 01
Created Sep 5, 2017
プログレスバー使い方
View tqdm pattern 01
from time import sleep
from tqdm import tqdm
for i in tqdm(range(100)):
sleep(0.1)
@suganoo
suganoo / config.ini
Created Sep 7, 2017
ConfigParserでkeyの存在確認する
View config.ini
[main]
aaaa = hogehoge
bbbb = fugafuga
cccc = mogumogu
You can’t perform that action at this time.