Skip to content

Instantly share code, notes, and snippets.

View felipecsl's full-sized avatar
⚒️
Building

Felipe Lima felipecsl

⚒️
Building
View GitHub Profile
@felipecsl
felipecsl / yarn-lockfile-diff.ts
Created September 30, 2024 20:53
Given `before-yarn.lock` and `after-yarn.lock`, prints the dependencies changed in a human readable list
const fs = require('fs');
const yarnLockfile = require('@yarnpkg/lockfile');
function parseLockfile(filePath) {
const file = fs.readFileSync(filePath, 'utf8');
return yarnLockfile.parse(file).object;
}
function getVersionDifferences(beforeLockfile, afterLockfile) {
const diffs: Record<string, { before: string, after: string }> = {};
@felipecsl
felipecsl / heic_to_jpeg.sh
Created September 11, 2024 16:51
Convert all images from heic format to jpeg
for file in *.HEIC; do sips -s format jpeg "$file" --out "${file%.*}.jpg"; done
@felipecsl
felipecsl / decryptRailsCookie.ts
Created January 25, 2024 13:03
Typescript/Node function to decrypt Rails 7.1 encrypted session cookies
import crypto from 'crypto';
import { promisify } from "node:util";
const pbkdf2 = promisify(crypto.pbkdf2);
// Works with Rails 7.1.3
// secretKeyBase is Rails.application.secret_key_base
async function decryptCookie(encryptedCookie: string, cookieName: string, secretKeyBase: string) {
const cookie = decodeURIComponent(encryptedCookie);
const [data, iv, authTag] = cookie.split("--").map(v => Buffer.from(v, 'base64'));
@felipecsl
felipecsl / useLazyEffect.ts
Created September 8, 2022 14:49
Debounced React useEffect with a wait time in milliseconds
// https://stackoverflow.com/a/67504622/51500
import {
DependencyList,
EffectCallback,
useCallback,
useEffect,
useRef,
} from "react";
import { debounce } from "lodash";
@felipecsl
felipecsl / install-redistimeseries.sh
Last active January 11, 2022 06:35
Install Redis time series on Amazon Linux
#!/bin/bash
wget http://downloads.sourceforge.net/ltp/lcov-1.14-1.noarch.rpm
sudo yum localinstall lcov-1.14-1.noarch.rpm
git clone --recursive https://github.com/RedisTimeSeries/RedisTimeSeries.git
cd RedisTimeSeries
sudo make setup
@felipecsl
felipecsl / install-redis.sh
Created September 17, 2020 20:25 — forked from jpickwell/install-redis.sh
Installing Redis 6.0.0 on Amazon Linux
#!/bin/bash
###############################################
# To use:
# chmod +x install-redis.sh
# ./install-redis.sh
###############################################
version=6.0.8
@felipecsl
felipecsl / FakeResourceHttpURLConnection.kt
Last active July 11, 2020 16:51
Kotlin snippets for return a canned response from a resource file whenever a URL is request is fired
// Based on https://stackoverflow.com/questions/565535/mocking-a-url-in-java
package com.example
import java.io.InputStream
import java.net.HttpURLConnection
import java.net.URL
class FakeResourceHttpURLConnection(
url: URL,
@felipecsl
felipecsl / retryIfThrown.kt
Last active April 27, 2023 00:02
Kotlin utility to retry a provided block a limited number of times
/**
* Retries the provided [block] up to [times] times if the block throws an exception of the type
* [exceptionType]. If any other exception type is thrown, the exception is caught and then
* immediately rethrown.
*/
fun retryIfThrown(times: Int, exceptionType: KClass<out Throwable>, block: () -> Unit) {
for (i in 0 until times) {
try {
block()
break
@felipecsl
felipecsl / setup.sh
Last active August 25, 2022 23:06
Base EC2 instance setup for Amazon Linux box
# Install all the packages
sudo yum install -y \
curl gpg gcc gcc-c++ make git \
openssl-devel readline-devel libcurl-devel \
zlib-devel postgresql-server.x86_64 ruby-devel \
sqlite sqlite-devel ruby-rdoc python-devel \
cairo-devel libffi-devel python-pip nc docker \
tmux htop postgresql-libs postgresql-devel \
amazon-cloudwatch-agent
sudo yum install autoconf automake bzip2 bzip2-devel cmake freetype-devel gcc gcc-c++ git libtool make mercurial pkgconfig zlib-devel -y
mkdir ~/ffmpeg_sources
# nasm
cd ~/ffmpeg_sources
curl -O -L https://www.nasm.us/pub/nasm/releasebuilds/2.14.02/nasm-2.14.02.tar.bz2
tar xjvf nasm-2.14.02.tar.bz2
cd nasm-2.14.02
./autogen.sh
./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin"