メモ:目についたJQueryプラグインとか
ガントチャート
The jQuery.ganttView plugin is a very lightweight plugin for creating a Gantt chart in plain HTML...no vector graphics or images required. The plugin supports dragging and resizing the Gantt blocks and callbacks to trap the updated data.
thegrubbsian/jquery.ganttView · GitHub
jQuery-PLANBOARD
The original use case for this planboard is allocating rooms or other types of accommodation in a hotel, camping or holiday resort, but it was designed so it can be used for other types of planning or allocation issues as well.
Home · marc-portier/jquery-planboard Wiki · GitHub
表示はこれが理想に近い。操作性はイマイチ。
DayPilot for ASP.NET MVC - Calendar, Scheduler and Gantt Components
理想的だけどSaasで$999
Ext Scheduler Examples | Bryntum
DayPilotに比べて手数はかかりそうだけど$370
Issue 150 - fullcalendar - Resource View (horizontal) - Full-sized Calendar jQuery Plugin - Google Project Hosting
FullCalendarにResourceViewを追加したいというトピック。
#51 jarno.ku...@gmail.com
Issue 150 - fullcalendar - Resource View (horizontal) - Full-sized Calendar jQuery Plugin - Google Project Hosting
Here's my approach for this matter. It must be tested better, but at least it's a start: https://github.com/jarnokurlin/fullcalendar/
demo can be found from here: http://tux.fi/~jarnok/fullcalendar/demos/resourceView.html
これを試してみてるとこ
RDゲートウェイで利用できるオレオレサーバー証明書をopensslで作る
RDゲートウェイは便利なんだけど、備え付けのオレオレ証明書発行が半年の証明書しか作れなかったのでこれをOpenSSLで作って楽しようというログ
下ごしらえ
openSSLのオプションだけだとextendedKeyUsaseが設定できないので、configに拡張設定しておく
#/etc/pki/tls/openssl.cnf [ server_auth_win ] extendedKeyUsage = serverAuth
で、この設定を使ってサーバー認証用のキーを作る
# openssl req -x509 -extensions 'server_auth_win' -nodes -days 3650 -newkey rsa:4096 -keyout myserver.key -out myserver.crt Generating a 4096 bit RSA private key ................................++ .....................................................................................................................................................................................................................................................................................................................................................................................++ writing new private key to 'myserver.key' ----- You are about to be asked to enter information that will be incorporated into your certificate request. What you are about to enter is what is called a Distinguished Name or a DN. There are quite a few fields but you can leave some blank For some fields there will be a default value, If you enter '.', the field will be left blank. ----- Country Name (2 letter code) [XX]:JP State or Province Name (full name) []:tokyo Locality Name (eg, city) [Default City]:chuou-ku Organization Name (eg, company) [Default Company Ltd]:hoge company Organizational Unit Name (eg, section) []: Common Name (eg, your name or your server's hostname) []:site.fqdn.name Email Address []:
これでサーバー認証用の10年キーができるので、最後にこれらを使ってpfxを作る
# openssl pkcs12 -export -in myserver.crt -inkey myserver.key -out myserver.pfx -name "myserver" Enter Export Password: Verifying - Enter Export Password:
このpfxをRDゲートウェイにインポートすればOK
Typeにやたら沢山あるGeneric系メンバってナンジャラホイ。
このサンプルが一番わかりやすい。
Type.ContainsGenericParameters プロパティ (System)
public class Base<T, U> { } public class Derived<V> : Base<int, V> { } public class Test { public static void Main() { Type derivedType = typeof(Derived<>); DisplayGenericTypeInfo(derivedType); DisplayGenericTypeInfo(derivedType.BaseType); } private static void DisplayGenericTypeInfo(Type t) { Console.WriteLine("\tIs this a generic type definition? {0}", t.IsGenericTypeDefinition); Console.WriteLine("\tIs it a generic type? {0}", t.IsGenericType); Console.WriteLine("\tDoes it have unassigned generic parameters? {0}", t.ContainsGenericParameters); if (t.IsGenericType) { Type[] typeArguments = t.GetGenericArguments(); Console.WriteLine("\tList type arguments ({0}):", typeArguments.Length); foreach (Type tParam in typeArguments) { // IsGenericParameter is true only for generic type // parameters. // if (tParam.IsGenericParameter) { Console.WriteLine( "\t\t{0} (unassigned - parameter position {1})", tParam, tParam.GenericParameterPosition); } else { Console.WriteLine("\t\t{0}", tParam); } } } } } /* This example produces the following output: --- Display a generic type and the open constructed type from which it is derived. Derived`1[V] Is this a generic type definition? True Is it a generic type? True Does it have unassigned generic parameters? True List type arguments (1): V (unassigned - parameter position 0) Base`2[System.Int32,V] Is this a generic type definition? False Is it a generic type? True Does it have unassigned generic parameters? True List type arguments (2): System.Int32 V (unassigned - parameter position 0) */
ここから、
- IsGenericType
- TypeがGenericであるか*1
- IsGenericTypeDefinition
- Typeが Class<T>などの不確定型を持つ定義になっているか*2
- ContainsGenericParameters
- Typeが Class<T>などの不確定型のパラメータを持つか
- IsGenericParameter
- Class<T>のTのような不確定型パラメータか
という感じっぽい。
*1:class of classの形になっているか
LinqToEntityで取り出したデータをお手軽にCSVにしたい
LinqToCSVとか色々あるんだけど帯に短し襷に長し。
もっと簡単に使いたいんだよな。
と、思ったのでリフレクションの復習も兼ねて自作してみる。
仕様
- IEnumerable<T>から出力
- 基本的にはClassの設計通りに出力する
- 1:1の参照だったらリンク先のオブジェクトも処理したい
- このへんはAnnotationで制御したい
- プロパティタイトル
- 非出力プロパティ
- 出力順
- 出力フォーマット
- 参照先を含めるかどうか
- フォーマットあたりでdelegateするとか。
こんな感じにしたらEF関係なく使えそうかな。
情報収集
IEnumerable<T>からTを取得する
IEnumerable<T> myEnumerable;
Type type = myEnumerable.GetType().GetGenericArguments()[0];
c# - getting type T from IEnumerable<T> - Stack Overflow
ここいらへん。
テストしてみる。
private string genericParameter(Object o) { StringBuilder buff = new StringBuilder(); buff.Append( string.Join(",", o.GetType().GetGenericArguments().Select(t => t.Name).ToArray()) + "\r\n"); return buff.ToString(); } private void genericTypeToolStripMenuItem_Click(object sender, EventArgs e) { textBox1.Text = ""; textBox1.Text += "string : " + genericParameter(""); textBox1.Text += "List<string> : " + genericParameter(new List<string>()); textBox1.Text += "KeyValuePair<int, string> : " + genericParameter(new KeyValuePair<int, string>()); textBox1.Text += "List<KeyValuePair<int, string>> : " + genericParameter(new List<KeyValuePair<int, string>>()); textBox1.Text += "Dictionary<string,KeyValuePair<int, string>> : " + genericParameter(new Dictionary<string, KeyValuePair<int, string>>()); }
出力結果
string : List<string> : String KeyValuePair<int, string> : Int32,String List<KeyValuePair<int, string>> : KeyValuePair`2 Dictionary<string,KeyValuePair<int, string>> : String,KeyValuePair`2
ふむ。
stringはGenericパラメータを持たないので空白。
ListやKVPはきちんと取得出来てる。
4つ目以降のTypeOf-TypeOfの形だとルートクラスのGetGenericArgsでは自身の直接のジェネリックタイプだけ出てくるのがわかる。
`2 ってのは2つのジェネリックタイプを持ってるって印かな。
Typeにやたら沢山あるGeneric系メンバってナンジャラホイ。
プロパティ一覧を取り出してみる
これはType.GetPropertiesでいけそう。
Type.GetProperties メソッド (BindingFlags) (System)
BindingFlags 列挙体 (System.Reflection)
private void getPropertiesToolStripMenuItem_Click(object sender, EventArgs e) { Type t = typeof(Form1); textBox1.Text = string.Join("\r\n", t.GetProperties(BindingFlags.Public | BindingFlags.Instance) .Select(p => string.Format("{0} : {1}", p.PropertyType.Name, p.Name)) .ToArray() ); }
結果
IButtonControl : AcceptButton Form : ActiveMdiChild Boolean : AllowTransparency Boolean : AutoScale Size : AutoScaleBaseSize Boolean : AutoScroll Boolean : AutoSize AutoSizeMode : AutoSizeMode AutoValidate : AutoValidate Color : BackColor FormBorderStyle : FormBorderStyle IButtonControl : CancelButton (以下略)
いけた。
MaxRequestLengthを設定するとInternalServerErrorでIISが起動できない
でかいサイズの画像アップロードを作ってて、RequestLengthOverが出たのでWeb.configの設定を
POSTされるアップロードの上限を設定するには、Web.configのhttpRuntime要素のmaxrequestlength属性に値を設定する。 なにも設定しない場合は、デフォルトのサイズ上限値(4MB)が適用される。 たとえば5MBに制限する場合、以下のようになる。
<configuration> <system.web> <httpRuntime maxrequestlength="5120"> </system.web> </configuration>ASP.NET アップロードファイルサイズの上限
と変更したらなぜかInternalServerError(500.19)が出てサーバー自体が起動できない。
続きを読むジョンジョンボビプログラムできたよー
工場研修の生産性のなさに嫌気が差してきたので「ボ」「ン」「ジョ」「ヴィ」をランダムに表示して「ジョン・ボン・ジョヴィ」が揃ったら終了するプログラム作りました pic.twitter.com/xX4pyLbq3s
— YaGi (@yagiyyyy) 2014, 6月 2
public partial class Form1 : Form { private void form1_DoubleClick(object sender, EventArgs e) { JohnBon.Jovi(); } } public class JohnBon { private enum JBJToken { ボ, ン, ジョ, ヴィ } private static int[] answer = new JBJToken[] { JBJToken.ジョ, JBJToken.ン, JBJToken.ボ, JBJToken.ン, JBJToken.ジョ, JBJToken.ヴィ } .Cast<int>().Reverse().ToArray(); public static void Jovi() { Random jbjRandom = new Random(); int tokenCount = Enum.GetValues(typeof(JBJToken)).Length; //initial List<int> list = Enumerable.Range(0, answer.Length).Select(i => jbjRandom.Next(tokenCount)).ToList(); while (!answer.SequenceEqual(list.Take(answer.Length))) { list.Insert(0, jbjRandom.Next(tokenCount)); } foreach (JBJToken t in list.Cast<JBJToken>().Reverse()) { Console.Write(t.ToString() + "・"); } Console.WriteLine(); Console.WriteLine(string.Format("{0} Bon Jovis", list.Count)); Console.WriteLine(@" _人人人人人人人人人人人人人人_ > You Give Love a Bad Name <  ̄Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y ̄"); } }
╭( ・ㅂ・)و やったー
もちょっと短く
public static void Jovi() { Random jbjRandom = new Random(); int tokenCount = Enum.GetValues(typeof(JBJToken)).Length; //initial List<int> list = Enumerable.Range(0, answer.Length).Select(i => jbjRandom.Next(tokenCount)).ToList(); while (!answer.SequenceEqual(list.Take(answer.Length))) { list.Insert(0, jbjRandom.Next(tokenCount)); } Console.Write(string.Join("・", list.Cast<JBJToken>().Reverse().Select(t => t.ToString()).ToArray())); Console.WriteLine(string.Format(@" {0} Bon Jovis _人人人人人人人人人人人人人人_ > You Give Love a Bad Name <  ̄Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y ̄", list.Count)); }
Consoleへの出力を先にLINQ使って文字列にすることで1行に。
解説(いらない
- トークンを数値と文字の媒介にするために列挙型に。
- IEnumerable<T>.SequenceEqual()で答え合わせ。
- 最新の6*1個のトークンを切り出すためにIEnumerable.Take()を使う。ただTakeでは末尾から取れないんでリストを逆順に作っとく
- 出力する段ではリストを再度逆順にしてキャストしてからSelectでstring配列にしてstring.Join()で結合
╭( ・ㅂ・)و
OrderByのセレクタを外出ししたい
外部からのパラメータでリストの表示順位を変えたいなんてのは比較的ありがちなんだけど、EF+LINQでやろうとしてもいまいち方法がわからん。
ケース
素直にやるとこうなる。
public class ViewModel{ public string SearchText {get;set;} public int? age {get;set;} public int Order{get;set;} public int OrderDirection{get;set;} } public class Person{ public int id {get;set;} public string Name {get;set;} public string FamilyName{get;set;} public int age{get;set;} } public IEnumerable<Person> search(ViewModel model){ using (Entity entity = new Entity()){ IQueryable<Person> query = entity.Persons ; if (!string.IsNullOrEmpty(model.SearchText)) query = query.Where(p=>p.Name==SearchText || p.FamilyName==SearchText); if (model.age.HasValue) query = query.Where(p=>p.age==model.age.Value); if (model.OrderDirection==0){ query = model.Order==0? query.OrderBy(p=>p.Name) : query.OrderBy(p=>p.id); }else{ query = model.Order==0? query.OrderByDescending(p=>p.Name) : query.OrderByDescending(p=>p.id); } return query.Select(p=>p); } }
「model.Orderによって表示順を、model.OrderDirectionによって昇順降順を切り替えたい」ってのの実現に
if (model.OrderDirection==0){ query = model.Order==0? query.OrderBy(p=>p.Name) : query.OrderBy(p=>p.id); }else{ query = model.Order==0? query.OrderByDescending(p=>p.Name) : query.OrderByDescending(p=>p.id); }
ってなるのがダサすぎる。
Orderbyのラムダを外出しにしてOrderDirectionによる分岐1個か、さらにそれも無くした形にしたい。