Skip to content

Instantly share code, notes, and snippets.

View rajrajhans's full-sized avatar

Raj Rajhans rajrajhans

View GitHub Profile
@rajrajhans
rajrajhans / rename_phoenix_project.sh
Created May 5, 2023 08:22
Script for Renaming Phoenix Project (works with Phoenix 1.7)
View rename_phoenix_project.sh
#!/bin/bash
set -e
CURRENT_NAME="PhoenixStarter"
CURRENT_OTP="phoenix_starter"
NEW_NAME="NewName"
NEW_OTP="new_name"
@rajrajhans
rajrajhans / token_cache.ex
Created March 4, 2023 10:51
Refreshing Third Party Tokens before they expire in Elixir using GenServers
View token_cache.ex
# https://rajrajhans.com/2023/02/refreshing-tokens-before-expiry-in-elixir/
defmodule MyApplication.TokenCache do
use GenServer
alias MyApplication.RandomApi
@refresh_lead_time_ms :timer.minutes(5)
@token_key :random_api
require Logger
@rajrajhans
rajrajhans / cloudflare_ddns.sh
Created November 16, 2022 18:40
Simple shell script to update specific CloudFlare DNS record with current ip. Useful when you do not have a static IP address, and are hosting your own servers.
View cloudflare_ddns.sh
#!/bin/bash
# run this script as a CRON job!
# get the current public ip address
printf "\n"
logger -s "Getting the current public IP address..."
current_ip=`curl -s ipinfo.io/ip`
update_dns_record(){
@rajrajhans
rajrajhans / framesTimecodeConverter.js
Last active September 22, 2021 06:02
Frames to Timecode in JavaScript, Timecode to Frames in Javascript
View framesTimecodeConverter.js
const FRAME_RATE = 24;
const framesToTimecode = (timeInFrames) => {
const numOfFramesPerMin = FRAME_RATE * 60;
const hours = Math.floor(timeInFrames / (numOfFramesPerMin * 60));
const minutes = Math.floor(timeInFrames / numOfFramesPerMin) % 60;
const seconds = Math.floor((timeInFrames % numOfFramesPerMin) / FRAME_RATE);
const frames = Math.floor((timeInFrames % numOfFramesPerMin) % FRAME_RATE);
const timecode = {
View contactForm.js
//Blog Post: https://rajrajhans.com/2020/07/using-netlify-lambda-functions-and-sendgrid-to-send-mail/
import React, { Component } from "react"
class ContactForm extends Component {
constructor(props) {
super(props);
this.state = {
name:'',
email:'',