iPod touchに大量の写真を保存する1つの方法
タイトルはあれですが、まあようするに画像サイズを小さくすればいいですよねというお話です。
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ResizePhoto { class Program { static void Main(string[] args) { var sourceDir = @"D:\Pictures\dist"; var distDir = @"D:\Pictures\dist2\"; var widthPx = 400; var files = System.IO.Directory.GetFiles(sourceDir, "*.jpg", System.IO.SearchOption.AllDirectories); resize(distDir, files, widthPx); } private static void resize(string distDir, string[] files, int widthPx) { files.ToList().ForEach( file => { var img = System.Drawing.Image.FromFile(file); var heightPx = (int)((float)img.Height * ((float)widthPx / (float)img.Width)); var thumbnail = new System.Drawing.Bitmap(widthPx, heightPx); using (var g = System.Drawing.Graphics.FromImage(thumbnail)) { g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; g.DrawImage(img, 0, 0, widthPx, heightPx); } thumbnail.Save(distDir + System.IO.Path.GetFileName(file)); }); } } }
urlからファイル名を取得
def get_filename url url =~ /([^\/]+?)([\?#].*)?$/ $& end url = "http://www.example.co.jp/foo/bar/image.jpg" filename = get_filename url p filename # image.jpg
共有フォルダの設定
いつも忘れるのでメモ
mount -t vboxsf share ~/share
単語の単数形と複数形を確認
ruby script/console # 複数形の確認 p "task".pluralize #=> "tasks" # 単数形の確認 p "tasks".singularize #=> "task"
restful_authenticationプラグインの使い方
restful_authenticationプラグインをインストール
script/plugin source http://svn.techno-weenie.net/projects/plugins
script/plugin install restful_authentication
認証用コンポーネントの生成
script/generate authenticated user sessions
テーブルの作成
rake db:migrate
config/routes.rbを編集
以下の5行を追加
map.resources :users map.resource :session map.signup '/signup', :controller => 'users', :action => 'new' map.login '/login', :controller => 'sessions', :action => 'new' map.logout '/logout', :controller => 'sessions', :action => 'destory'
app/controllers/application.rbを編集
includeを追加
include AuthenticatedSystem
認証が必要なviewにフィルタを設定
before_filter :login_required
will_paginateを使ったページング
will_paginateプラグインをインストール
sudo gem sources -a http://gems.github.com sudo gem install mislav-will_pagnate
config/envoironment.rbの修正
以下を追加する
config.gem 'mislav-will_paginate', :lib => 'will_paginate'
controllerの修正
indexアクションを以下のように修正
#@tasks = Task.find(:all) @tasks = Task.paginate :page => params[:page]
viewの修正
indexビューに以下を追加
<%= will_paginate(@tasks) %>