Skip to content

Tarik Billa

  • Web Development
    • html
    • vue.js
    • laravel
    • css
    • javascript
    • jquery
    • node.js
    • php
    • asp.net
  • Programming
    • python
    • java
    • c
    • c++
    • c#
  • git
  • android

ordinal-indicator

JavaScript new Date Ordinal (st, nd, rd, th)

January 30, 2023 by Tarik

Note this works for day numbers from 1 to 31. const nth = function(d) { if (d > 3 && d < 21) return ‘th’; switch (d % 10) { case 1: return “st”; case 2: return “nd”; case 3: return “rd”; default: return “th”; } } // test code const fortnightAway = new Date(+new … Read more

Categories javascript Tags date, javascript, ordinal-indicator Leave a comment

Print a string as hexadecimal bytes

October 24, 2022 by Tarik

You can transform your string to an integer generator. Apply hexadecimal formatting for each element and intercalate with a separator: >>> s = “Hello, World!” >>> “:”.join(“{:02x}”.format(ord(c)) for c in s) ’48:65:6c:6c:6f:2c:20:57:6f:72:6c:64:21

Categories python Tags hex, ordinal-indicator, python, string Leave a comment

Tarik Billa

Software Engineer
tarikbilla@gmail.com
+8801884414000
  • Reuse a hash in YAMLApril 17, 2024
  • Dockerfile: how to redirect the output of a RUN command to a variable?April 16, 2024
  • How to cd to a directory with spaces in the directory name?April 16, 2024
  • Maximum MIME type length when storing the type in a databaseApril 16, 2024
  • What is the difference between Unit, Integration, Regression and Acceptance Testing?April 16, 2024
© 2026 Tarik Billa