Skip to content

Instantly share code, notes, and snippets.

View ranaroussi's full-sized avatar

Ran Aroussi ranaroussi

View GitHub Profile
@ranaroussi
ranaroussi / nanoid.php
Created March 15, 2023 21:46
Simple PHP implementation of Nanoid, secure URL-friendly unique ID generator
<?php
/**
* Generate secure URL-friendly unique ID.
* By default, ID will have 21 symbols to have same collisions probability
* as UUID v4.
*
* @param integer $len The length of the ID to generate.
* @param mixed $entropy balanced, true (max), false (min)
* @param string $alphabet The characters to use in the ID.
@ranaroussi
ranaroussi / riskfree.py
Created June 28, 2020 11:06
Daily Risk Free Rate (based on 3-Month US Treasury Bills Rates)
import yfinance as yf
import pandas as pd
# de-annualize yearly interest rates
def deannualize(annual_rate, periods=365):
return (1 + annual_rate) ** (1/periods) - 1
def get_risk_free_rate():
# download 3-month us treasury bills rates
annualized = yf.download("^IRX")["Adj Close"]
@ranaroussi
ranaroussi / calculateCompoundInterest.js
Created September 14, 2023 13:44
Calculate compounded interest with periodic contributions
const calculateCompoundInterest = (P, r, t, n, PMT, PMT_f, toFixed=2) => {
/*
* P = initial principle
* r = interest rate (annual)
* t = duration of invesment
* n = compound events per year (1 = annual, 6 = semi-annual, 3 = quarterly, 12 = monthly, ...)
* PMT = ongoing contibution amount
* PMT_f = contributions per year (1 = annual, 6 = semi-annual, 3 = quarterly, 12 = monthly, ...)
* --->
* I = total investment
@ranaroussi
ranaroussi / create-release.yml
Created August 17, 2023 15:38
GitHub action: Set version => Tag => Create Release (triggered by PR merge)
name: Versioning
permissions: write-all
# Controls when the workflow will run
on:
# Triggers the workflow on push or pull request events but only for the "main" branch
pull_request:
branches:
- main
types:
@ranaroussi
ranaroussi / eurusd_order.py
Last active March 5, 2023 11:10
order EUR.USD using ezIBpy
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
import ezibpy
import time
# initialize ezIBpy
ibConn = ezibpy.ezIBpy()
ibConn.connect(clientId=1234, host="localhost", port=7497)
@ranaroussi
ranaroussi / enumerate-notion-items.py
Created August 2, 2021 22:27 — forked from lenolib/enumerate-notion-items.py
Create a unique sequential id for items (tasks) in a notion database / view
import re
from notion.client import NotionClient
def enumerate_notion_items(
view_url, id_col, created_at_col="created_time", token=None, client=None
):
"""
Given that a property with name e.g. "Item ID" exists for a notion dataset,
and that at least one item has a value for that property, this function
@ranaroussi
ranaroussi / demo.html
Last active November 25, 2022 15:58
Detect if DevTools is open and its orientation
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no, viewport-fit=cover">
<script src="devtools.js"></script>
<script>
devTools.init((o) => {
if (o.open) {
@ranaroussi
ranaroussi / test.js
Last active August 5, 2022 17:26
Node timer with nano-second precision
const Timer = require('./timer')
const timer = new Timer();
// do stuff...
timer.stop();
// '1s, 589.334334 ms'
@ranaroussi
ranaroussi / enum.js
Created June 15, 2022 14:34
Javascript enum using Object.freeze
class Enum {
constructor(...args) {
if (args.length === 0) {
throw new Error('Enum must be initialized with at least one argument');
}
let obj = (args.length === 1) ? args[0] : args;
if (args.length > 1 || Array.isArray(obj)) {
obj = Object.assign({}, ...obj.map((x) => ({ [x]: x })));
}
[...Object.entries(obj)].forEach((items) => {
@ranaroussi
ranaroussi / premarket.py
Last active April 21, 2022 17:24
Retrieve Pre-Market data from Google Finance (python 3.x)
"""
Retrieve Pre-Market data from Google Finance
Ported to Python 3.x
Original code by Dr. Pawel Lachowicz
http://www.quantatrisk.com/2015/05/07/hacking-google-finance-in-pre-market-trading-python/
"""
import requests
import json
from time import sleep