2017년 8월 28일 월요일

[C#] fastest byte[] to Hex string array

 public static class IOExt
    {
        private static readonly uint[] _lookup32Unsafe = CreateLookup32Unsafe();

        private static unsafe readonly uint* _lookup32UnsafeP = (uint*)GCHandle.Alloc(_lookup32Unsafe,GCHandleType.Pinned).AddrOfPinnedObject();

        private static uint [ ] CreateLookup32Unsafe()
        {
            var result = new uint[256];
            for ( int i = 0 ; i < 256 ; i++ )
            {
                string s=i.ToString("X2");
                if ( BitConverter.IsLittleEndian )
                    result [ i ] = ( ( uint )s [ 0 ] ) + ( ( uint )s [ 1 ] << 16 );
                else
                    result [ i ] = ( ( uint )s [ 1 ] ) + ( ( uint )s [ 0 ] << 16 );
            }
            return result;
        }

        public static string ByteArrayToHexViaLookup32Unsafe( byte [ ] bytes )
        {
            unsafe
            {
                var lookupP = _lookup32UnsafeP;
                var result = new char[bytes.Length * 2];
                fixed ( byte* bytesP = bytes )
                fixed ( char* resultP = result )
                {
                    uint* resultP2 = (uint*)resultP;
                    for ( int i = 0 ; i < bytes.Length ; i++ )
                    {
                        resultP2 [ i ] = lookupP [ bytesP [ i ] ];
                    }
                }
                return new string( result );
            }
        }

    }
https://stackoverflow.com/a/24343727/6127030

[C#] IO Path 관련 명령어 - 프로그램 자체 경로 가져올때


  1. Application.StartupPathand 7. System.IO.Path.GetDirectoryName(Application.ExecutablePath) - Is only going to work for Windows Forms application
  2. System.IO.Path.GetDirectoryName( System.Reflection.Assembly.GetExecutingAssembly().Location)
    Is going to give you something like: "C:\\Windows\\Microsoft.NET\\Framework\\v4.0.30319\\Temporary ASP.NET Files\\legal-services\\e84f415e\\96c98009\\assembly\\dl3\\42aaba80\\bcf9fd83_4b63d101" which is where the page that you are running is.
  3. AppDomain.CurrentDomain.BaseDirectory for web application could be useful and will return something like "C:\\hg\\Services\\Services\\Services.Website\\" which is base directory and is quite useful.
  4. System.IO.Directory.GetCurrentDirectory() and 5. Environment.CurrentDirectory
will get you location of where the process got fired from - so for web app running in debug mode from Visual Studio something like "C:\\Program Files (x86)\\IIS Express"
  1. System.IO.Path.GetDirectoryName( System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase)
will get you location where .dll that is running the code is, for web app that could be "file:\\C:\\hg\\Services\\Services\\Services.Website\\bin"
Now in case of for example console app points 2-6 will be directory where .exe file is.
Hope this saves you some time.




 AppDomain.CurrentDomain.BaseDirectory  이거써라

2017년 8월 24일 목요일

[windows]c드라이브 권한 제거

http://blog.daum.net/khkim6001/649
c드라이브 권한 제거


[Haskell] Install

-- haskell and cobal install --

My Enviroment is  windows10 64bit and i just install full version haskell installer from https://www.haskell.org/platform/

and i down load cobal 2.0.0.0 from https://hackage.haskell.org/package/cabal-install

and put this cobal.exe in  

C:\Program Files\Haskell Platform\8.0.2-a\bin
C:\Program Files\Haskell Platform\8.0.2-a\lib\extralibs\bin

both.

and add enviroment path
C:\Program Files\Haskell Platform\8.0.2-a\bin
C:\Program Files\Haskell Platform\8.0.2-a\lib\extralibs\bin

After all this , when i opened cmd and typed "calbal --version"

-cabal update
cabal install ghc-mod stylish-haskell
or
cabal update 
cabal install alex
cabal install happy
cabal install ghc-mod hlint stylish-haskell


-- install atom
  • language-haskell : 문법 강조, 자동 들여쓰기, Snippets
  • haskell-ghc-mod : 형(type) 검사
  • ide-haskell : 에러/경고/Lints, type/info 보여주기, Prettify
  • autocomplete-haskell : 자동완성
apm install language-haskell haskell-ghc-mod ide-haskell-cabal ide-haskell autocomplete-haskell




2017년 8월 21일 월요일

Covariance vs Contravariance

covariance : converting from wider to narrower (넓은것에서 좁은것으로의 변환)

contravariance : converting from narrower to wider (좁은것에서 넓은것으로의 변환)


제네릭 인터페이스에서 형식 매개 변수가 다음 조건을 충족하는 경우 공변(covariant)으로 선언할 수 있습니다.
  • 형식 매개 변수는 인터페이스 메서드의 반환 형식으로만 사용되고 메서드 인수의 형식으로 사용되지 않습니다.

형식 매개 변수는 인터페이스 메서드에 대한 제네릭 제약 조건으로 사용되지 않습니다.


   interface INoraml { }
    class NormalSample : INoraml { }



    interface ICovariant { }
    class Sample : ICovariant { }

    interface IContravariant { }
    class SampleContra : IContravariant { }


    public class covriance
    {
      public void main()
        {
            ICovariant iobj = new Sample();
            ICovariant istr = new Sample();
            ICovariant iobst = new Sample();

            iobj = istr;
        }

        public void main2()
        {
            INoraml iobj = new NormalSample();
            INoraml istr = new NormalSample();
            INoraml iobst = new NormalSample();
            iobj = istr;
            istr = iobj;
        }

        public void main3()
        {
            IContravariant iobj = new SampleContra();
            IContravariant istr = new SampleContra();
            IContravariant iobst = new SampleContra();
            iobj = istr;
            istr = iobj;
        }

[bitplex] 분석

데이터 로드 

MxFile은 전역변수 

1. MxFile에 "ptnmap_depth1" 이 있는지 체크 
!Data.HasData(partition_name)
DataHeaders.Any(x => x.Name.Equals(name, StringComparison.CurrentCultureIgnoreCase));
//https://msdn.microsoft.com/ko-kr/library/system.stringcomparison(v=vs.110).aspx

2. "ptnmap_depth1" 이 있다면 

2-1 : MxDataHeader

2017년 8월 17일 목요일

[C#] enum name to string

public enum Teste { ab ,abg}
    class Program
    {
        static void Main( string [ ] args )
        {
            var strlist = Enum.GetNames(typeof(Teste)); // To String List
            var name = Teste.ab.ToString();  // single string

            Console.ReadLine();



        }
    }

[C#] Jagged Array Property

 int[][] temp = new int[2][] {
               new int[] {2,4},
               new int[] {3,2}
           };

            int[][] temp2 = new int[2][] {
               new int[] {20,2,4,5,4},
               new int[] {30,40}
           };

            temp [ 0 ] = temp2 [ 0 ];
            temp [ 0 ] = temp2 [ 0 ];



[C#] Get Files in Folder

 FolderBrowserDialog ofd = new FolderBrowserDialog();
            if ( ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK )
            {
                try
                {
                    FileNamesList = new List();
                    Directory.GetFiles( ofd.SelectedPath ).Where( x => System.IO.Path.GetExtension(x) == ".jpg").Select( x => x).ToList();
                   




                    var result = SingleProcessing( new Image( ofd.FileName ) , true);
                    mainimg.ImageSource = result.Item1.ToBitmapSource();
                }
                catch ( Exception )
                {
                }
            }

2017년 8월 14일 월요일

[c#] partial application

 public static Func>> tt => str1 => str2 => str3 => Console.WriteLine( str1 + str2 + str3 );


        static void Main( string [ ] args )
        {
            var temp1 = tt("2");
            var temp2 = tt("2")("3");

        }