Skip to content

Instantly share code, notes, and snippets.

@takepara
takepara / NakedRazor
Created April 19, 2018 10:24
Razor+Roslyn
using System;
using System.CodeDom;
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
@takepara
takepara / zundoko4.cs
Last active March 15, 2016 03:16
ズンドコ4
IEnumerable<string> Words()
{
var count = 0;
for(;;)
{
var isZ = Guid.NewGuid().GetHashCode()%2 == 0 ? true : false;
if(isZ)
{
count ++;
}
@takepara
takepara / zundoko3.cs
Created March 15, 2016 02:42
ズンドコ3
IEnumerable<string> Words()
{
var words = new String(' ',5);
for(;;)
{
var word = Guid.NewGuid().GetHashCode()%2 == 0 ? "0" : "1";
words = (words + word).Substring(1,5);
if(words == "00001")
{
@takepara
takepara / zundoko2.cs
Created March 13, 2016 12:21
ズンドコ2
bool kiyoshing = true;
IEnumerable<string> Words(){
for(;kiyoshing;)
yield return Guid.NewGuid().GetHashCode()%2 == 0 ? "ズン" : "ドコ";
}
void Main()
{
Words().Aggregate(
new List<string>(),
(seq,word) => {
@takepara
takepara / zundoko1.cs
Created March 13, 2016 12:21
ズンドコ1
bool kiyoshing = true;
IEnumerable<string> Words(){
for(;kiyoshing;)
yield return Guid.NewGuid().GetHashCode()%2 == 0 ? "ズン" : "ドコ";
}
void Main()
{
List<string> words = new List<string>();
foreach(var word in Words())
{
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using RazorEngine.Configuration;
using RazorEngine.Roslyn;
using RazorEngine.Templating;
namespace RoslynPerformance
{
@takepara
takepara / gist:6ac1d44e087fba849cfd
Last active August 29, 2015 14:16
LinqIterator 判定とIEnumerable<T>取得
using System;
using System.Collections.Generic;
using System.Linq;
namespace LinqGetType
{
public class Category
{
public int Id { get; set; }
public string Name { get; set; }
@takepara
takepara / gist:264d0c2b3c0f4dfe2433
Last active August 29, 2015 14:14
Webアプリケーションから共有フォルダに偽装ユーザーでアクセスするサンプル
using System;
using System.Configuration;
using System.Diagnostics;
using System.IO;
using System.Runtime.ConstrainedExecution;
using System.Runtime.InteropServices;
using System.Security;
using System.Security.Principal;
using System.Web.Mvc;
using Microsoft.Win32.SafeHandles;
@takepara
takepara / gist:5dc86f4a4490b5ee76fd
Created June 9, 2014 06:13
メロディのキーをチェンジ
// http://blog.jnito.com/entry/2014/06/06/104420
// 相変わらずLINQPadで。Languageを"c# program"にしてコピペ。
// ToScaleがダサくてすいませんね。
class KaraokeMachine
{
private static string[] _scales = new[]{"C","C#","D","D#","E","F","F#","G","G#","A","A#","B"};
private string _melody;
public KaraokeMachine(string melody)
{
@takepara
takepara / gist:88d12d54ae099a8455f4
Created June 3, 2014 14:27
7の数をかぞえる
int CountNumber(int number,int target = 7)
{
var count = 0;
var numberParts = 0;
var numberChars = number.ToString().Select(c => int.Parse(c + "")).Reverse().ToArray();
for (int i = 0; i < numberChars.Count(); i++)
{
count += numberChars[i] * (i * (int)Math.Pow(10, i - 1));
if (numberChars[i] > target)