Skip to content

Instantly share code, notes, and snippets.

@ahallora
ahallora / index.js
Created September 18, 2021 19:58
Slack API: Get User details based on reactions
require('dotenv').config();
const { App } = require('@slack/bolt');
const reaction = process.env.EMOJI;
const url = process.env.URL;
const app = new App({
signingSecret: process.env.SLACK_SIGNING_SECRET,
token: process.env.SLACK_BOT_TOKEN,
});
@ahallora
ahallora / README.md
Last active September 3, 2024 01:01
Convert MP4 to GIF free and open-source using FFMPEG and Windows Context menu

Convert MP4 to GIF free and easy directly from the Windows context menu

Previously I've been using GifCam, but it doesn't play well with my retina display, so I had to come up with something. There's strong options for Mac but no good free options for Windows.

I can use the native Windows snipping tool to record my screen, but I'm unable to save the recording as a gif, resulting in pretty big MP4 files. I don't want that. So I created this little script that can convert the recorded MP4 file to GIF for a great reduction in file size.

Installation

  1. Install ffmpeg from www.ffmpeg.org
  2. Update the path to ffmpeg in the bat file
@ahallora
ahallora / LambdaCacheController.js
Last active June 19, 2024 18:47
Simple AWS Lambda Container In-Memory Cache Controller for Node.js / ES6
export class LambdaCacheController {
constructor() {
this.value = null;
this.timestamp = null;
this.ttl = 3000000; // default 5 minutes
}
async getValue() {
return new Promise((resolve, reject) => {
try {
@ahallora
ahallora / ABTest.tsx
Last active March 27, 2024 08:06
Basic React ABTesting Component - POC
import React, { ReactNode, useState } from "react";
type Experiment = {
exposure: number;
render: ({ success }: { success: any }) => any;
name?: string;
};
enum TestEvent {
"VIEW" = "View",
@ahallora
ahallora / decimalStringToCento.ts
Created March 24, 2024 12:08
Decimal string to cento number
export const decimalStringToCento = (decimalString: string): number => {
// Replace comma with dot to make it a valid float
const cleanedString = decimalString.replace(",", ".");
// Parse the string as a floating-point number
const floatValue = parseFloat(cleanedString);
// Multiply by 100 to get the cento number
const centoNumber = Math.round(floatValue * 100);
@ahallora
ahallora / csvToJson.ts
Created March 24, 2024 12:07
Convert csv to JSON
const parseCSVLine = (line: string): string[] => {
const parts = line.split(",");
const result: string[] = [];
parts.reduce(
(accumulator, currentPart) => {
if (!accumulator.insideQuotes) {
if (currentPart.startsWith('"') && currentPart.endsWith('"')) {
// Handle the case when the value is enclosed in double quotes
result.push(currentPart.slice(1, -1));
@ahallora
ahallora / useScrollableMask.ts
Last active February 21, 2024 07:56
useScrollableMask
/*
HOW TO USE:
import React from "react";
import useScrollableMask from "./useScrollableMask";
const Example = () => {
const { scrollDiv, scrollDivStyles } = useScrollableMask();
return (
@ahallora
ahallora / useAudioContext.js
Created February 6, 2024 15:29
Web Audio API react hook to easily stream music with fade in and out (working on Safari iOS too)
import { useState, useEffect } from "react";
export const useAudioContext = () => {
const [audioContext, setAudioContext] = useState(null);
const [currentSourceNode, setCurrentSourceNode] = useState(null);
const [gainNode, setGainNode] = useState(null);
useEffect(() => {
const context = new AudioContext();
setAudioContext(context);
@ahallora
ahallora / AdvancedForm.jsx
Last active February 3, 2024 21:48
React form where form state is saved in querystring using react-hook-form
"use client";
import { useForm } from "react-hook-form";
import { useEffect } from "react";
const AdvancedForm = () => {
const { register, handleSubmit, setValue, watch } = useForm();
const watchedValues = watch();
// Function to update the query string
const updateQueryString = () => {
@ahallora
ahallora / readme.md
Created January 31, 2024 08:51
LocalAI and StableDiffusion on Ubuntu (WSL2)

Making LocalAI and StableDiffusion work on Ubuntu (via WSL2)

Prerequisites:

  • Docker running
  • nvidia-smi running

Print out the GPUs available in docker:

docker run -it --rm --gpus all ubuntu nvidia-smi -L