Skip to content

Instantly share code, notes, and snippets.

View kowill's full-sized avatar

kowill kowill

  • 19:51 (UTC +09:00)
View GitHub Profile

image

@kowill
kowill / DoubleBitString.cs
Last active October 16, 2018 16:18
double → bit string → double
string ToBitDoubleString(double num)
{
return BitConverter.GetBytes(num)
.Reverse() // little endian -> big endian
.SelectMany(x => x.ToString("X2")) //to x16 char
.Select(x => Convert.ToString(Convert.ToInt32($"{x}", 16), 2).PadLeft(4, '0')) // to x2
.Aggregate("", (x, y) => x + y);
}
double ToDouble(string str)
@kowill
kowill / samlple.cs
Created September 12, 2016 13:31
逆ポーランド変換→計算
using System;
using System.Collections.Generic;
namespace Test20160912
{
class Program
{
static void Main(string[] args)
{
var inputs = new[] { "((1 + 4) * (3 + 7) / 5)", "((1 - 7) / (7 - 5)) * 5", "", "1+2" };
@kowill
kowill / DelZoneId.ps1
Created July 8, 2016 07:25
Delete Zone Id
ls | ?{!$_.PSIsContainer} | Unblock-File
@kowill
kowill / sample.cs
Created June 19, 2016 16:11
最大公約数の取得
int GetGcd(int a, int b)
{
if (a < b) return GetGcd(b, a);
int tmp = 0;
do
{
tmp = a % b;
a = b;
b = tmp;
} while (tmp != 0);
@kowill
kowill / BindableEditor.cs
Last active July 3, 2022 15:28
AvalonEditのTextプロパティをbindableへ
using ICSharpCode.AvalonEdit;
using System;
using System.Windows;
namespace AvalonEditSample
{
public class BindableEditor : TextEditor
{
public BindableEditor()
{
@kowill
kowill / FbSql.xshd
Last active July 3, 2022 15:29
Firebird 用xshd
<SyntaxDefinition name="SQL" extensions=".sql" xmlns="http://icsharpcode.net/sharpdevelop/syntaxdefinition/2008">
<Color name="Digits" foreground="#FF00008B" exampleText="3.1415f" />
<Color name="Comment" foreground="#FF008000" exampleText="string text = &quot;Hello, World!&quot;" />
<Color name="Punctuation" foreground="#FFFF0000" exampleText="string text = &quot;Hello, World!&quot;" />
<Color name="String" foreground="#FF808000" exampleText="string text = &quot;Hello, World!&quot;" />
<Color name="String2" foreground="#FF999933" exampleText="string text = &quot;Hello, World!&quot;" />
<Color name="Keyword" foreground="#FF0000FF" fontWeight="bold" exampleText="SELECT" />
<Color name="MethodCall" foreground="#FF191970" fontWeight="bold" />
<Color name="ObjectReference" foreground="#FF008080" exampleText="Customer.Name" />
<Color name="CommentMarkerSetTodo" foreground="#FFFF0000" fontWeight="bold" />
@kowill
kowill / Sample.cs
Created May 11, 2016 14:39
10進数→任意の進数
public string ToRadixString(int num, int radix)
{
if (num == 0) return "0";
var list = new List<string>();
var tmp = num;
while (0 < tmp)
{
var digit = tmp % radix;
tmp = tmp / radix;
list.Add(digit.ToString());
@kowill
kowill / Sample.cs
Created May 11, 2016 14:32
ナルシスト数判定
public static bool IsNarcissistic(int num)
{
var numStr = num.ToString();
return num == (int)numStr.Select(c => int.Parse(c.ToString())).Sum(x => Math.Pow(x, numStr.Length));
}
@kowill
kowill / Program.cs
Created April 20, 2016 06:53
20160420Firebird3.0
using FirebirdSql.Data.FirebirdClient;
using System;
using System.IO;
namespace Fb3Test
{
class Program
{
static void Main(string[] args)
{