Login

Tag "slice"

Snippet List

Trim the center of a string

I had to build unique strings for a payment system and i wanted to make them kindof friendly so i generated them with usernames and datetimes(safe enough uniqueness in combo), some usernames are long and they break the limit of this payment system so i thought i should cut the center of the string so it stills has a part of the username and a part of the datetime, the most changing part of the datetime is of course the last part, as microseconds vary rapidly. So i wrote this little function to cut the center of a string i thought it cute so i leave it here. Pay attention to the comment so you can see what is going on.

  • python
  • string
  • slice
Read More

Slice filter

Handy for things such as: `{{ some_string|slice:","|join:";" }}`

  • filter
  • string
  • slice
  • simple
Read More

2 snippets posted so far.