Friday, December 17, 2021

Python strptime Polish month discrepency between Linux and Windows

 very similar to the russian issue 

We have discrepancy in Polish between Linux and Windows

Run this command in both Linux and WIndows version 


import locale

import datetime

locale.setlocale(locale.LC_ALL, "pl_PL")

datetime.datetime.strptime('2021-grudnia-17','%Y-%B-%d')  #works only in Linux

datetime.datetime.strptime('2021-Grudzień-17','%Y-%B-%d') #works only in Winods 

Tuesday, October 26, 2021

Python not all space are the same

 Lets look at the below 2 strings

'7 октября 2021'

'7 октября 2021'


They look exactly same but are not. Lets try this in Python 

str = '7 октября 2021'

str_1 = '7 октября 2021'

print(str == str_1) -->  you will get false here


so what is the difference, the space is different lets try this 

str = '7 октября 2021'
for s in str:
print("char is {0} and order is {1}".format(s,ord(s)))
str_1 = '7 октября 2021'

for s in str_1:
print("char is {0} and order is {1}".format(s,ord(s)))


the space in str is 

char is   and order is 160

while the space in str_1 is

char is   and order is 32


So if you try str.replace(' ',"/") it does not work. You need to try differently like this

str.replace(chr(160),'/')

Friday, October 15, 2021

Python strptime Russian month discrepency between Linux and Windows

There is more than a way to write the month in any given language for example in Russian the month September can be written in more than one way

But on Python's implementation of strptime there is a difference in how the windows  or Linux OS perceives the month. 

Just run this Python code in Windows and Linux and see the difference for yourself

import locale

import datetime

locale.setlocale(locale.LC_ALL, "ru_RU")

datetime.datetime.strptime('2021-сентября-18', '%Y-%B-%d')

datetime.datetime.strptime('2021-сентябрь-18', '%Y-%B-%d')


In Windows "сентябрь" works whereas in Linux "сентября" works. This is same for all the months since most of them end in either "рь"  or "ря"

Tuesday, August 17, 2021

Showing the ECS Running Task in Grafana

 Grafana has cloudwatch datasource but the default metrics are cpu and memory and there is no direct way to track the # of running task. But there is a way possible. 

Please follow the instruction for  seeing the running tasks in Cloudwatch and implement the same in Grafana

https://docs.aws.amazon.com/AmazonECS/latest/userguide/cloudwatch-metrics.html#cw_running_task_count


Tuesday, July 12, 2016

SSMS Slow Application Fast

I ran into a situation where the sp takes several minutes to run in SSMS and fraction of a second in Application. The Application calls this SP using Entity Framework.
After seeing the profile only difference between the EF and SSMS is the variable
set arithabort this is off in EF and on in SSMS
in SSMS then I ran
set arithabort off
and then ran my sp and it went faster.

To continue debugging the real issue I created a new sp as a back up of my sp and it ran faster even with set arithabort on!!
Puzzled I just ran alter in my sp and did no changes and just saved it.
Now even my sp runs faster!!

Same issue happened in another environment in which SSMS is faster and applicaiton is slower.
Once again did an alter save and now the sp runs faster in both modes

Wednesday, June 8, 2016

Beatpicker enable a date in a month

I have been using beatpicker. I had got into a situation wherein I need to enable only 1 date in a month for the current year. And the date has to be enabled after today's date.
So if I'm in March Feb and Jan date needs to be disabled.
The beatpicker has few limitations it has a limit on the number of items that can be mentioned in the disablingRules and another is lets say if I say                      
{ from: [*, *, 2], to: [*, *, 31] },
For months which has less than 31 days the date logic gets overflowed to the next month.
After trying various combinations the below code works well
disablingRules: [
                        { from: currentdate, to: '<' }, //diable less than today's date
                        { from: [currentYear, 1, 2], to: [currentYear, 1, 31] },
                        { from: [currentYear, 2, 2], to: [currentYear, 2, 28] },
                        { from: [currentYear, 3, 2], to: [currentYear, 3, 31] },
                        { from: [currentYear, 4, 2], to: [currentYear, 4, 30] },
                        { from: [currentYear, 5, 2], to: [currentYear, 5, 31] },
                        { from: [currentYear, 6, 2], to: [currentYear, 6, 30] },
                        { from: [currentYear, 7, 2], to: [currentYear, 7, 31] },
                        { from: [currentYear, 8, 2], to: [currentYear, 8, 31] },
                        { from: [currentYear, 9, 2], to: [currentYear, 9, 30] },
                        { from: [currentYear, 10, 2], to: [currentYear, 10, 31] },
                        { from: [currentYear, 11, 2], to: [currentYear, 11, 30] },
                        { from: [currentYear, 12, 2], to: '>' },//next year disable
                        { from: ['*', '*', '*'], to: ['*', '*', 29] }, // special case of disabline the date for feb in case of leap year

                        ],

You can populate the current year as a js variable

Thursday, April 18, 2013

is string IEnumerable?


Do you know that string is IEnumerable and it’s a collection of character?
You don’t believe then try a simple code
***************************************************
  string z = "abc";
if (z is IEnumerable)
{
}
 ***************************************************
Or much simpler -> a go to definition for string
 
    public sealed class String : IComparable, ICloneable, IConvertible, IComparableIEnumerableIEnumerable, IEquatable