Skip to content

Instantly share code, notes, and snippets.

View ranaroussi's full-sized avatar

Ran Aroussi ranaroussi

View GitHub Profile
@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 / 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 / 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 / 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 / redison.py
Last active October 6, 2020 22:30
Redison - extension for redis to get/set json objects
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Redison - an extension for redis to get/set json objects
# https://gist.github.com/ranaroussi/90268aca3bf438d1aabfdb918288c6a9/edit
#
# Copyright 2020 Ran Aroussi
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@ranaroussi
ranaroussi / Clone-Github-Wiki-Pages.sh
Created September 19, 2020 22:51 — forked from hanxue/Clone-Github-Wiki-Pages.sh
Cloning Github Wiki Pages
hanxue-mac:Github hanxue$ git clone https://github.com/AppScale/appscale.wiki.git
Cloning into 'appscale.wiki'...
remote: Counting objects: 1745, done.
remote: Compressing objects: 100% (1733/1733), done.
remote: Total 1745 (delta 1089), reused 10 (delta 4)
Receiving objects: 100% (1745/1745), 267.93 KiB | 35.00 KiB/s, done.
Resolving deltas: 100% (1089/1089), done.
Checking connectivity... done
hanxue-mac:Github hanxue$ ls appscale.wiki/
.git/
@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"]