Skip to content

Instantly share code, notes, and snippets.

@remorses
remorses / script.py
Created March 4, 2024 11:17
Convert Openai ChatGPT exported data to csv
import csv
import json
def extract_messages(data, max_messages):
messages = []
for message_id, message_data in data["mapping"].items():
if message_data["message"]:
message = message_data["message"]
content = message.get("content", {}).get("parts", [""])[0]
@remorses
remorses / main.py
Created January 24, 2024 10:11
Remove Adobe watermarks from pdf with Python
from pypdf import PdfReader, PdfWriter
def remove_watermark(pdf_path, output_path):
reader = PdfReader(pdf_path)
writer = PdfWriter()
for page in reader.pages:
if '/Resources' in page and '/XObject' in page['/Resources']:
@remorses
remorses / gist:ceb7a3cfc3fac671866b5c67d464a1a5
Created July 11, 2023 18:56
nextjs pattern to redirect to /docs.js
module.exports = {
async redirects() {
return [
{
source: '/',
destination: 'https://example.com/docs',
permanent: false,
},
{
source: '/:slug*',
import path from "path";
import fs from "fs";
import { getPackages } from "@monorepo-utils/package-utils";
const sourceDir = "src";
getPackages(__dirname).map(x => {
let types = getTypesFile({
sourceDir: path.resolve(x.location, sourceDir)
});
@remorses
remorses / main.graphql
Created March 7, 2020 15:39
Get graphql enum values
query enumValuesOfMetaInformationTags {
__type(name: "META_INFORMATION_TAGS") {
name
enumValues {
name
}
}
}
@remorses
remorses / main.ts
Created February 26, 2020 15:21
Download a file with node-fetch
const buffer = await fetch(url).then((r) => r.buffer())
const content = buffer.toString('utf8')
// then pass this where you like
@remorses
remorses / main.ts
Created February 26, 2020 14:44
Cloud storage uplaod file and get url
import admin from 'firebase-admin'
const file = admin
.storage()
.bucket('')
.file('name.txt')
await file.save('dsfgsdf', {
gzip: true,
public: true,
contentType: 'image',
})
@remorses
remorses / main.md
Created January 25, 2020 14:48
react-extra-hooks-article

I have always used Apollo to make graphql requests inside of react, usually doing something like this

import { useQuery } from '@apollo/react-hooks';
import gql from 'graphql-tag';

const GET_GREETING = gql`
  query getGreeting($language: String!) {
    greeting(language: $language) {
      message
@remorses
remorses / dicts_set.py
Created July 12, 2019 11:35
set of dictionaries in python
l = [
{
'a': 1,
'b': 1,
},
{
'a': 2,
'b': 1,
},
{
@remorses
remorses / multiway_trees_bfs.hs
Created May 28, 2019 19:19
breadth first search (bfs) for multiway trees implemented in haskell
data Tree a = Node a [Tree a]
traverseBF :: Tree a -> Tree a
traverseBF tree = tbf tree
where
tbf (Node x []) = Node x []
tbf (Node x xs) = Node x (map tbf $ xs)