This is the code I frequently use.
It recursively exports file list in a directory on Microsoft Office Application, like Excel. It is written in VBA.
VBA can be written in object oriented way, but I didn’t because I had to write the code as soon as possible.
Process Flow
A user clicks the button on the sheet.
The program show a folder browsing dialog.
User chooses the folder, then the program make the list of file in the folder.
The program exports the file list onto a form (or sheet).
To Do
Create a module file and create the following functions.
get file list
handle folder browsing dialog
Create a dialog to show the result.
Create a button on the sheet and add function on clicking.
Continue reading VBA: Output file list in a directory, recursively →
I will introduce the way to edit and save files at the remote server, on my local machine, and other alternative way.
Story
At the company, everyone develops the program on the remote server. Yes, it is Linux server with dark terminal, which provides only vim editor. The server can’t connect to public internet, so we need to upload tools with WinSCP from local machine if we want.
ローカルマシンで開発環境を構築するにも、いろんなチームが開発した多様なライブラリがないと動かないようになっていたため、ローカルマシンの環境を構築するのは困難な状況でした。 ファイアウォールの接続制限なんかもあって。
So I decided to edit remote files directly on the local machine, which can connect to the internet and install rich editors.
ここからは、リモートのファイルを(擬似的に)直接編集できるエディタを紹介していきます。
インストールすれば編集可能になるエディタ
まずは、インストールさえすれば編集可能になるエディタを紹介します。 プラグインなどの追加インストールは不要です。
NetBeans
IDE なら簡単にできるんじゃないかと思って トライしてみたのが NetBeans です。実際のところ、とても簡単に思い通りのことができました。
保存時に自動でリモートマシンに保存してくれます。シンタックスチェックもやってくれます。
既存のリモートマシンのファイルを元にプロジェクトを作成して進めていくこともできますし、新たにプロジェクトを作ってそこからリモートマシンにアップロードすることもできます。
やりかたは、 NetBeans のページで紹介されていますので、そちらをご覧ください。
参考: NetBeans IDEを使用するリモートWebサーバーへのPHPアプリケーションのデプロイ
Komodo Edit
Follow Edit, Preference, and you can configure remote server. After configuration, it can edit remote files.
reference: Basic settings to use Komodo Edit (removed: http://shimz.me/blog/editor/148)
gedit
After some configuration, it can edit remote files.
reference: Use Gedit as Remote File Editor via FTP and SSH (Ubuntu) (removed: http://thecodecentral.com/2010/04/02/use-gedit-as-remote-file-editor-via-ftp-and-ssh-ubuntu)
プラグインなどをインストールすることで編集可能になるエディタ
ここから下は 別途プラグインなどのインストールをすることで、リモートファイルが編集可能になるエディタです。
Sublime Text 2
It can edit remote files with SFTP plugin.
reference: Sublime text SFTPをつかってリモートファイルをローカルで快適に編集
It can edit remote files with rsub plugin, which requires the server to install something.
reference: リモートサーバー上のファイルをローカルのSublime Text 2で編集する (deleted)
gVim
Windows マシン から、 PuTTY と連携して scp を使えるようにしようとしましたが、あえなく失敗。リモートマシンからファイルの一覧すら取得できませんでした。やり方を紹介しているサイトは多いのですが。
興味のある方は是非。
reference: vimからSSH/SCP接続してみる
I had to use groonga. The reason is simple, there is data only in groonga.
groonga も含め 全文検索エンジンを使うのは初めてだったので、 公式ドキュメントを見ながら探っていきました。 データベースで使用する SQL と groonga のクエリを比較してみると次のようになりました。 もともと別物なので参考程度に見ていただければと思います。
SELECT
We use SELECT
to get some data from groonga, also from database. But there’s considerable difference between the structure of data between groonga and database. As for groonga, sql command is like the following.
select -- table Site -- query title : @ test -- output_columns _id , _score , title -- sortby - _score , _id
Simple comparison is as follows.
Database
groonga
表示カラム
(listed after select
)
––output_columns
Table
from
––table
Search Condition
where
––filter
, ––query
, ––match_column
, ––scorer
Order
order by
––sortby
Offset
offset
––offset
Limit
limit
––limit
Group
group by
––drilldown
(drilldown したときの件数指定などは下の説明を参照)
Logical Operator
and
, or
&&
, ||
Supplemental Explanation
––output_columns
検索結果に表示するカラムを指定する。カンマで区切ることにより、複数カラムを指定できる。
select -- table Site -- output_columns column1 , column2
––query
全文検索を行う。
select -- table Site -- query title : @ this
title カラムについて 文字列 “this” の全文検索を行う。
––match_columns, ––query
検索結果に含めるカラムを指定する。複数指定もできる。
select -- table Site -- match_columns title -- query this
––query
と一緒に使い、 title カラムについて 文字列 “this” の全文検索を行う。
––filter
Specify query condition. Likewise javascript, we can use operator “==
”, “<=
“, “>
”, etc. AND
, OR
should be represented as &&
, ||
.
select -- table Site -- filter "_id <= 1" -- output_columns _id , _key
––drilldown
バージョン4.0.1 の資料を見るかぎり、 drilldown に指定したそれぞれのカラムについてグループ化した結果が表示される。 column_1 と column_2 を指定していれば、 column_1 だけでグループ化した結果と、 column_2 でグループ化した結果が続けて表示される。 ORDER BY column_1, column_2
のようなことはできない。
drilldown の結果に対する件数指定(オフセットなど)は下記のように、 通常の ––sortby
, ––offset
, ––limit
の頭に drilldown
をつけて指定する。 drilldown した結果だけがほしければ、 ––limit
に 0
を指定して出てくる通常カラムを制限する。
select -- table Site -- limit 0 -- drilldown country -- drilldown_sortby _nsubrecs -- drilldown _ limit 2 -- drilldown _ offset 2
Specific Column
Column Name
Description
_id
ID column whose is generated by groonga automatically in query.
_key
The column which contains primary key.
_score
Virtual column in query result. (Likewise ROWNUM
in Oracle DB.) It has higher number if the record matches to query condition more.
_nsubrecs
The column which contains query drilldown result number when drilldown
is used. It’s like COUNT
function in SELECT COUNT(1) FROM …
.
python のスクリプト(.py) を作って、スクリプト内で自分自身のファイル名を種痘する場合のお話です。
abc.py ファイル を実行した場合に、 abc.log のようなログファイルを作る際に使えます。
ここからは、次のようにしてモジュールを読み込む必要があります。
ディレクトリを除いたファイル名
ディレクトリに対してこれを実行すると、ディレクトリ名が取得できます。
ファイル名(拡張子なし)
path . splitext ( path . basename ( __file__ ) ) [ 0 ]
“.” で文字列を区切ってリストにします。 “a.b.c” のように “.” が2つ以上ある場合は 最後の “.” で区切って (“a.b”, “c”) を返します。
path.basename(__file__)[0] をファイルの存在するディレクトリで実行した場合も同じ結果になります。 (crontab などで実行すると思わぬ結果になります。 “a/b.py” が (“a/b”, “.py”) になります。)
お米1合はいくら(値段)になるでしょうか。茶碗1杯のお米はいくらになるでしょうか。 毎日弁当を持って行っているのですが、果たしてどれくらい節約になっているのか 気になりました。
前提条件
一般的な数字で計算します。 今回は次のようにします。
炊飯前の 1合 のお米は 150g
茶碗1杯は 0.5合
お米 10kg を 3,000円 で買う場合を想定します。 茶碗1杯のお米は 75g なので 3,000(円) ÷ 100,000(g) × 75(g) = 2.25(円) になります。 もうちょっとお米のブランドを上げて 1kg 4,000円 にすると、 茶碗1杯で 3円 になります。 1度にどれだけ炊飯するかによりますが、 炊飯にかかる電気代を含めても 茶碗1杯 あたり 13円 です(電気代は関東電気保安協会の値を使用)。
お弁当、是非持っていきましょう。 ごはんだけでも。
コンビニのおにぎりだったらいくら
コンビニのおにぎりはいくらのお米を使っているのでしょうか。 計算のため、次の前提をおきます。
コンビニのおにぎりに使われているお米は炊き上がり状態で 100g
150g のお米を炊くと 340g のごはんになる
コンビニのおにぎりは 100(g) × 150(g) ÷ 340(g) = 44g のお米に相当します。 先ほどの 10kg 3,000円 のお米では 44g は 3,000(円) ÷ 100,000(g) × 44g = 1.32(円) になります。
Posts navigation
A Life Summary of an Gypsy