Search This Blog

Title of the confirm dialog

Description of what is about to happen

Print Barcode Using ESC/POS Command




Derivated from ISO 6346

ISO 6346 is an international standard covering the coding, identification and marking of intermodal (shipping) containers used within containerized intermodal freight transport. The standard establishes a visual identification system for every container
that includes a unique serial number (with check digit), the owner, a country code, a size, type and equipment category as well as any operational marks. The standard is managed by the International Container Bureau (BIC).
(ref https://en.wikipedia.org/wiki/ISO_6346)

This function use javascript, that must be enabled to run properly, and also use no speedMode / compressedDataMode.

Enter maximum 11 valid chars of Indentification Number (eg: CSQU3054383) and click 'VALIDATE'. Check validity of check digit of a container code. Need reCapthca validation Once time only.









Test Container Code Live Validation

Format AAAX0000009
AAA Owner Code
The owner code consists of three capital letters of the Latin alphabet to indicate the owner or principal operator of the container. Such code needs to be registered at the Bureau International des Conteneurs in Paris to ensure uniqueness worldwide.
X Equipment Category Identifier
The equipment category identifier consists of one of the following capital letters of the Latin alphabet:
J : detachable freight container-related equipment
U : freight containers
Z : trailers and chassis
Under the ISO code, then, only J, U and Z are in use—the reefer container is identified by means of the size type code.
000000 Serial Number
The serial number consists of 6 numeric digits, assigned by the owner or operator, uniquely identifying the container within that owner/operator's fleet.
9 Check Digit
The check digit consists of one numeric digit providing a means of validating the recording and transmission accuracies of the owner code and serial number.

TOP
Shipping Container Code Validation

Bitmap Color Replacement

Replace specific bitmap pixels color with specific intensity(0~100%) and/or limited alpha  into new defined color. First get bitmap pixels by width and height by an iteration then do process of pixel color replacement.


List of functions

○ Replace Color.
○ Replace Non Transparent Color.
○ Replace Non Transparent ColorA.
○ Set Replace All Color Bitmap (2 overloads).
○ Set Replace Color Bitmap(2 overloads).

Class Lerp is needed and can be viewed here


Source Code


  1 
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
using System;
using System.Collections;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;

namespace TechScales
{
    internal static class BitmapExtensions
    {
        /// <summary>
        /// Replace color with limited alpha and specific intensity
        /// </summary>
        /// <param name="source"></param>
        /// <param name="to"></param>
        /// <param name="minAlphaReplace"></param>
        /// <param name="intensity"></param>
        /// <returns></returns>
        internal static Bitmap SetReplaceAllColorBitmap(
            this Bitmap source, Color to, byte minAlphaReplace = 0, float intensity = .25f)
        {
            if (source == null) { return null; }
            if (intensity < 0.1f && intensity > 1f) { intensity = 1f; }
            Bitmap bm = new Bitmap(source);
            for (int w = 0; w < source.Width - 1; w++)
            {
                for (int h = 0; h < source.Height - 1; h++)
                {
                    Color c = bm.GetPixel(w, h);
                    if (c.A > minAlphaReplace)
                    {
                        c = Color.FromArgb(c.A, intensity == 1f ? to : c.Lerp(to, intensity));
                        bm.SetPixel(w, h, c);
                    }
                }
            }
            return bm;
        }
        /// <summary>
        /// Replace color with specific intensity
        /// </summary>
        /// <param name="source"></param>
        /// <param name="to"></param>
        /// <param name="minAlphaReplace"></param>
        /// <param name="intensity"></param>
        /// <returns></returns>
        internal static Bitmap SetReplaceAllColorBitmap(
            this Bitmap source, Color to, float intensity)
        {
            return SetReplaceAllColorBitmap(source, to, 0, intensity);
        }
        /// <summary>
        /// Replace all color into new color with specific intensity
        /// </summary>
        /// <param name="source">gambar</param>
        /// <param name="col">warna baru</param>
        /// <param name="intensity"></param>
        /// <returns></returns>
        internal static Bitmap SetReplaceColorBitmap(
            this Bitmap source, Color col, float intensity = 1f)
        {
            if (source == null) { return null; }
            if (intensity < 0.1f && intensity > 1f) { intensity = 1f; }
            Bitmap bm = new Bitmap(source);
            for (int w = 0; w < source.Width - 1; w++)
            {
                for (int h = 0; h < source.Height - 1; h++)
                {
                    Color c = bm.GetPixel(w, h);
                    if (c.A > 0)
                    {
                        c = Color.FromArgb(c.A, intensity == 1f ? col : c.Lerp(col, intensity)); 
                        bm.SetPixel(w, h, c);
                    }
                }
            }
            return bm;
        }
        /// <summary>
        /// Replace specific color into new color with specific intensity
        /// </summary>
        /// <param name="source">gambar</param>
        /// <param name="from">warna diganti</param>
        /// <param name="to">watrna pengganti</param>
        /// <param name="intensity">intensitas</param>
        /// <returns></returns>
        internal static Bitmap SetReplaceColorBitmap(
            this Bitmap source, Color @from, Color to, float intensity = 1f)
        {
            if (source == null) { return null; }
            if (from.Equals(to)) { return source;                  }
            if (intensity < 0.1f && intensity > 1f) { intensity = 1f; }
            Bitmap bm = new Bitmap(source);
            for (int w = 0; w < source.Width - 1; w++)
            {
                for (int h = 0; h < source.Height - 1; h++)
                {
                    Color c = bm.GetPixel(w, h);
                    if (c.R == from.R && c.G == from.B && c.B == from.B)
                    {
                        c = Color.FromArgb(c.A, intensity == 1f ? to : c.Lerp(to, intensity));
                        bm.SetPixel(w, h, c);
                    }
                }
            }
            return bm;
        }
        private static unsafe Bitmap ReplaceNonTransparentColorA(
            Bitmap source,
            Color replacement,
            byte alphaLimitMinim = 5)
        {
            const int PIXEL_SIZE = 4;                   // 32 bits per pixel
            var target = new Bitmap(source.Width, source.Height, PixelFormat.Format32bppArgb);
            BitmapData sourceData = null, targetData = null;

            try
            {
                sourceData = source.LockBits(
                  new Rectangle(0, 0, source.Width, source.Height),
                  ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);

                targetData = target.LockBits(
                  new Rectangle(0, 0, target.Width, target.Height),
                  ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb);

                for (int y = 0; y < source.Height; ++y)
                {
                    byte* sourceRow = (byte*)sourceData.Scan0 + (y * sourceData.Stride);
                    byte* targetRow = (byte*)targetData.Scan0 + (y * targetData.Stride);

                    for (int x = 0; x < source.Width; ++x)
                    {
                        byte b = sourceRow[x * PIXEL_SIZE + 0];
                        byte g = sourceRow[x * PIXEL_SIZE + 1];
                        byte r = sourceRow[x * PIXEL_SIZE + 2];
                        byte a = sourceRow[x * PIXEL_SIZE + 3];

                        r = replacement.R;
                        g = replacement.G;
                        b = replacement.B;

                        targetRow[x * PIXEL_SIZE + 0] = b;
                        targetRow[x * PIXEL_SIZE + 1] = g;
                        targetRow[x * PIXEL_SIZE + 2] = r;
                        targetRow[x * PIXEL_SIZE + 3] = a;
                    }
                }
            }
            finally
            {
                if (sourceData != null) { source.UnlockBits(sourceData); }
                if (targetData != null) { target.UnlockBits(targetData); }
            }
            return target;
        }
        internal static Bitmap ReplaceNonTransparentColor(this 
            Bitmap source,
            Color replacement,
            byte alphaLimitMinim = 5)
        {
            return ReplaceNonTransparentColorA(source, replacement, alphaLimitMinim);
        }
        internal static Bitmap ReplaceColor(
            this Bitmap source, Color @from, Color to, float intensity = 1f)
        {
            return SetReplaceColorBitmap(source, from, to, intensity);
        }
    }
}

Test

Result
1.   2.   3.   4.   5.   6.
Code
1. Bitmap bm = original bitmap
2. bm.ReplaceColor(Color.Black, Color.DodgerBlue, 0.85f);
3. bm.ReplaceNonTransparentColor(Color.Green, 5);
4. bm.SetReplaceAllColorBitmap(Color.DodgerBlue, 0, 0.25f);
5. bm.SetReplaceAllColorBitmap(Color.Yellow, 0.65f);
6. bm.SetReplaceAllColorBitmap(Color.Black, Color.Red, 0.85f);

TOP

File Size Conversion

Convert file size between selected unit enumeration (bit/bytes) and mode kilo bit size. Use functions and extensions for various file size data type (int, long, double)

List of functions

○ Convert.
○ To Another File Size (2 overloads).
○ Calculate Default File Size (2 overloads).
○ To Default File Size From Bits (2 overloads).
○ To Default File Size From Bytes (3 overloads).





Main class File Size Conversion

Source Code

  1 
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83 
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;

namespace TechScales
{ 
    static partial class FileSizeConverter
    {

        //'####################################################
        //' logic source:
        //' matisse bitcalc
        //'####################################################

        private const int BITS_IN_A_BYTE = 8;
        /// <summary>
        /// mode kilo bit
        /// </summary>
        internal enum eKilo : int
        {
            IEEE_1000 = 1000,
            Legacy_1024 = 1024
        }
        /// <summary>
        /// file size unit
        /// </summary>
        internal enum eUnit
        {
            /// <summary>
            /// unit b
            /// </summary>
            bits = 0,
            /// <summary>
            /// unit B
            /// </summary>
            bytes,
            /// <summary>
            /// unit Kb
            /// </summary>
            kilobits,
            /// <summary>
            /// unit KB
            /// </summary>
            kilobytes,
            /// <summary>
            /// unit Mb
            /// </summary>
            megabits,
            /// <summary>
            /// unit MB
            /// </summary>
            megabytes,
            /// <summary>
            /// unit Gb
            /// </summary>
            gigabits,
            /// <summary>
            /// unit GB
            /// </summary>
            gigabytes,
            //terabytes,
            //petabytes
        }
        internal static string UnitFileSize(eUnit e)
        {
            var s = "";
            switch (e)
            {
                case eUnit.bits: s = "bits"; break;
                case eUnit.bytes: s = "bytes"; break;
                case eUnit.kilobits: s = "Kb"; break;
                case eUnit.kilobytes: s = "KB"; break;
                case eUnit.megabits: s = "Mb"; break;
                case eUnit.megabytes: s = "MB"; break;
                case eUnit.gigabits: s = "Gb"; break;
                case eUnit.gigabytes: s = "GB"; break;
            }
            return s;
        }

    }
}

Others enum eUnit, can be added (tera, peta - bits/bytes) by removes its // sign, on line62 and line63. The content of string UnitFileSize and contents of function Convert and CalculateDefaultFileSize, must be changed too, according to enum eUnit added.

TOP

RGB Color Linear Interpolation

Sometimes some cases, color (C0) with its RGB values, need to be changed to a new color (Cn), based from another color (C1) with a certain amount of percentage (0 to 100%) from C1, linearly.

(C0 » C1 (n%) = Cn)

The process of converting color, from one color that influenced by another color into a new color, we name it 'Color Linear Interpolation (Lerp)'


Source Code

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92 
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;

namespace TechScales
{ 
    static class ColorExtension
    {
        internal static float Lerp(this float start, float end, float amount)
        {
            float difference = end - start;
            float adjusted = difference * amount;
            return (start + adjusted);
        }
        /// <summary>
        /// linear interpolation
        /// </summary>
        /// <param name="colour"></param>
        /// <param name="to" >Color To</param>
        /// <param name="amount">0 ~ 1.0</param>
        /// <returns></returns>
        /// <remarks></remarks> 
        internal static Color Lerp(this Color colour, Color to, float amount)
        {
            // start color
            float r0 = (float)colour.R,
                  g0 = (float)colour.G,
                  b0 = (float)colour.B;
            // end color
            float r1 = (float)to.R,
                  g1 = (float)to.G,
                  b1 = (float)to.B;
            // lerp the color
            byte r = (byte)(r0.Lerp(r1, amount)),
                 g = (byte)(g0.Lerp(g1, amount)),
                 b = (byte)(b0.Lerp(b1, amount));
            // return the new color
            return Color.FromArgb(r, g, b);
        }
        internal static T DeepClone<T>(this T a)
        {
            using (var stream = new System.IO.MemoryStream())
            {
                var formatter = new System.Runtime.Serialization
                                .Formatters.Binary.BinaryFormatter();
                formatter.Serialize(stream, a);
                stream.Position = 0;
                return (T)formatter.Deserialize(stream);
            }
        }
        /// <summary>
        /// simple inversion of color
        /// </summary>
        /// <param name="from"></param>
        /// <returns></returns>
        private static Color InvertA(this Color from)
        {
            return Color.FromArgb(from.A, 255 - from.R, 255 - from.G, 255 - from.B);
        }
        /// <summary>
        /// simple inversion of color, to black or white
        /// </summary>
        /// <param name="from"></param>
        /// <param name="toBlackOrWhiteColor"></param>
        /// <returns></returns>
        internal static Color Invert(this Color from, bool toBlackOrWhiteColor = true)
        {
            if (!toBlackOrWhiteColor) { return from.InvertA(); }
            return (GetBrightness(from) > 130 ? Color.Black : Color.White);
        }
        private static int GetBrightness(Color c)
        {
            return 
            (int)Math.Sqrt(c.R * c.R * .299 + c.G * c.G * .587 + c.B * c.B * .114);
        }
        /*
         * another way
         */ 
        static Color LerpRGB(Color a, Color b, float t)
        {
            return Color.FromArgb
            (
                a.A + (int)((b.A - a.A) * t),
                a.R + (int)((b.R - a.R) * t),
                a.G + (int)((b.G - a.G) * t),
                a.B + (int)((b.B - a.B) * t)
            );
        }
    }
}

Test

Immediate Window
?System.Drawing.Color.Blue.Lerp(System.Drawing.Color.Red, 0.25f);
 "{Name=ff3f00bf, ARGB=(255, 63, 0, 191)}"
    A: 255
    B: 191
    G: 0
    IsEmpty: false
    IsKnownColor: false
    IsNamedColor: false
    IsSystemColor: false
    Name: "ff3f00bf"
    R: 63
 
?System.Drawing.Color.Blue.Lerp(System.Drawing.Color.Yellow, 0.25f);
 "{Name=ff3f3fbf, ARGB=(255, 63, 63, 191)}"
    A: 255
    B: 191
    G: 63
    IsEmpty: false
    IsKnownColor: false
    IsNamedColor: false
    IsSystemColor: false
    Name: "ff3f3fbf"
    R: 63
 

var newColor = Color.Blue.Lerp(Color.Cyan, 0.85f); "{Name=ff00d8ff, ARGB=(255, 0, 216, 255)}" A: 255 B: 255 G: 216 IsEmpty: false IsKnownColor: false IsNamedColor: false IsSystemColor: false Name: "ff00d8ff" R: 0 lerp blue cyan .085f

TOP

Payment Card Number Validation


A payment card is a device that enables its owner (the cardholder) to make a payment by electronic funds transfer. The most common types of payment cards are credit cards and debit cards. Payment cards are usually embossed plastic cards, 85.60 × 53.98 mm in size, which comply with the ISO/IEC 7810 ID-1 standard. They usually also have an embossed card number conforming with the ISO/IEC 7812 numbering standard.

ref: https://en.wikipedia.org/wiki/Payment_card

Today there are many types of cards (payment / credit), there is one of simple way to test the card number, whether valid / invalid, using the Luhn algorithm. Matching publisher network can also be done if it had known the data of the card's issuer networking.




What goal?
○ Check/validate Card Number based on Luhn Algorithm.
○ Check Type, Issuer, Active.
○ Random Card Number Generator Simulation.
○ For Learning Purpose.



Main Class for PayCard Checker

Source Code

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89 
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq; // .Net Framework 4.0

namespace TechScales
{ 
    internal class PayCardEngine
    {
        ~PaymentCardEngine()
        {
            if (Cards != null && Cards.Count > 0) { Cards.Clear(); Cards = null; }
            GC.Collect();
            GC.WaitForPendingFinalizers();
        }
        internal enum CardType
        {
            Unidentify = -1,
            AmericanExpress = 0,
            Bankcard,
            ChinaUnionPay,
            DinersClubCarteBlanche,
            DinersClubenRoute,
            DinersClubInternational,
            DinersClubUSA_Canada,
            DiscoverCard,
            InterPayment,
            InstaPayment,
            JCB,
            Laser,
            Maestro,
            Dankort,
            NSPKMIR,
            MasterCard,
            Solo,
            Switch,
            Visa,
            UATP,
            Verve,
            CardguardEadbGils,
        }
        internal enum Active
        {
            Undefined = -1,
            No = 0,
            Yes = 1,
        }
        internal enum Checker
        {
            None = 0,
            Luhn = 1,
        }
        internal class ValidThrough
        {
            public ValidThrough(int month, int year)
            {
                Month = month; Year = year;
            }
            public int Month
            {
                get;
                set;
            }
            public int Year
            {
                get;
                set;
            }
            public override string ToString()
            {
                return string.Concat(Month, "/", (Year % 1000));
            }
        }
        internal static void ResetCardsData()
        {
            if (Cards != null)
            {
                Cards.Clear(); Cards = null;
            }
            Cards = new List<PayCard>();
        }
        static List<PayCard> Cards { get; set; }

        internal class PayCard
        {
        }
    }
}

Card Type, can be added within enum PayCardEngine.CardType after line41. Card Type also can be taken uniquely from added card data network. Class PayCard will described in here.

Top    Payment Card Live Validation