Skip to content

Instantly share code, notes, and snippets.

@ichiroku11
ichiroku11 / gist:5719039
Created June 6, 2013 03:09
再帰CTEで子孫の取得と先祖の取得
use tempdb;
create table #Folder(
Id int,
Name varchar(5),
ParentId int null,
constraint PK_Id primary key(Id),
constraint FK_ParentId foreign key(ParentId) references #Folder(Id)
);
@ichiroku11
ichiroku11 / gist:5773839
Last active December 18, 2015 11:09
offsetとfetchでページング
if object_id('Sequence') is not null
drop table Sequence;
-- シーケンスのソース(共通テーブル式を使って1~50までの連番生成)
with Source(Value) as(
select 1
union all
select Value + 1
from Source
)
@ichiroku11
ichiroku11 / gist:5935000
Created July 5, 2013 14:40
NLog.configのサンプル 変数定義とファイルを日付でローリング
<?xml version="1.0" encoding="utf-8" ?>
<nlog
xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<variable
name="layout"
value="${longdate}|${level}|${message}" />
<targets>
@ichiroku11
ichiroku11 / Program.cs
Created July 20, 2013 13:10
Func<TItem, TKey>を使ったKeyedCollection<TKey, TItem>の実装
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp {
class DefaultKeyedCollection<TKey, TItem> : KeyedCollection<TKey, TItem> {
private readonly Func<TItem, TKey> _func;
@ichiroku11
ichiroku11 / Program.cs
Created July 26, 2013 14:06
JsonConvert.PopulateObject で、 デフォルト値が設定してあるインスタンスのプロパティを JSON から取得した値で上書き
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;
namespace ConsoleApp {
class Settings {
@ichiroku11
ichiroku11 / gist:6403881
Last active December 22, 2015 02:29
Overload on Constants(定数によるオーバーロード)を試す Version:0.9.1.1
document.addEventListener("DOMContentLoaded", function(event) {
var toString = Object.prototype.toString;
// 文字列リテラルを使ってcreateElementを呼び出すと、HTMLAnchorElement
// オーバーロードが有効になる
var element1 = document.createElement("a");
// エラーにならない
element1.href;
console.log(toString.apply(element1)); // [object HTMLAnchorElement]
@ichiroku11
ichiroku11 / SampleController.cs
Created September 10, 2013 12:55
FilterAttribute の Order プロパティを指定した場合の実行順序を確認してみた
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace MvcApp.Controllers {
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, Inherited = true, AllowMultiple = true)]
public class SampleAttribute : FilterAttribute, IAuthorizationFilter, IActionFilter, IResultFilter, IExceptionFilter {
@ichiroku11
ichiroku11 / FilterConfig.cs
Created September 10, 2013 13:08
FilterAttribute で FilterScope の違いによる実行順序を確認してみた
using System.Web;
using System.Web.Mvc;
namespace MvcApp {
public class FilterConfig {
public static void RegisterGlobalFilters(GlobalFilterCollection filters) {
filters.Add(new SampleAttribute("Global"));
}
}
}
@ichiroku11
ichiroku11 / gist:6537195
Created September 12, 2013 13:22
セット演算子を使った select into と insert into select
if object_id('tempdb..#Test') is not null
drop table #Test;
select *
into #Test
from (values(1), (2)) as Test(Value)
union all
select *
from (values(3), (4)) as Test(Value);
@ichiroku11
ichiroku11 / AutoMapperTest.cs
Created September 22, 2013 11:44
AutoMapperを試してみた
using System;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using AutoMapper;
namespace Test {
class User1 {
public int Id { get; set; }
public string Name { get; set; }
}