Thursday, December 29, 2022

pandas calculate return by shifting timeseries index

 usually, we calculate the return with next row data by simply using df.Close.shift()

but if we want shifting by a specific time period, can try:

df['ret15min'] = (df.Close.shift(-15, freq="min") -df.Close)*100/df.Close

Sunday, November 1, 2020

Install without root access / for current user

 You can use conda to install mysql client!

https://stackoverflow.com/questions/36651091/how-to-install-packages-in-linux-centos-without-root-user-with-automatic-depen/52561058#52561058

Thursday, October 29, 2020

recreate / cloning conda env with limited internet access

  • https://www.anaconda.com/blog/moving-conda-environments
  • https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html

Thursday, June 25, 2020

Generate FPS QR Code with customized amount


  1. Scan an existing QR code at https://zxing.org/w/decode.jspx to get the text content
  2. Remove the last 4 characters, which is the checksum (CRC), from the text content
  3. Spot the substring that contains the amount from the text content
  4. Replace the amount substring with new amount using the *same number* of characters, for example, replacing 
    • 1755.00
      • with
    • 0050.00
      • will update the amount from $1,755 to $50
  5. Calculate the new checksum
    1. http://www.sunshine2k.de/coding/javascript/crc/crc_js.html
      1. width: CRC-16
      2. parametrization: Custom
      3. Polynomial: 0x1021
      4. Initial Value: 0xFFFF
      5. Input Data: String
      6. Paste the updated text content from above
      7. Click Calculate CRC
  6. Generate new QR code
    1. https://www.qrcode-monkey.com/#text
    2. Paste the updated text content appended with the new 4-character CRC
    3. Click Create QR Code


Ref: FPS QR code specification at https://www.hkma.gov.hk/media/eng/doc/key-functions/financial-infrastructure/infrastructure/retail-payment-initiatives/Common_QR_Code_Specification.pdf

Thursday, April 30, 2020

send email html content with inline image


  • preferred way:
    • script to generate html content with image encoded as base64 text
      • <img src='data:imag/png;base64,....'/>
      • base64.b64encode().decode("ascii") to get that ... string from image
    • single html file to include all the html and images, etc. 😀
    • cat that html and pipe to mutt -e "set content_type=text/html" to send the email

Tuesday, March 3, 2020

url to pdf on linux

yum install wkhtmltopdf
To manipulate the pdfs, use pdfunite / pdfseparate from
yum install poppler-utils

Saturday, December 28, 2019

centos minimal

install centos 8 minimal

install google-chrome from google repo, which should install all the X dependencies

additional language support for web page display
> yum groupinstall Fonts

To start chrome full screen
> X& DISPLAY=:0 google-chrome --window-size=1920,1080&

if sound is not already working,
> yum install alsa-utils
unmute everything with
> alsamixer
https://wiki.archlinux.org/index.php/Advanced_Linux_Sound_Architecture#Disabling_auto_mute_on_startup