このあたりの記事をみて、.netのSmtpClientを使用して、
メールを送信しようとしたところ、
エラーがでて送信できなかった。
メーラー(Outlook)では、送信できるのに、と思って原因を探していたら、
ウィルス対策ソフトがブロックしていたみたいだった。
で、ウィルス対策ソフトを一時的に、Offにしてみたら、送信できた。
2016年12月17日土曜日
2016年11月20日日曜日
Emacs24のruby-modeで波カッコが入力できなくなった時
Emacs24には、デフォルトでruby-modeが組み込まれているため、
自分で古い ruby-modeを用意する必要がなくなったみたい。
単純に、自分で用意したruby-modeをPathの通っていない位置におくだけで
波カッコが入力できるようになった。
自分で古い ruby-modeを用意する必要がなくなったみたい。
単純に、自分で用意したruby-modeをPathの通っていない位置におくだけで
波カッコが入力できるようになった。
2016年10月18日火曜日
.netでローソク足と出来高表示
.netでローソク足と出来高を表示する
コンパイルは
csc ChartTest2.cs /r:System.Windows.Forms.DataVisualization.dll
結果はこんな感じ。
ただ、このままだと、上と下でY軸の線が合わずにみづらいので、
chart.ChartAreas["chart1"].AlignWithChartArea = "chart2";
を追加して、軸合わせする。
(上下の軸合わせしたいだけなのに、探すのに手間取った。
Chartクラスは、凄い便利だと思うけど、使い方に癖があって
慣れないと使いづらい。)
で、直した版はこんな感じ。
実行結果は、↓
軸があって見易くなった。
コンパイルは
csc ChartTest2.cs /r:System.Windows.Forms.DataVisualization.dll
using System.Runtime.InteropServices;
using System;
using System.Drawing;
using System.Drawing.Printing;
using System.Windows.Forms;
using System.Windows.Forms.DataVisualization.Charting;
public class ChartTest:Form
{
private Chart chart;
public ChartTest()
{
this.SuspendLayout();
Size = new Size(500,500);
SetChart();
this.ResumeLayout();
}
//チャート画面の作成
private void SetChart()
{
//チャート画面の作成
chart = new Chart();
//1つ目のチャートエリア
chart.ChartAreas.Add(new ChartArea("chart1"));
chart.ChartAreas["chart1"].AxisX.Interval = 5;
//2つ目のチャートエリア
chart.ChartAreas.Add(new ChartArea("chart2"));
//チャートエリアサイズ
chart.Size = new Size(400,400);
Controls.Add(chart);
//チャート1の描画
chart.Series.Add(new Series());
Series series;
series = chart.Series[0];
series.ChartArea = "chart1";
series.ChartType = SeriesChartType.Candlestick;
//データの作成(ローソク足)
int ii;
for(ii = 1; ii < 10 ; ii++)
{
double[] d = new double[4];
d[0] = ii * 10; // 高値
d[1] = ii * 3; // 安値
d[2] = ii * 5; // 始値
d[3] = ii * 8; // 終値
DataPoint dp = new DataPoint(ii,d);
series.Points.Add(dp);
}
//チャート2の描画(出来高)
chart.Series.Add(new Series());
Series series2;
series2 = chart.Series[1];
series2.ChartArea = "chart2";
series2.ChartType = SeriesChartType.StackedColumn;
//データの作成(出来高)
for(ii = 1; ii < 10 ; ii++)
{
DataPoint dp = new DataPoint(ii,ii*10000);
series2.Points.Add(dp);
}
}
public static int Main(string[] args)
{
ChartTest ct = new ChartTest();
ct.ShowDialog();
return 0;
}
}
ただ、このままだと、上と下でY軸の線が合わずにみづらいので、
chart.ChartAreas["chart1"].AlignWithChartArea = "chart2";
を追加して、軸合わせする。
(上下の軸合わせしたいだけなのに、探すのに手間取った。
Chartクラスは、凄い便利だと思うけど、使い方に癖があって
慣れないと使いづらい。)
で、直した版はこんな感じ。
using System;
using System.Drawing;
using System.Drawing.Printing;
using System.Windows.Forms;
using System.Windows.Forms.DataVisualization.Charting;
public class ChartTest:Form
{
private Chart chart;
public ChartTest()
{
this.SuspendLayout();
Size = new Size(500,500);
SetChart();
this.ResumeLayout();
}
//チャート画面の作成
private void SetChart()
{
//チャート画面の作成
chart = new Chart();
//1つ目のチャートエリア
chart.ChartAreas.Add(new ChartArea("chart1"));
chart.ChartAreas["chart1"].AxisX.Interval = 5;
//2つ目のチャートエリア
chart.ChartAreas.Add(new ChartArea("chart2"));
//チャートエリアサイズ
chart.Size = new Size(400,400);
Controls.Add(chart);
//チャート1の描画
chart.Series.Add(new Series());
Series series;
series = chart.Series[0];
series.ChartArea = "chart1";
series.ChartType = SeriesChartType.Candlestick;
//データの作成(ローソク足)
int ii;
for(ii = 1; ii < 10 ; ii++)
{
double[] d = new double[4];
d[0] = ii * 10; // 高値
d[1] = ii * 3; // 安値
d[2] = ii * 5; // 始値
d[3] = ii * 8; // 終値
DataPoint dp = new DataPoint(ii,d);
series.Points.Add(dp);
}
//チャート2の描画(出来高)
chart.Series.Add(new Series());
Series series2;
series2 = chart.Series[1];
series2.ChartArea = "chart2";
series2.ChartType = SeriesChartType.StackedColumn;
//データの作成
for(ii = 1; ii < 10 ; ii++)
{
DataPoint dp = new DataPoint(ii,ii*10000);
series2.Points.Add(dp);
}
/**** 上のチャートと下のチャートのY軸位置調整 ******/
chart.ChartAreas["chart1"].AlignWithChartArea = "chart2";
/***************************************************/
}
public static int Main(string[] args)
{
ChartTest ct = new ChartTest();
ct.ShowDialog();
return 0;
}
}
軸があって見易くなった。
2016年9月19日月曜日
C#から、dllの読み込み
C#から、Windows APIなどの、Dllを読み込む時は、読み込みの宣言をしてから使用する。
設定ファイル:file.ini
using System.Runtime.InteropServices;
public class DllRead
{
//読込む、dllの定義
[DllImport("Kernel32.Dll", EntryPoint="GetPrivateProfileInt")]
public static extern uint GetPrivateProfileInt(string lpAppName,string lpKeyName,
int nDefault,string lpFileName);
public static void Main()
{
uint hoge;
//iniファイルの読込
hoge = GetPrivateProfileInt("app","key",10,@".\file.ini");
System.Console.WriteLine(hoge);
}
}
[app] key=66
2016年7月16日土曜日
postgresqlで月曜日の最新の日付を取得する。
下の表があるとき、月曜の中で最新の日付を取得する。
結果
| date |
| 2016-07-11(月) |
| 2016-07-12(火) |
| 2016-07-13(水) |
| 2016-07-14(木) |
| 2016-07-15(金) |
SELECT Max(date) FROM dateTable WHERE extract(dow from date) = 1; -- 日曜日(0)から土曜日(6)までの曜日
結果
max ------------ 2016-07-11
2016年6月25日土曜日
WindowsでTCP・IP通信のひな型
サーバー側
クライアント側
#include#include int main(){ SOCKET soc,accpSoc; int ret,w_ret,len; struct sockaddr_in addr,accpAddr; WORD wVersionRequested; WSADATA wsaData; char buf[256]; wVersionRequested = MAKEWORD( 2, 2 ); //0.Setup ret = WSAStartup( wVersionRequested, &wsaData ); if ( ret != 0 ) { /* Tell the user that we could not find a usable */ /* WinSock DLL. */ printf("fail startup"); return -1; } //1.ソケット作成 soc = socket(AF_INET,SOCK_STREAM,IPPROTO_TCP); //2.bind addr.sin_family = AF_INET; addr.sin_addr.s_addr = inet_addr("0.0.0.0"); addr.sin_port = htons(5150); ret = bind( soc,(SOCKADDR*) &addr, sizeof(addr) ); if(ret == 0){ printf("success bind\n"); } else{ w_ret = WSAGetLastError(); printf("fail bind error code(%d)\n",w_ret); return w_ret; } //3.listen ret = listen(soc,1); if(ret == 0){ printf("success listen\n"); } else{ w_ret = WSAGetLastError(); printf("fail listen error code(%d)\n",w_ret); return w_ret; } //4.accept accpSoc = accept(soc,NULL,NULL); printf("accept socket"); //5.receive while(1){ len = recv(accpSoc,buf,sizeof(buf),0); w_ret = WSAGetLastError(); if(len <= 0){ break; } printf("recv message length = %d\n",len); } //6.後始末 if ( LOBYTE( wsaData.wVersion ) != 2 || HIBYTE( wsaData.wVersion ) != 2 ) { /* Tell the user that we could not find a usable */ /* WinSock DLL. */ WSACleanup( ); return 0; } else{ return -1; } }
クライアント側
#include#include int main(){ SOCKET soc; int ret,w_ret; struct sockaddr_in addr; WORD wVersionRequested; WSADATA wsaData; char* message = "hoge"; //0.準備 ret = WSAStartup( wVersionRequested, &wsaData ); if ( ret != 0 ) { /* Tell the user that we could not find a usable */ /* WinSock DLL. */ printf("fail startup"); return -1; } //1.ソケット作成 soc = socket(AF_INET,SOCK_STREAM,IPPROTO_TCP); //2.接続 addr.sin_family = AF_INET; addr.sin_addr.s_addr = inet_addr("127.0.0.1"); addr.sin_port = htons(5150); if ( connect( soc, (SOCKADDR*) &addr, sizeof(addr) ) == SOCKET_ERROR) { printf( "Failed to connect.\n" ); WSACleanup(); return -1; } //3.送信 while(1){ send(soc,message,sizeof(message),0); Sleep(1000); } //4.後始末 WSACleanup(); return 0; }
2016年6月11日土曜日
.net シリアライズ機能を使用してクラスの保存
シリアライズ機能を使用する時のひな型
using System;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
//クラス保存出来るように、属性を追加
[Serializable()]
public class Hoge
{
public DateTime d;
}
public class SaveLoad
{
public const string FILE_NAME = "hoge.txt";
public static void InitFile()
{
if(!File.Exists(FILE_NAME))
{
Hoge[] h = new Hoge[1];
h[0] = new Hoge();
h[0].d = DateTime.Now;
Save(h);
}
}
public static void Save(Hoge[] h)
{
FileStream fs = new FileStream(FILE_NAME,FileMode.Create,FileAccess.Write);
BinaryFormatter b = new BinaryFormatter();
b.Serialize(fs,h);
fs.Close();
}
public static Hoge[] Load()
{
BinaryFormatter b = new BinaryFormatter();
FileStream fs = new FileStream(FILE_NAME, FileMode.OpenOrCreate, FileAccess.Read);
Hoge[] loadFile;
loadFile = (Hoge[])b.Deserialize(fs);
fs.Close();
return loadFile;
}
public static void Main()
{
Hoge[] h;
//ファイルがない場合は、ファイルを作成
SaveLoad.InitFile();
//ファイルのロード
h = SaveLoad.Load();
System.Console.WriteLine("前回起動時刻は"+ h[0].d.ToString("yyyy/MM/dd HH:mm:ss")+"です。");
//終了時刻をセーブ
h[0].d = DateTime.Now;
SaveLoad.Save(h);
}
2016年5月1日日曜日
postgresql で 列にコメントを表示する
1.表を作成する
CREATE TABLE hoge (hoge int);
2.列にコメントをつける
COMMENT ON COLUMN hoge.hoge IS 'ほげ';
3.列のコメントを表示する
\d+ hoge
テーブル "public.hoge"
列 | 型 | 修飾語 | ストレージ | 対象統計情報 | 説明
------+---------+--------+------------+--------------+------
hoge | integer | | plain | | ほげ
2016年4月10日日曜日
postgresql で 3番目に大きい数を取得する
select num
from hoge
order by num desc -- numを降順に並べる
limit 1 -- 条件に合うnumを一つだけ取得する
offset 3; -- 条件に合うnumを3番目から取得する
from hoge
order by num desc -- numを降順に並べる
limit 1 -- 条件に合うnumを一つだけ取得する
offset 3; -- 条件に合うnumを3番目から取得する
2016年3月26日土曜日
2016年3月23日水曜日
PostgresqlでTCP・IP接続をできるようにする
Postgresqlは設定を変えないと外部から接続できないのでメモ
(Postgresqlはdebian8.2)
1. postgresql.confの設定を変える
/etc/postgresql/9.4/main/postgresql.conf
を開いて、
listen_addresseas = 'localhost'
→
listen_addresseas = '*'
に変更する
2.pg_hba.confの設定を変える
/etc/postgresql/9.4/main/pg_hba.conf
を開いて、
host all all 192.168.1.0/24 md5
を追加する。
(192.168.1.0/24は、IPによって変える)
3.違うパソコンからpsqlでアクセスしてみる
psql -h 192.168.1.17 dbName
(192.168.1.17は、IPによって変える)
で接続できるか確認する。
(Postgresqlはdebian8.2)
1. postgresql.confの設定を変える
/etc/postgresql/9.4/main/postgresql.conf
を開いて、
listen_addresseas = 'localhost'
→
listen_addresseas = '*'
に変更する
2.pg_hba.confの設定を変える
/etc/postgresql/9.4/main/pg_hba.conf
を開いて、
host all all 192.168.1.0/24 md5
を追加する。
(192.168.1.0/24は、IPによって変える)
3.違うパソコンからpsqlでアクセスしてみる
psql -h 192.168.1.17 dbName
(192.168.1.17は、IPによって変える)
で接続できるか確認する。
2016年3月13日日曜日
Visual Studio キーバインドメモ
編集
| Ctrl+K,Ctrl+C | 選択範囲をコメント |
| Ctrl+K,Ctrl+U | 選択範囲をコメントアウト |
| Ctrl+K,Ctrl+F | 選択範囲のフォーマット |
| Ctrl+r,Ctrl+r | 名前の変更 |
| Alt+Shiftを押しながら↑↓←→ | 矩形領域の選択 |
| Ctrl+M,Ctrl+S | 現在の領域を折りたたむ |
| Ctrl+M,Ctrl+E | 現在の領域を展開 |
| Ctrl+M,Ctrl+O | 定義を折りたたむ |
| Shift+Ctrl+B | ソリューションのビルド |
C#でWebBrowser
今まで全然使ったことがなかったけれど、
.NetにはWebBrowserといクラスがあって、
Form内にブラウザを作れる。
これが使えると、どこかのサイトにログインした後に
プログラム的に結果をとってくるとかが簡単にできて便利そう。
このプログラムを実行するだけだと、スクリプトエラーとなるので、
IE9エンジンをIEコンポーネントブラウザで使う
を参考に、レジストリーキーを更新する。
using System;
using System.Drawing;
using System.Windows.Forms;
public class WebBrowserTest : Form
{
WebBrowser webBrowser1 ;
public WebBrowserTest()
{
//パネルにWebブラウザをadd
this.webBrowser1 = new System.Windows.Forms.WebBrowser();
this.webBrowser1.Location = new System.Drawing.Point(-3, 37);
this.webBrowser1.MinimumSize = new System.Drawing.Size(20, 20);
this.webBrowser1.Name = "webBrowser1";
this.webBrowser1.Size = new System.Drawing.Size(783, 544);
this.webBrowser1.TabIndex = 0;
this.webBrowser1.Dock = DockStyle.Fill;
Uri uri = new Uri("http://www.yahoo.co.jp");
webBrowser1.Url = uri;
this.Controls.Add(this.webBrowser1);
}
[STAThread]
public static void Main()
{
WebBrowserTest test = new WebBrowserTest();
test.Size = new Size(1000,1000);
Application.Run(test);
}
}
2016年2月29日月曜日
Windowsでプロセス間通信5(共有メモリ)
プロセス間通信を共有メモリで行う場合のひな型
送信側
受信側
送信側
using System;
using System.IO;
using System.IO.MemoryMappedFiles;
using System.Threading;
using System.Runtime.InteropServices;
public class ShareMemWrite
{
public const string MEMNAME = "TEST";
public static void Main()
{
//1.共有メモリの作成
MemoryMappedFile mem = MemoryMappedFile.CreateOrOpen(MEMNAME,512);
MemoryMappedViewAccessor acc = mem.CreateViewAccessor();
DateTime d;
while(true)
{
//2.共有メモリの書き込み
d = DateTime.Now;
acc.Write(1,ref d);
Thread.Sleep(1000);
}
}
}
受信側
using System;
using System.IO;
using System.IO.MemoryMappedFiles;
using System.Threading;
using System.Runtime.InteropServices;
public class ShareMemRead
{
public const string MEMNAME = "TEST";
public static void Main()
{
//1.共有メモリの作成
MemoryMappedFile mem = MemoryMappedFile.CreateOrOpen(MEMNAME,512);
MemoryMappedViewAccessor acc = mem.CreateViewAccessor();
DateTime d;
while(true)
{
//共有メモリの読み込み
acc.Read(1,out d);
System.Console.WriteLine(d);
Thread.Sleep(1000);
}
}
}
2016年2月20日土曜日
Windowsでプロセス間通信4(メッセージキュー)
プロセス間通信をメッセージキューで行う場合のひな型
送信側
受信側
送信側
using System;
using System.Messaging;
using System.Runtime.Serialization.Formatters.Binary;
using System.Threading;
public class QueueSend
{
const string QUEUE_NAME = ".\\Private$\\TEST";
public static void Main(string[] args)
{
MessageQueue queue;
//メッセージキューがある場合はNewする
//ない場合は、作成する
if(MessageQueue.Exists(QUEUE_NAME))
{
queue = new MessageQueue(QUEUE_NAME);
}
else
{
queue = MessageQueue.Create(QUEUE_NAME);
}
BinaryMessageFormatter bf = new BinaryMessageFormatter();
Message msg;
while(true)
{
DateTime d = DateTime.Now;
//メッセージをフォーマットして送信する
msg = new Message(d,bf);
queue.Send(msg);
Thread.Sleep(1000);
}
}
}
受信側
using System;
using System.Messaging;
using System.Threading;
public class QueueRecv
{
const string QUEUE_NAME = ".\\Private$\\Test";
public static void Main(string[] args)
{
MessageQueue queue;
//メッセージキューがある場合はNewする
//ない場合は、作成する
if(MessageQueue.Exists(QUEUE_NAME))
{
queue = new MessageQueue(QUEUE_NAME);
}
else
{
queue = MessageQueue.Create(QUEUE_NAME);
}
//フォーマッタを指定
queue.Formatter = new BinaryMessageFormatter();
Message msg;
DateTime d;
while(true)
{
//メッセージを受信
msg = queue.Receive();
//受信したメッセージを型変換
d = (DateTime)msg.Body;
Console.WriteLine(d.ToString());
}
}
}
2016年2月17日水曜日
Windowsでプロセス間通信3(名前付きパイプ)
プロセス間通信をファイルで行う場合のひな型
送信側
受信側
おまけ(名前付きパイプの一覧表示)
送信側
using System;
using System.IO.Pipes;
using System.Text;
using System.Threading;
public class NamedPipeSend
{
const string NAME = "test";
public static void Main(string[] args)
{
//1.パイプ作成
NamedPipeClientStream client = new NamedPipeClientStream(".",NAME,PipeDirection.Out);
//2.サーバに接続
client.Connect();
byte[] sendData = new byte[1024];
while(true)
{
//3.処理
Thread.Sleep(1000);
DateTime d = DateTime.Now;
Encoding enc = Encoding.UTF8;
sendData = enc.GetBytes(d.ToString());
client.Write(sendData,0,sendData.Length);
client.Flush();
}
}
}
受信側
using System;
using System.IO.Pipes;
using System.Text;
public class NamedPipeReceive
{
const string NAME = "test";
public static void Main(string[] args)
{
//1.パイプ作成
NamedPipeServerStream server = new NamedPipeServerStream(NAME,PipeDirection.In);
//2.受信待ち
server.WaitForConnection();
byte[] rData = new byte[4096];
int len;
while(true)
{
rData = new byte[4096];
//データ受信
len = server.Read(rData,0,rData.Length);
if(len == 0)
{
break;
}
Array.Resize(ref rData,len);
Encoding enc = Encoding.UTF8;
System.Console.WriteLine(enc.GetString(rData));
}
}
}
おまけ(名前付きパイプの一覧表示)
public class NamedPipeList
{
public static void Main()
{
string[] pipeList = System.IO.Directory.GetFiles("\\\\.\\pipe\\");
foreach(string pipe in pipeList)
{
System.Console.WriteLine(pipe);
}
}
}
2016年2月16日火曜日
Windowsでプロセス間通信2(ソケット(UDP))
プロセス間通信をソケット(UDP)で行う場合のひな型
送信側
受信側
送信側
using System;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading;
public class SocketSend
{
const string address = "127.0.0.1";
const int port = 5555;
public static void Main()
{
//1.ソケット作成
Socket soc = new Socket(AddressFamily.InterNetwork,
SocketType.Dgram,
ProtocolType.Udp);
IPEndPoint ePoint = new IPEndPoint(IPAddress.Parse(address),port);
while(true)
{
//2.処理
Thread.Sleep(1000);
//3.データ送信
DateTime d = DateTime.Now;
Encoding enc = Encoding.UTF8;
byte[] sendData;
sendData = enc.GetBytes(d.ToString());
soc.SendTo(sendData,ePoint);
}
}
}
受信側
using System;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading;
public class Socketレエイヴェ
{
const string address = "127.0.0.1";
const int port = 5555;
public static void Main()
{
//1.ソケット作成
Socket soc = new Socket(AddressFamily.InterNetwork,
SocketType.Dgram,
ProtocolType.Udp);
EndPoint ePoint = new IPEndPoint(0,0);
EndPoint bPoint = new IPEndPoint(0,port);
byte[] rData = new byte[4096];
int len;
//2.ソケットのバインド
soc.Bind(bPoint);
while(true)
{
//2.データ受信
len = soc.ReceiveFrom(rData,ref ePoint);
Array.Resize(ref rData,len);
Encoding enc = Encoding.UTF8;
Console.WriteLine(enc.GetString(rData));
//3.処理
Thread.Sleep(1000);
}
}
}
2016年2月14日日曜日
Windowsでプロセス間通信1(ファイル)
プロセス間通信をファイルで行う場合のひな型
送信側
受信側
送信側
using System;
using System.IO;
using System.Threading;
public class FileWrite
{
private static Mutex mut = new Mutex(false,"mut");
private const string FILE_NAME = "hoge.txt";
public static void Main(string[] args)
{
while(true)
{
//1.処理
Thread.Sleep(1000);
//2.ロック
mut.WaitOne();
//3.書き込み
DateTime d = DateTime.Now;
StreamWriter sw = new StreamWriter(FILE_NAME);
sw.WriteLine(d.ToString());
sw.Close();
//4.ロックの開放
mut.ReleaseMutex();
}
}
}
受信側
using System;
using System.IO;
using System.Threading;
public class FileRead
{
private static Mutex mut = new Mutex(false,"mut");
private const string FILE_NAME = "hoge.txt";
public static void Main(string[] args)
{
while(true)
{
//1.ロック
mut.WaitOne();
//2.読み込み
StreamReader sr = new StreamReader(FILE_NAME);
Console.WriteLine(sr.ReadLine());
sr.Close();
//3.ロックの開放
mut.ReleaseMutex();
//4.処理
Thread.Sleep(1000);
}
}
}
Windowsでプロセス通信
Windowsでプロセス間の通信を行う時、いくつか方法が
あるけど、比べてみた。
| No. | 方法 | 説明 | 長所 | 短所 |
| 1 | ファイル | ファイルを作成して共有 | 分かりやすい | HDDディスクを使ってしまう。 |
| 2 | ソケット通信 | TCP or UDP通信を使う | プロセスを別のPCに移しても動く | オーバスペックな気がする |
| 3 | namedpipe | 名前付きパイプ | ||
| 4 | メッセージキュー | メッセージキュー | オブジェクトをそのまま渡せる | |
| 5 | 共有メモリ | 共有メモリを作成して書き込み読み込みを行う | 可変長データは共有しづらい |
2016年2月10日水曜日
linux コマンドでディレクトリ毎の行数確認
├─a
│ chmod.c
│ od.c
│
└─b
cut.c
paste.c
上のような感じでaとbのフォルダにファイルがある時、
aフォルダとbフォルダ毎のファイルの行数を調べたい時の話
1行でできたらおしゃれなのだろうけど、うまくいかなかったので、
shscriptとコマンドを組み合わせて作ってみた。
shscriptの内容は下のような感じ
hoge.sh
#!/bin/bash for dir in "$@" do echo $dir
#nameで対象ファイルの絞り込み find $dir -type f -name \*.c -o -name \*.h|xargs wc -l|grep 合計 done
うえのシェルスクリプトをパスを通した場所に保存して、find で探したディレクトリを渡す。
find . -type d|xargs hoge.sh
実行結果はこんな感じ。
. 3907 合計 ./a 2555 合計 ./b 1352 合計
取りえず我慢
2016年2月3日水曜日
c#で動的な関数呼び出し
using System;
using System.Reflection;
public class DynamicCall
{
public static void TestMethod(int a,int b)
{
System.Console.WriteLine("a="+a.ToString()+" b="+b.ToString());
}
public void TestMethod2()
{
System.Console.WriteLine("test Method2");
}
public static void Main()
{
DynamicCall dCall = new DynamicCall();
//型の取得
Type t = typeof(DynamicCall);
//メソッドの取得
MethodInfo mInfo = t.GetMethod("TestMethod");
//メソッド呼び出しstaticメソッドの場合は、nullでOK
mInfo.Invoke(null,new object[] {10,20});
//メソッドの取得
mInfo = t.GetMethod("TestMethod2");
//メソッド呼び出し通常メソッドの場合は、
//一番目の引数にインスタンス変数を渡す
mInfo.Invoke(dCall,null);
}
}
using System.Reflection;
public class DynamicCall
{
public static void TestMethod(int a,int b)
{
System.Console.WriteLine("a="+a.ToString()+" b="+b.ToString());
}
public void TestMethod2()
{
System.Console.WriteLine("test Method2");
}
public static void Main()
{
DynamicCall dCall = new DynamicCall();
//型の取得
Type t = typeof(DynamicCall);
//メソッドの取得
MethodInfo mInfo = t.GetMethod("TestMethod");
//メソッド呼び出しstaticメソッドの場合は、nullでOK
mInfo.Invoke(null,new object[] {10,20});
//メソッドの取得
mInfo = t.GetMethod("TestMethod2");
//メソッド呼び出し通常メソッドの場合は、
//一番目の引数にインスタンス変数を渡す
mInfo.Invoke(dCall,null);
}
}
2016年1月23日土曜日
emacs lispで文字列挿入
hoge001
hoge002
:
hoge100
みたいに単純に数字だけ変わっていく場合
emacs lispでしたみたいに書いて実行する。
(let ((ii 1))
(while (<= ii 100)
(insert (format "hoge%03d\n" ii))
(setq ii (+ ii 1))
)
)
hoge002
:
hoge100
みたいに単純に数字だけ変わっていく場合
emacs lispでしたみたいに書いて実行する。
(let ((ii 1))
(while (<= ii 100)
(insert (format "hoge%03d\n" ii))
(setq ii (+ ii 1))
)
)
登録:
コメント (Atom)

