Skip to content

Instantly share code, notes, and snippets.

View obedparla's full-sized avatar
👨‍💻
42

Obed Parlapiano obedparla

👨‍💻
42
View GitHub Profile
const fs = require('fs');
const path = require('path');
const tinify = require('tinify');
require('dotenv').config()
tinify.key = process.env.API;
// Define the directories.
const inputDir = './images';
const outputDir = './optimized';
@obedparla
obedparla / simple-fetch.ts
Created August 24, 2023 11:46
Simple fetch
export function fetchFromUrl<T>(
url: string,
options: RequestInit,
): Promise<T | { error: string }> {
return fetch(url, { ...options })
.then((response) => {
if (response.ok) {
try {
return response.json();
} catch (e) {
@obedparla
obedparla / turnPxValuesToFrUnits.ts
Created July 7, 2023 13:12
Turn pixel (px) values to fractional units (fr) for CSS Grid
// Turn "px" values into "fr" values.
// e.g: column widths: [768, 384, 768] and total width 1920.
// 738 / 1920 = 0.4. * 1000 = 4fr
// Times 1000 because if it's something like 10px: 10 / 1920 = 0.005
// And we want to raise it to a full integer
export function turnPxValuesToFrUnits(
fractionalValues: number[],
total: number
) {
return fractionalValues
@obedparla
obedparla / delete_all_tweets.js
Created June 20, 2023 20:11
Delete all your tweets without an API and for free
// Delete ALL your tweets and un-retweet everything
// Just paste this code on the dev tools and leave the tab open. It deletes at [speed]. Make it faster or slower
// I don't know if Twitter has some internal safety to prevent a bunch of deletions from happening to fast, but at 100 it deletes 1000 tweets in under two minutes
// BEWARE you can't undo this action, and it will delete EVERYTHING
const speed = 100;
// do it on repeat. Timeouts are ugly but whatever, it works
setInterval(function (){
@obedparla
obedparla / gist:e3f91eb60cf692d893480d658b2add63
Last active May 5, 2023 12:47
Completely clean Docker resources (images, network, volumes)
Note: These commands will remove all your Docker resources, not just the images. Be sure to backup any important data from your Docker volumes before running these commands.
bash
```
# Stop all running Docker containers:
docker stop $(docker ps -aq)
# Remove all Docker containers:
docker rm $(docker ps -aq)
@obedparla
obedparla / php
Created November 27, 2022 22:40
Add HTML after Breakdance's styles
<?php
add_action('init', function() {
add_action(
'wp_head',
function () {
echo "<link rel='stylesheet' href='<url_to_stylesheet>'></link>";
},
1000000 + 1
);
# Find how much all your node modules weigh
find . -name "node_modules" -type d -prune -print | xargs du -chs
# To delete them AT YOUR OWN RISK:
find . -name 'node_modules' -type d -prune -print -exec rm -rf '{}' \;
@obedparla
obedparla / objectGetTypedKeys.ts
Created November 7, 2021 11:49
Correctly gets all Object.keys types for TypeScript (both keys and values types)
export const objectGetTypedKeys = Object.keys as <T extends object>(
obj: T
) => Array<keyof T>;
@obedparla
obedparla / Design for devs notes.md
Last active September 2, 2021 11:11
Design for devs notes
@obedparla
obedparla / karabiner_rules
Created February 8, 2021 18:18
Obed's karabiner rules
"rules": [
{
"description": "button5 left space",
"manipulators": [
{
"from": {
"pointing_button": "button5"
},
"to": [
{